[英]TYPO3 extend tt_content with FAL image and display in frontend
我想用圖像擴展 tt_content 表。 應該可以在每個內容元素中設置此圖像。 這是我到目前為止得到的
ext_tables.sql
CREATE TABLE tt_content (
tx_layout_background_image int(11) unsigned DEFAULT '0' NOT NULL,
);
排版:
page.10 = FLUIDTEMPLATE
page.10 {
templateName = TEXT
templateName.stdWrap.cObject = CASE
templateName.stdWrap.cObject {
key.data = pagelayout
pagets__kubus_layout = TEXT
pagets__kubus_layout.value = Default
default = TEXT
default.value = Default
}
templateRootPaths {
0 = {$resDir}/Private/Templates/Page/
}
partialRootPaths {
0 = {$resDir}/Private/Partials/Page/
}
layoutRootPaths {
0 = {$resDir}/Private/Layouts/Page/
}
dataProcessing {
20 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
20 {
references {
table = tt_content
uid.field = uid
fieldName = tx_layout_background_image
}
as = images
}
}
}
覆蓋/tt_content.php
<?php
$temporaryColumn = array(
'tx_layout_background_image' => [
'label' => 'BG Image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'tx_layout_background_image',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference'
],
'overrideChildTca' => [
'columns' => [
'crop' => [
'description' => 'field description',
],
],
'types' => [
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
'showitem' => '
--palette--;;imageoverlayPalette,
--palette--;;filePalette'
],
],
],
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$temporaryColumn
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addFieldsToPalette(
'tt_content',
'layout',
'tx_layout_background_image',
'after:layout'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'--div--;Layout,
--palette--;;layout',
'',
''
);
問題是我只是在數據數組中得到這個
data.tx_layout_background_image => 1 (integer)
我怎樣才能從中得到圖像? 我用treatasreference嘗試過,但我沒有得到正確的圖像對象。
編輯
有了這個,它似乎在工作
lib.contentElement {
dataProcessing.99 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
dataProcessing.99 {
as = backgroundImages
references.fieldName = tx_layout_background_image
references.table = tt_content
}
}
您在該字段中找到的1
是對該字段的引用數。 真實的關系存儲在另一條記錄中。
由於發明了 FAL(文件抽象層),對文件的引用不再存儲為文件的路徑和名稱,而是由記錄 ( sys_file
) 表示,其中存儲了路徑和名稱(以及更多信息)。 與表sys_file_reference
中的 mm-records 建立關系。 它由字段組成
uid_local
( sys_file
記錄的uid
)uid_foreign
(相關記錄的uid
)tt_content
tablenames
fieldname
名(該記錄中的字段名稱,因為可能有多個具有文件關系的字段:您的字段名稱: tx_layout_background_image
)sorting_foreign
(如果多個文件可能相關,則給出命令)table_local
(總是sys_file
)現在您可以對此相關記錄進行顯式查詢。
但是您也可以使用可以為您處理它的數據處理器:
當您使用文件時,它應該是您在代碼中使用的文件處理器。
但是您錯過了正確的上下文。
要么您將該字段插入到錯誤的表中( tt_content
而不是pages
)。
或者您在錯誤的表上使用了文件處理器: tt_content 記錄的呈現不是在page.10
中完成,而是在tt_content.<cType>
中完成,例如:
例子:
tt_content.my_custom_ctype = FLUIDTEMPLATE
tt_content.my_custom_ctype {
:
dataProcessing.10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
dataProcessing.10 {
as = backgroundImages
references.fieldName = tx_layout_background_image
references.table = tt_content
}
}
如果您希望將其添加到每個 cType,您可以將其添加到lib.contentElement
中,這是所有內容元素的原型,從中復制/引用到所有 cType。
lib.contentElement {
dataProcessing.10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
dataProcessing.10 {
as = backgroundImages
references.fieldName = tx_layout_background_image
references.table = tt_content
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.