首页 文章

TYPO3 8.7.8自定义内容元素,后端包含自定义字段

提问于
浏览
0

我一直在寻找相当长的一段时间但找不到我想要的东西 .

我创建了两个自定义内容元素:parallax_content和bg_image .

在目前的后端,我有一个标准textmedia元素的字段,其代码如下(来自tt_content):

array('showitem' => ' 
  --palette--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;
  general,
  --palette--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.header;
  header,
  rowDescription,
  bodytext;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext_formlabel,
  --div--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.media,
  assets,
  --palette--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.imagelinks;
  imagelinks,
  --div--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
  layout;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:layout_formlabel,
  --palette--;
  LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.palette.mediaAdjustments;mediaAdjustments,
  --palette--;
  LLL:EXT:fluid_styled_content/Resources/Private/Language/Database.xlf:tt_content.palette.gallerySettings;
  gallerySettings,
  --palette--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.appearanceLinks;appearanceLinks,
  --div--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.access,
  hidden;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:field.default.hidden,
  --palette--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.access;
  access,
  --div--;
  LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.extended,
  --div--;
  LLL:EXT:lang/locallang_tca.xlf:sys_category.tabs.category,
  categories',

  'columnsOverrides' => array(
    'bodytext' => array(
      'defaultExtras' => 'richtext:rte_transform[mode=ts_css]'
    )
  )
)

对于我的元素parallax_content,我需要以下字段:

  • Headers

  • 一个复选框"insert Logo"

  • 一个正文

  • 图像选择字段

对于image_bg,我需要:

  • 图像选择字段

  • 包含2个项目的下拉列表

但我看了documentation但是它没有再找到其他文档,我获得的信息与上面链接的信息一样"much" . 我理解一些部分,例如palette.header创建整个 Headers 调色板,包括 Headers , Headers 链接,对齐,日期等 .

所以我的问题是:

有人可以向我解释上面的代码如何工作exaclty?一个元素从哪里开始,它在哪里结束? “--palette--”和“--div--”有什么用?如何创建标签(例如一般,媒体等)?是否可以使用这些调色板创建上面列出的字段?我可以创建自己的调色板吗?如果有,怎么样?或者是否可能使用/制作我自定义字段的打字错误?或者我需要为每个元素创建一个扩展吗?如果可能的话,我想避免这种情况 .

是的,这是很多问题,我是TYPO3的新手,不仅尝试使用TYPO3,而且尽可能地理解它(至少对我需要的东西) . 我的首要任务是理解上面的代码,但任何指针,解释,帮助甚至链接到文档(我可能还没有看到目前为止),这可能导致我的请求的解决方案,我将不胜感激 . 提前致谢!

1 回答

  • 0

    在我当前的项目中,我为tt_content中的textmedia元素添加了一个视差效果 .

    首先,我覆盖tt_content TCA:

    'background_media' => array(
        'exclude' => 1,
        'l10n_mode' => 'mergeIfNotBlank',
        'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:background_media',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'background_media',
            array(
                'minitems' => 0,
                'maxitems' => 1,
                'appearance' => array(
                    'createNewRelationLinkTitle' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:add_media',
                    'showAllLocalizationLink' => 1,
                ),
                'foreign_match_fields' => array(
                    'fieldname' => 'background_media',
                    'tablenames' => 'tt_content',
                    'table_local' => 'sys_file',
                ),
                // custom configuration for displaying fields in the overlay/reference table
                // to use the newsPalette and imageoverlayPalette instead of the basicoverlayPalette
                'foreign_types' => array(
                    \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => array(
                        'showitem' => '
                                --palette--;LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.imageoverlayPalette,
                                --palette--;;imageoverlayPalette,
                                --palette--;;filePalette'
                    ),
    
                )
            ),
            $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
        )
    ),
    'effects' => [
        'exclude' => true,
        'label' => 'LLL:EXT:extension/Resources/Private/Language/locallang.xml:effects',
        'config' => [
            'type' => 'select',
            'itemsProcFunc' => 'VENDOR\Extension\UserFunction\ProviderField->createEffectItems',
            'renderType' => 'selectCheckBox',
            'multiple' => true,
            'minitems' => 0,
            'maxitems' => 999,
            'items' => []
        ]
    ],...
    
    
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $additionalColumns);
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_content', 'background_media,effects', 'textmedia', 'after:layout');
    \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tt_content', 'image_classes,text_classes', 'textmedia', 'after:layout');
    

    现在我有2个额外的字段: - 背景图像(FAL) - 自己样式的Selct Box(UserFunc)

    我的UserFunc(VENDOR \ Extension \ UserFunction \ ProviderField-> createEffectItems)

    /**
         * @param ConfigurationService $configurationService
         * @return void
         */
        public function injectConfigurationService(ConfigurationService $configurationService) {
            $this->configurationService = $configurationService;
        }
    
    public function createEffectItems($config) {
            $settings = $this->configurationService->getSettingsForExtensionName('extension');
    
            $classNames = json_decode($settings['container']['effects'],true);
            if (!is_array($classNames)) return $config;
    
            $optionList = array();
            foreach ($classNames as $key => $val) {
                $optionList[] = [$val, $key];
            }
            $config['items'] = array_merge($config['items'], $optionList);
            return $config;
        }
    

    现在我可以在Typoscript设置中定义自己的CSS类了...

    最后但并非最不重要的FluidStyleContent部分:我重写了Fluid_tyled_content模板Textmedia.html和Layout Detaulf.html .

    <v:content.resources.fal uid="{data.uid}" table="tt_content" field="background_media" as="ceBackground">
            <f:if condition="{ceBackground}">
                {v:uri.image(treatIdAsReference: 1, src: ceBackground.0.id, maxW: 1920) -> v:variable.set(name: 'parallaxBg')}
            </f:if>
        </v:content.resources.fal>
    <div id="c{data.uid}" {f:if(condition: '{parallaxBg}', then: 'style="background-image: url(\'{parallaxBg}\');" ')}">
    
    </div>
    
    For a multiple classes use: {data.effects -> v:format.replace(substring: ',', replacement: ' ')}
    

    最好的祝福

相关问题