dream04110 2018-07-03 10:47
浏览 39

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

I would like to build a slider (Own Content Element). So on the backend i would like to have a section with multiple records. What do i mean? By clicking the "Create new" i would like to have an image selection and rich text selection.

Something like that.

Section

How can i achieve this?

So far i have:

TCA/Overrides/tt_content.php

which gives me the rich editor and the image selection in backend, but not grouped.

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

Now with the current code i get the results in frontend. One Text and one Image. But how can i get it as group after configured it on the backend?

  • 写回答

1条回答 默认 最新

  • douye9175 2018-07-03 18:44
    关注

    You need add new field to the sys_file_reference TCA:

    Configuration/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,
    );
    

    Remember to add new field into database (using database compare tool in install tool).

    Then use it in TCA of your new slider:

    Configuration/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'
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ];
    

    And then your Fluid template may look like that:

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题