我想用自己的字段扩展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
}
}
}
在Fluid我得到image.uid oder image.link但是image.nofollow总是空的 . 我错了什么?我认为映射不正确......
好吧,我得到了正确的答案,并注意到我犯了一个错误,并在某些方面解释错了 . 第一:它不是普通的extbase扩展,而只是一个自己的内容元素 . 所以我没有自己的扩展模型,我可以像Georg和Victor提出的那样注入实现 . 我只需要更改流畅的语法:完成工作 .
我认识到我不需要我的大部分代码:
-
Classes/Domain/Model/MyFileReference.php
没有必要 -
config.tx_extbase.persistence.classes
也没有必要
只需要TCA代码,并且流畅的语法不同 .
但我无法弄清楚为什么这种语法工作和正常的语法不 .
谢谢你的回答!
3 回答
您需要参考自定义实现 .
也可以这样做,如 Georg Ringer 在他的回答中建议的那样,或者你可以在TS级别上替换这个类,如下所示:
这将自动在引用它的所有属性中实例化
MyFileReference
而不是核心的FileReference
,还包括@inject
和ObjectManager->get()
调用 .如果你想在全局级别(对于所有插件,包括核心)进行,你可以在上面的TS中将
tx_yourext
更改为tx_extbase
.据我所知,您可以使用
{image.properties.nofollow}
访问自己的流体属性 .您是否也引用了sys_file_reference实现?
所以,这可能看起来像那样