簡體   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