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

こ雲淡風輕ζ 提交于 2019-12-11 15:36:57

问题


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'
       ),

    ],

回答1:


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



来源:https://stackoverflow.com/questions/47119493/typo3-extension-read-custom-fal-variable-in-the-domain-to-use-in-fluid-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!