扩展 sys_file_reference (FAL)

lis*_*rdo 5 typo3 fal

我想用自己的字段扩展 sys_file_reference 。所以我创建了该字段和 TCA。在后端,该字段可用,但我无法引用流体模板中的该字段。

ext_tables.php:

CREATE TABLE sys_file_reference (
 nofollow int(11) DEFAULT '0' NOT NULL,
);
Run Code Online (Sandbox Code Playgroud)

配置/TCA/Overrides/sys_file_reference.php:

$tempColumns = array(
    'nofollow' => array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'Link als Nofollow?',
        'config' => array(
            'type' => 'check',
            'default' => '0'
        )
    )
);
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_file_reference',$tempColumns,1);
TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette('sys_file_reference', 'imageoverlayPalette','--linebreak--,nofollow','after:description');
Run Code Online (Sandbox Code Playgroud)

到目前为止它在后端工作。

类/域/模型/MyFileReference.php

<?php
namespace LISARDO\Foerderland\Domain\Model;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;

class MyFileReference extends FileReference {

    /**
     * nofollow
     *
     * @var integer
     */
    protected $nofollow;


    /**
     * Returns the nofollow
     *
     * @return integer $nofollow
     */
    public function getNofollow() {
        return $this->nofollow;
    }

    /**
     * Sets the nofollow
     *
     * @param integer $nofollow
     * @return void
     */
    public function setNofollow($nofollow) {
        $this->nofollow = $nofollow;
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的设置中:

config.tx_extbase.persistence.classes {
    LISARDO\Foerderland\Domain\Model\MyFileReference {
        mapping {
            tableName = sys_file_reference
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在 Fluid 中,我得到 image.uid 或 image.link 但 image.nofollow 始终为空。我做错了什么?我认为映射不正确......


好吧,我得到了正确的答案,并注意到我犯了一个错误,并在某些方面解释了错误。首先:它不是一个普通的 extbase 扩展,而只是一个自己的内容元素。所以我的扩展没有自己的模型,我可以按照 Georg 和 Victor 的建议注入实现。我只需更改 Fluid 中的语法: {image.properties.nofollow} 即可完成这项工作。

我认识到我不需要我的大部分代码:

  • Classes/Domain/Model/MyFileReference.php没有必要
  • config.tx_extbase.persistence.classes也没有必要

只需要 TCA 代码,并且流体中使用不同的语法。

但我无法弄清楚为什么这种语法有效而普通语法无效。

感谢您的所有回答!

Ren*_*amm 4

据我所知,您可以使用 Fluid 访问您自己的属性{image.properties.nofollow}