typo3typo3-7.6.xtx-newstypo3-extensionsfal

TYPO3 extension; read custom FAL variable in the domain to use in fluid template


In my custom extension I introduced a binary variable to the image metadata that needs to be read, similar to the "Show in list view" of tx_news.

With tx_news as example I was able to add the variable, the new palette shows the checkbox in the backend and the selection is registered in a new database field in the sys_file_reference table ...

now I need to use this variable in my fluid templates, and here I lose the trail; the objects are items and the new variable is named opentab, I declare the variable as follows in the domain:

/**
 * items
 * 
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\FileReference>
 * @lazy
 */
protected $items = null;

/**
 * items with opentab set
 *
 * @var array
 * @transient
 */
protected $itemsOpen;

this is how I try to read the items with opentab checked:

/**
 * Get open items
 *
 * @return array
 */
public function getItemsOpen()
{
    $itemOpen = [];
    foreach ($this->getItems() as $item) {
        if ($item->getOriginalResource()->getProperty('opentab')) {
            $itemOpen[] = $item;
        }
    }
    return $itemOpen;
}

with <f:debug> in my fluid template I do see the variable itemsOpen but no value whatever the db contains for this field ...

my TCA for the items:

    'items' => [
        'exclude' => 1,
        'label' => $ll . 'tx_trader_domain_model_object.floorplans',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'items',
            [
                'appearance' => [
                    'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
                ],
                // custom configuration for displaying fields in the overlay/reference table
                // to use the itemsPalette and imageoverlayPalette instead of the basicoverlayPalette
                'foreign_types' => [
                    '0' => [
                        'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;itemsPalette,
                            --palette--;;imageoverlayPalette,
                            --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
                        'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;itemsPalette,
                            --palette--;;imageoverlayPalette,
                            --palette--;;filePalette'
                    ],
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
                        'showitem' => '
                            --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette;itemsPalette,
                            --palette--;;imageoverlayPalette,
                            --palette--;;filePalette'
                    ]
               ]
           ],
           'gif,jpg,jpeg,png,pdf'
       ),

    ],

Solution

  • Fluid calls magically the getter methods. So try <f:debug>{object.itemsOpen}</f:debug>.

    The property will stay empty since you do not fill it anywhere. It isn't used in your getter