繁体   English   中英

TYPO3 使用 FAL 图像扩展 tt_content 并在前端显示

[英]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_localsys_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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM