简体   繁体   English

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

[英]TYPO3 extend tt_content with FAL image and display in frontend

i want to extend the tt_content table with an image.我想用图像扩展 tt_content 表。 It should be possible to set this image in every content element.应该可以在每个内容元素中设置此图像。 This is what i got so far这是我到目前为止得到的

ext_tables.sql ext_tables.sql

CREATE TABLE tt_content (
   tx_layout_background_image int(11) unsigned DEFAULT '0' NOT NULL,
);

TypoScript:排版:

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
    }
  }
}

Overrides/tt_content.php覆盖/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',
    '',
    ''
);

The Problem is that i just get this in the data array问题是我只是在数据数组中得到这个

data.tx_layout_background_image => 1 (integer)

How can i get the image from this?我怎样才能从中得到图像? I Tried it with treatasreference but i dont get the right image object.我用treatasreference尝试过,但我没有得到正确的图像对象。


Edit编辑
With this it seems like its working有了这个,它似乎在工作

lib.contentElement {
    dataProcessing.99 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
    dataProcessing.99 {
        as = backgroundImages
        references.fieldName = tx_layout_background_image
        references.table = tt_content
   }
}

The 1 you have found in the field is the number of references to this field.您在该字段中找到的1是对该字段的引用数。 The real relation is stored in another record.真实的关系存储在另一条记录中。

Since inventing FAL (File Abstraction Layer) references to files are no longer stored as path and name of the file but are represented by a record ( sys_file ), where the path and name (and further information) is stored.由于发明了 FAL(文件抽象层),对文件的引用不再存储为文件的路径和名称,而是由记录 ( sys_file ) 表示,其中存储了路径和名称(以及更多信息)。 a relation is done with mm-records in the table sys_file_reference .与表sys_file_reference中的 mm-records 建立关系。 it consists of the fields它由字段组成

  • uid_local (the uid of the sys_file -record) uid_localsys_file记录的uid
  • uid_foreign (the uid of the related record) uid_foreign (相关记录的uid
  • tablenames (name of the table of related record: tt_content in your case)表名(相关记录表的名称:在您的情况下tt_content tablenames
  • fieldname (name of the field in that record as there might be multiple fields with file relations: your field-name: tx_layout_background_image ) fieldname名(该记录中的字段名称,因为可能有多个具有文件关系的字段:您的字段名称: tx_layout_background_image
  • sorting_foreign (giving an order if multiple files could be related) sorting_foreign (如果多个文件可能相关,则给出命令)
  • table_local (always sys_file ) table_local (总是sys_file )

Now you can make an explicit query on this related records.现在您可以对此相关记录进行显式查询。


But you also can use a dataprocessor which can handle it for you:但是您也可以使用可以为您处理它的数据处理器:
As you use files it should be a filesprocessor as you used it in your code.当您使用文件时,它应该是您在代码中使用的文件处理器

But you missed the correct context.但是您错过了正确的上下文。

Either you have inserted the field to the wrong table ( tt_content instead of pages ).要么您将该字段插入到错误的表中( tt_content而不是pages )。
Or you used the filesprocessor on the wrong table: the rendering of tt_content records is not done in page.10 but in tt_content.<cType> like:或者您在错误的表上使用了文件处理器: tt_content 记录的呈现不是在page.10中完成,而是在tt_content.<cType>中完成,例如:

example:例子:

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
   }
}

If you wish to add it to every cType you can add it to lib.contentElement the prototype for all content elements from where it gets copied/referenced into all cTypes.如果您希望将其添加到每个 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