【问题标题】:TYPO3 How to add Create new button on TCA?TYPO3 如何在 TCA 上添加创建新按钮?
【发布时间】:2018-07-03 10:47:33
【问题描述】:

我想构建一个滑块(自己的内容元素)。所以在后端我想有一个包含多条记录的部分。我是什么意思?通过单击“新建”,我想要一个图像选择和富文本选择。

类似的东西。

我怎样才能做到这一点?

到目前为止我有:

TCA/Overrides/tt_content.php

这为我提供了丰富的编辑器和后端的图像选择,但没有分组。

$GLOBALS['TCA']['tt_content']['types']['my_slider'] = array(   'showitem' => '   
    --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
    --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
    --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media, 
   ',    
    'columnsOverrides' => [
          'bodytext' => [
             'config' => [
                'enableRichtext' => true,
                'richtextConfiguration' => 'default'
             ]
         ]  
      ]
    );

tt_content.typosript

tt_content {
 my_slider < lib.contentElement
 my_slider {
  templateRootPaths.10 = {$Private}Templates/
  templateName = Slider.html
  dataProcessing {
    10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
    10 {
      references.fieldName = assets
      as = images
    }
  }
}
}

Slider.html

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
      data-namespace-typo3-fluid="true">

  <h1>{data.header}</h1>
  <p>{data.bodytext}</p>
   <f:for each="{images}" as="image">
     <f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
      {image.description}
  </f:for>
   <f:debug>{data}</f:debug>
</html>

现在使用当前代码,我可以在前端获得结果。一个文本和一个图像。但是在后端配置后如何将其作为组获取?

【问题讨论】:

    标签: php typo3 fluid


    【解决方案1】:

    您需要向sys_file_reference TCA 添加新字段:

    配置/TCA/Overrides/sys_file_reference.php

    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
        'sys_file_reference',
        [
            'tx_myext_description' => [
                'label' => 'My field description',
                'config' => [
                    'type' => 'text',
                    'cols' => '80',
                    'rows' => '15',
                    'enableRichtext' => true,
                    'richtextConfiguration' => 'default'
                ]
            ],
        ]
    );
    

    ext_tables.sql

    CREATE TABLE sys_file_reference (
      tx_myext_description mediumtext,
    );
    

    记得在数据库中添加新字段(使用安装工具中的数据库比较工具)。

    然后在新滑块的 TCA 中使用它:

    配置/TCA/Overrides/tt_content.php

    $GLOBALS['TCA']['tt_content']['types']['my_slider'] = [
        'showitem' => '
        --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
        --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,
        --palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.headers;headers,bodytext,assets;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
       ',
        'columnsOverrides' => [
            'bodytext' => [
                'config' => [
                    'enableRichtext' => true,
                    'richtextConfiguration' => 'default'
                ]
            ],
            'assets' => [
                'config' => [
                    'overrideChildTca' => [
                        'types' => [
                            0 => ['showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][0]['showitem'].',tx_myext_description'],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [
                                'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT]['showitem'].',tx_myext_description'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [
                                'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE]['showitem'].',tx_myext_description'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [
                                'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO]['showitem'].',tx_myext_description'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [
                                'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO]['showitem'].',tx_myext_description'
                            ],
                            \TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [
                                'showitem' => $GLOBALS['TCA']['sys_file_reference']['types'][\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION]['showitem'].',tx_myext_description'
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ];
    

    然后您的 Fluid 模板可能如下所示:

    Slider.html

    <html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
          data-namespace-typo3-fluid="true">
    
    <h1>{data.header}</h1>
    <p>{data.bodytext}</p>
    <f:for each="{images}" as="image">
        <f:image image="{image}" alt="{file.properties.alt}" cropVariant="desktop"/>
        {image.properties.tx_myext_description -> f:format.html()}
    </f:for>
    </html>
    

    【讨论】:

    • 您似乎在图片的标题上启用了覆盖面编辑器。这是一个好主意,但我希望在创建多个记录时将图像和文本编辑器分开。您从我这里得到 +1,因为它在技术上是一种解决方案。只是不是我要找的那个。 :)
    • @AristeidisKaravas 刚刚调整了上面帖子中的代码。现在它与图像分离了 - 描述和以前一样工作,而您的 RTE 内容将保留在新字段 tx_myext_description
    • @mrf 这正是我所需要的,谢谢。新领域似乎要取代 Image Manipulation 部分,这可以避免吗?以及如何删除元数据字段?
    • @mrf 没关系,我意识到我只是使用['showitem'] = 而不是['showitem'].
    猜你喜欢
    • 2012-07-01
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 2012-05-29
    相关资源
    最近更新 更多