繁体   English   中英

TYPO3如何在TCA上添加“创建新按钮”?

[英]TYPO3 How to add Create new button on TCA?

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

这样的事情。

部分

我怎样才能做到这一点?

到目前为止,我有:

TCA /覆盖/ 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>

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

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

配置/ TCA /覆盖/ 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 /覆盖/ 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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