4

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

ext_tables.php:

CREATE TABLE sys_file_reference (
 nofollow int(11) DEFAULT '0' NOT NULL,
);

配置/TCA/覆盖/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');

就它在后端工作而言。

类/域/模型/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;
    }
}

在我的设置中:

config.tx_extbase.persistence.classes {
    LISARDO\Foerderland\Domain\Model\MyFileReference {
        mapping {
            tableName = sys_file_reference
        }
    }
}

在流体中,我得到 image.uid oder image.link 但 image.nofollow 总是空的。我做错了什么?我认为映射不正确...


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

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

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

只需要 TCA-Code 并且使用不同的语法。

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

感谢所有答案!

4

3 回答 3

4

据我所知,您可以使用{image.properties.nofollow}.

于 2016-09-27T06:52:00.670 回答
2

您是否也在引用您的 sys_file_reference 实现?

所以,这可能看起来像这样

/**
 *
 * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\LISARDO\Foerderland\Domain\Model\MyFileReference>
 * @lazy
 */
protected $media;
于 2016-09-27T06:09:43.800 回答
1

您需要参考您的自定义实现。

要么像Georg Ringer在他的回答中建议的那样做,要么你可以在 TS 级别替换课程,如下所示:

plugin.tx_yourext {
    objects {
        TYPO3\CMS\Extbase\Domain\Model\FileReference {
            className = LISARDO\Foerderland\Domain\Model\MyFileReference
        }
    }
}

这将在引用它的所有属性中自动实例化MyFileReference而不是核心,也包括和调用。FileReference@injectObjectManager->get()

如果您想在全局级别执行此操作(对于所有插件,包括核心),您可以在上面的 TS 中更改tx_yourexttx_extbase

于 2016-09-27T07:58:03.527 回答