我想在TYPO3 8.7.16上创建一个自定义内容元素,但是到目前为止我所看到的所有指南已经过时,或者某些设置不适用于当前的TYPO3版本。因此,对于这个示例,如果有人能指出我正确的方向,我将非常感激。
概念
我想制作一个Slider:
到目前为止,我已经知道了:
TSConfig
mod.wizards.newContentElement.wizardItems.my_slider {
header = Slider
after = common
elements {
my_slider {
iconIdentifier = EXT:ak_extension_base/Resources/Public/Icon/Slider.svg
title = Slider
description = Create a Slider
tt_content_defValues {
CType = my_slider
}
}
}
show := addToList(my_slider)
}
配置/TCA/Overrides/tt_content.php
((使其在列表上显示时可见)
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
array(
'Slider',
'my_slider',
'EXT:ak_extension_base/Resources/Public/Icons/Slider.svg'
),
'CType',
'ak_extension_base'
);
在同一文件上,我也获得了以下代码:
$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,
image;Slider_Image,
bodytext;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:bodytext_formlabel,
--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.frames;frames,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.appearanceLinks;appearanceLinks,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:language,
--palette--;;language,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
--palette--;;hidden,
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.access;access,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:categories,
categories,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:notes,
rowDescription,
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended,
',
'columnsOverrides' => [
'bodytext' => [
'config' => [
'enableRichtext' => true,
'richtextConfiguration' => 'default'
]
],
'image' => [
'label' => 'Slider Image',
'config' => [
'type' => 'inline',
],
],
]
);
到目前为止一切正常。我将滑块放在其自己的标签上,一切正常。
编辑:我已经找到了在TCA上添加图像的方法。
现在,我想为此内容元素(滑块)创建模板。我知道我必须包含一个静态文件。所以我做到了:
TCA / Overrides / sys_template.php
<?php
// Add an entry in the static template list found in sys_templates for static TS
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
'ak_extension_base',
'Configuration/TypoScript',
'Include Slider'
);
?>
有了这个,我在列表上得到了静态模板,我可以将其包括在内。
现在我需要声明我的流体模板,以便在打字稿上具有以下内容:
tt_content {
my_slider < lib.contentElement
my_slider {
templateName = Slider
dataProcessing {
1 = Vendor\AkExtensionBase\DataProcessing\SliderProcessor
1 {
useHere = theConfigurationOfTheDataProcessor
}
}
}
}
起初,我有这个SliderProcessor作为NewContentElementProcessor,并且当我添加内容元素时,出现一个错误,提示说NewContentElementProcessor不存在。因此,我进行了更正,然后,出现了 500错误。因此,在此之后的某处,我配置了错误的内容。这是我其余的代码。
TYPOSCRIPT
lib.contentElement {
templateRootPaths {
200 = EXT:ak_extension_base/Resources/Private/Templates/
}
}
类/数据处理/SliderProcessor.php
<?php
namespace Vendor\AkExtensionBase\DataProcessing;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
class SliderProcessor implements DataProcessorInterface
{
/**
* Process data for the content element "My new content element"
*
* @param ContentObjectRenderer $cObj The data of the content element or page
* @param array $contentObjectConfiguration The configuration of Content Object
* @param array $processorConfiguration The configuration of this processor
* @param array $processedData Key/value store of processed data (e.g. to be passed to a Fluid View)
* @return array the processed data as key/value store
*/
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
)
{
$processedData['slider'] = 'This variable will be passed to Fluid';
return $processedData;
}
}
类/挂钩/PageLayoutView/SliderPreviewRender.php
<?php
namespace Vendor\AkExtensionBase\Hooks\PageLayoutView;
use \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use \TYPO3\CMS\Backend\View\PageLayoutView;
class SliderPreviewRenderer implements PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of a content element of type "My new content element"
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionality
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*
* @return void
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
)
{
if ($row['CType'] === 'my_slider') {
$itemContent .= '<p>We can change our preview here!</p>';
$drawItem = false;
}
}
}
资源/私人/模板/Slider.html
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true">
<h1>{slider}</h1>
</html>
所以有什么想法我做错了吗?还有我没有想到的其他方式吗?
编辑,我可以将问题范围缩小到数据处理。一路上我迷路了。例如,我不知道tt_content上的数据处理器的配置是什么。
编辑2 我已经找到了在前端显示所有内容的方法。
已按照本文档采取的措施。 Dokumentation