1

Hello dear Stackoverflow community,

i've meet following Scenario which appears to not work properly.

I have an Model called Principal

Inside the Model, i have the following property

protected Pages|null $storage = null;

And the following functions:

public function getStorage(): Pages|null
{
    return $this->storage;
}

public function setStorage(Pages|null $storage): void
{
    $this->storage = $storage;
}

With the following TCA Entry for that Database column:

'storage' => [
    'label'  => 'Mandanten Ordner',
    'config' => [
        'type'          => 'group',
        'internal_type' => 'db',
        'allowed'       => 'pages',
        'foreign_table' => 'pages',
        'foreign_field' => 'uid',
        'minitems'      => 1,
        'suggestOptions' => [
            'default' => [
                'minimumCharacters' => 1,
                'searchWholePhrase' => true
            ],
        ],
        'fieldControl'  => [
            'addRecord' => [
                'options'  => [
                    'title' => 'Neu anlegen',
                ],
            ]
        ]
    ],
],

and db column:

storage int(11) DEFAULT '0' NOT NULL,

i created a Pages Model, for which i have Configured a Classes.php under Configuration->Extbase->Persistence. The Configuration was the following:

\MyVendor\MyExtensionKey\Domain\Model\Pages::class => [
    'tableName' => 'pages',
    'recordType' => '0'
],

The Pages Model:

<?php

namespace MyVendor\MyExtensionKey\Domain\Model;

class Pages extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
{
    public function getPid(): int|null
    {
        return $this->pid;
    }

    public function setPid(int $pid): void
    {
        $this->pid = $pid;
    }
}

but when i try to call the getStorage() function from my Principal Model, i always only get null returned even if the uid of the page is already saved to my Principal Model.

i am confused as i already did associate an Model of mine to another Table, it worked when i for example used the fe_user table and so on, but pages does not seems to work.

Is there another solution to my specific case or is this one of the limits that can't be fully implemented within a TYPO3 Extension?

4
  • Maybe it's the recordType => 0, which is not an existing page type? Commented Jun 3 at 12:44
  • I am still testing that, seems like that was the problem regarding not finding the Pages Model Object associated to the Principal Object via getStorage(). But it seems like it only finds the pages entry with the uid 1 and associate it to the Pages model, even through the Database saved the pages entry with the uid 574. the recordType i've tried out was 1 (Standard) and 254 (Folder) Commented Jun 3 at 13:08
  • You need to set the maxitems to 1 in your TCA. "internal_type" and "foreign_field" does not exist in type=group. docs.typo3.org/m/typo3/reference-tca/12.4/en-us/ColumnsConfig/… Commented Jun 4 at 16:15
  • that pretty much did the trick in combination with the Answer of @ThomasLöffler Thanks you two. ^^ Commented Jun 5 at 13:07

1 Answer 1

1

Thanks to Thomas Löffler and Mogens, i came across this solution:

  1. In Configuration\Extbase\Persistence\Classes.php

    1. For the Pages Mapping, the recordType should be 254 (In Case you wanna use Folders) or 1 (In Case you wanna use a Standard Site) and so on -> See https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/PageTypes/Index.html

      \MyVendor\MyExtensionKey\Domain\Model\Pages::class => [
          'tableName' => 'pages',
          'recordType' => '254'
      ],
      
  2. Configuration\TCA\tx_yourextensionkey_domain_model_principal.php

    1. In my TCA, the type for the storage field was set to group, but group do not have an internal_type or foreign_field, that's why even with the fact that the right value was saved to the Database, it was somehow bugged when i called the getStorage method from my principal Model.

    2. For the reference what array_keys can be used for the group type, see https://docs.typo3.org/m/typo3/reference-tca/12.4/en-us/ColumnsConfig/Type/Group/Index.html#properties-of-the-tca-column-type-group, which was suggested by Mogens comment

      'storage' => [
          'label'  => 'Mandanten Ordner',
          'config' => [
              'type'          => 'group',
              'allowed'       => 'pages',
              'foreign_table' => 'pages',
              'minitems'      => 1,
              'suggestOptions' => [
                  'default' => [
                      'minimumCharacters' => 1,
                      'searchWholePhrase' => true
                  ],
              ],
              'fieldControl'  => [
                  'addRecord' => [
                      'options'  => [
                          'title' => 'Neu anlegen',
                      ],
                  ]
              ]
          ],
      ],
      

      These are the corrected code parts, the first one is the Configuration\Extbase\Persistence\Classes.php and the second one is the Configuration\TCA\tx_yourextensionkey_domain_model_principal.php code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.