[英]Extending sys_file_reference (FAL)
我想用自己的字段擴展sys_file_reference。 因此,我創建了該領域和TCA。 在后端,該字段可用,但我無法在我的流體模板中引用該字段。
ext_tables.php:
CREATE TABLE sys_file_reference (
nofollow int(11) DEFAULT '0' NOT NULL,
);
配置/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');
到目前為止,它在后端工作。
類/域/模型/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或image.link,但是image.nofollow始終為空。 我怎么了 我認為映射不正確...
好吧,我得到了正確的答案,並注意到我犯了一個錯誤並以某種方式解釋了錯誤。 首先:它不是正常的extbase擴展,而只是一個自己的內容元素。 因此,對於擴展我沒有自己的模型,我無法按照Georg和Victor的建議注入實施。 我只需要更改Fluid的語法即可:{image.properties.nofollow}可以完成工作。
而且我認識到我不需要大多數代碼:
Classes/Domain/Model/MyFileReference.php
config.tx_extbase.persistence.classes
也沒有必要 僅需要TCA代碼,並且使用不同的語法。
但是我無法弄清楚為什么這種語法有效,而普通語法卻沒有。
感謝所有答案!
您是否也在引用sys_file_reference實現?
所以,看起來可能像那樣
/**
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\LISARDO\Foerderland\Domain\Model\MyFileReference>
* @lazy
*/
protected $media;
眾所周知,您可以使用{image.properties.nofollow}
在流體中訪問您自己的屬性。
您需要參考您的自定義實現。
可以按照喬治·林格 ( Georg Ringer)的建議進行操作,也可以在TS級別上替換該類,如下所示:
plugin.tx_yourext {
objects {
TYPO3\CMS\Extbase\Domain\Model\FileReference {
className = LISARDO\Foerderland\Domain\Model\MyFileReference
}
}
}
這將自動實例化MyFileReference
而不是在引用它的所有屬性中實例化核心的FileReference
,還包括@inject
和ObjectManager->get()
調用。
如果要在全局級別(對於所有插件,包括核心)執行此操作,只需在上述TS tx_yourext
tx_extbase
更改為tx_extbase
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.