Created
March 23, 2021 22:40
-
-
Save dachande/f9e8be81bea9ca9eb76b1ce1246f18a0 to your computer and use it in GitHub Desktop.
TYPO3 Content Element Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# customsubcategory=cetemplates=Content Element Templates | |
styles { | |
templates { | |
# cat=goldgas - base/cetemplates/101/100; type=string; label=Template Root Path | |
templateRootPath = EXT:goldgas_base/Resources/Private/Templates/ContentElements/ | |
# cat=goldgas - base/cetemplates/101/110; type=string; label=Partial Root Path | |
partialRootPath = EXT:goldgas_base/Resources/Private/Partials/ContentElements/ | |
# cat=goldgas - base/cetemplates/101/120; type=string; label=Layout Root Path | |
layoutRootPath = EXT:goldgas_base/Resources/Private/Layouts/ContentElements/ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('TYPO3_MODE') or die(); | |
call_user_func(function () { | |
$ll = 'LLL:EXT:goldgas_base/Resources/Private/Language/locallang_db.xlf:tt_content.'; | |
// Add Content Element | |
if (!is_array($GLOBALS['TCA']['tt_content']['types']['gg_textmedia'])) { | |
$GLOBALS['TCA']['tt_content']['types']['gg_textmedia'] = []; | |
} | |
// Add content element to selector list | |
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem( | |
'tt_content', | |
'CType', | |
[ | |
'LLL:EXT:goldgas_base/Resources/Private/Language/locallang_be.xlf:content_element.gg_textmedia.title', | |
'gg_textmedia', | |
'tx-goldgasbase-ce-textmedia' | |
], | |
'gg_teasers', | |
'after' | |
); | |
// Assign icon | |
$GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['gg_textmedia'] = 'tx-goldgasbase-ce-textmedia'; | |
// Configure element type | |
$GLOBALS['TCA']['tt_content']['types']['gg_textmedia'] = array_replace_recursive( | |
$GLOBALS['TCA']['tt_content']['types']['gg_textmedia'], | |
[ | |
'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;header_minimal, | |
bodytext, | |
--palette--;;cta, | |
--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.images, | |
image, | |
--div--;LLL:EXT:goldgas_base/Resources/Private/Language/locallang_be.xlf:content_element.gg_textmedia.tab.download, | |
assets, | |
--div--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:tabs.appearance, | |
--palette--;;frames_custom,header_position, | |
--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:notes, | |
rowDescription, | |
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:extended, | |
', | |
'columnsOverrides' => [ | |
'bodytext' => [ | |
'config' => [ | |
'enableRichtext' => true, | |
], | |
], | |
'image' => [ | |
'config' => [ | |
'minitems' => 0, | |
'maxitems' => 6, | |
'appearance' => [ | |
'fileUploadAllowed' => false, | |
], | |
'filter' => [ | |
0 => [ | |
'parameters' => [ | |
'allowedFileExtensions' => 'jpg,jpeg,png,svg', | |
], | |
], | |
], | |
'overrideChildTca' => [ | |
'columns' => [ | |
'uid_local' => [ | |
'config' => [ | |
'appearance' => [ | |
'elementBrowserAllowed' => 'jpg,jpeg,png,svg', | |
], | |
], | |
], | |
], | |
], | |
], | |
], | |
'assets' => [ | |
'label' => $ll . 'field.assets.override.files', | |
'config' => [ | |
'minitems' => 0, | |
'maxitems' => 99, | |
'appearance' => [ | |
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:media.addFileReference', | |
'fileUploadAllowed' => false, | |
], | |
'filter' => [ | |
0 => [ | |
'parameters' => [ | |
'allowedFileExtensions' => 'ppt,pptx,doc,docx,xls,xlsx,pdf,zip', | |
], | |
], | |
], | |
'overrideChildTca' => [ | |
'columns' => [ | |
'uid_local' => [ | |
'config' => [ | |
'appearance' => [ | |
'elementBrowserAllowed' => 'ppt,pptx,doc,docx,xls,xlsx,pdf,zip', | |
], | |
], | |
], | |
], | |
'types' => [ | |
'0' => [ | |
'showitem' => ' | |
--palette--;;basicoverlayPalette, | |
--palette--;;filePalette' | |
], | |
\TYPO3\CMS\Core\Resource\File::FILETYPE_TEXT => [ | |
'showitem' => ' | |
--palette--;;basicoverlayPalette, | |
--palette--;;filePalette' | |
], | |
\TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE => [ | |
'showitem' => ' | |
--palette--;;imageoverlayPalette, | |
--palette--;;filePalette' | |
], | |
\TYPO3\CMS\Core\Resource\File::FILETYPE_AUDIO => [ | |
'showitem' => ' | |
--palette--;;audioOverlayPalette, | |
--palette--;;filePalette' | |
], | |
\TYPO3\CMS\Core\Resource\File::FILETYPE_VIDEO => [ | |
'showitem' => ' | |
--palette--;;videoOverlayPalette, | |
--palette--;;filePalette' | |
], | |
\TYPO3\CMS\Core\Resource\File::FILETYPE_APPLICATION => [ | |
'showitem' => ' | |
--palette--;;basicoverlayPalette, | |
--palette--;;filePalette' | |
], | |
], | |
], | |
], | |
] | |
], | |
], | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('TYPO3_MODE') or die(); | |
call_user_func(function () { | |
// Add custom icons | |
$icons = [ | |
[ | |
'tx-goldgasbase-ce-textmedia', | |
'EXT:goldgas_base/Resources/Public/Icons/ContentElements/TextMedia.svg', | |
], | |
]; | |
\Goldgas\Base\Utility\IconUtility::registerIcons($icons); | |
// Add page TSconfig | |
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(' | |
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:goldgas_base/Configuration/PageTSconfig/" extensions="tsconfig"> | |
'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Table structure for table 'tt_content' | |
# | |
CREATE TABLE tt_content ( | |
cta_link varchar(1024) DEFAULT '' NOT NULL, | |
cta_text varchar(255) DEFAULT '' NOT NULL, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Goldgas\Base\DataProcessing; | |
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface; | |
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; | |
use TYPO3\CMS\Core\Utility\GeneralUtility; | |
use TYPO3\CMS\Core\Service\FlexFormService; | |
class FlexFormProcessor implements DataProcessorInterface | |
{ | |
/** | |
* Process content object data | |
* | |
* @param \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $cObj | |
* @param array $contentObjectConfiguration | |
* @param array $processorConfiguration | |
* @param array $processedData | |
* @return array | |
*/ | |
public function process( | |
ContentObjectRenderer $cObj, | |
array $contentObjectConfiguration, | |
array $processorConfiguration, | |
array $processedData | |
): array { | |
if (isset($processorConfiguration['if.']) && !$cObj->checkIf($processorConfiguration['if.'])) { | |
return $processedData; | |
} | |
// set targetvariable, default "flexform" | |
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'flexform'); | |
// set fieldname, default "pi_flexform" | |
$fieldName = $cObj->stdWrapValue('fieldName', $processorConfiguration, 'pi_flexform'); | |
// parse flexform | |
$flexformService = GeneralUtility::makeInstance(FlexFormService::class); | |
$processedData[$targetVariableName] = $flexformService->convertFlexFormContentToArray($cObj->data[$fieldName]); | |
// if targetvariable is settings, try to merge it with contentObjectConfiguration['settings.'] | |
if ($targetVariableName == 'settings') { | |
if (is_array($contentObjectConfiguration['settings.'])) { | |
$convertedConf = GeneralUtility::removeDotsFromTS($contentObjectConfiguration['settings.']); | |
foreach ($convertedConf as $key => $value) { | |
if (!isset($processedData[$targetVariableName][$key]) || | |
$processedData[$targetVariableName][$key] == false | |
) { | |
$processedData[$targetVariableName][$key] = $value; | |
} | |
} | |
} | |
} | |
return $processedData; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create custom content element library from fluid_styled_content | |
lib.customContentElement =< lib.contentElement | |
lib.customContentElement { | |
# Important definition making LLL:EXT:... definition obsolete in | |
# f:translate ViewHelper in content element flud templates. | |
extbase.controllerExtensionName = GoldgasBase | |
# Add FlexFormProcessor as default to make flexform configuration settings | |
# available in content element fluid templates. | |
dataProcessing.100 = Goldgas\Base\DataProcessing\FlexFormProcessor | |
dataProcessing.100 { | |
if.isTrue.field = pi_flexform | |
fieldName = pi_flexform | |
as = settings | |
} | |
} | |
<INCLUDE_TYPOSCRIPT: source="DIR:EXT:goldgas_base/Configuration/TypoScript/ContentElements/Elements" extensions="typoscript"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html | |
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" | |
xmlns:sms="http://typo3.org/ns/Sitegeist/ResponsiveImages/ViewHelpers" | |
xmlns:ib="http://typo3.org/ns/Goldgas/Infobubble/ViewHelpers" | |
data-namespace-typo3-fluid="true" | |
> | |
<f:layout name="Default" /> | |
<f:section name="Main"> | |
Lorem Ipsum dolor sit amet... | |
</f:section> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod.wizards.newContentElement.wizardItems.goldgas_base { | |
elements { | |
gg_textmedia { | |
iconIdentifier = tx-goldgasbase-ce-textmedia | |
title = LLL:EXT:goldgas_base/Resources/Private/Language/locallang_be.xlf:content_element.gg_textmedia.title | |
description = LLL:EXT:goldgas_base/Resources/Private/Language/locallang_be.xlf:content_element.gg_textmedia.description | |
tt_content_defValues { | |
CType = gg_textmedia | |
} | |
} | |
} | |
show := addToList(gg_textmedia) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tt_content.gg_textmedia > | |
tt_content.gg_textmedia =< lib.customContentElement | |
tt_content.gg_textmedia { | |
templateName = TextMedia | |
dataProcessing { | |
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor | |
10 { | |
references { | |
fieldName = image | |
} | |
as = images | |
} | |
20 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor | |
20 { | |
references { | |
fieldName = assets | |
} | |
as = files | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('TYPO3_MODE') or die(); | |
call_user_func(function () { | |
$ll = 'LLL:EXT:goldgas_base/Resources/Private/Language/locallang_db.xlf:tt_content.'; | |
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTcaSelectItem( | |
'tt_content', | |
'CType', | |
[ | |
'LLL:EXT:goldgas_base/Resources/Private/Language/locallang_be.xlf:content_element_wizard.goldgas_base.header', | |
'--div--' | |
], | |
'--div--', | |
'before' | |
); | |
// Add columns to tt_content TCA definition for custom content elements and generic usage | |
$columns = [ | |
'cta_link' => [ | |
'exclude' => true, | |
'label' => $ll . 'field.cta_link', | |
'config' => [ | |
'type' => 'input', | |
'renderType' => 'inputLink', | |
'size' => 50, | |
'max' => 1024, | |
'eval' => 'trim', | |
'fieldControl' => [ | |
'linkPopup' => [ | |
'options' => [ | |
'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:header_link_formlabel', | |
], | |
], | |
], | |
'softref' => 'typolink' | |
] | |
], | |
'cta_text' => [ | |
'exclude' => true, | |
'label' => $ll . 'field.cta_text', | |
'config' => [ | |
'type' => 'input', | |
'size' => 50, | |
'max' => 255, | |
'eval' => 'trim', | |
], | |
], | |
]; | |
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content', $columns); | |
// Add palettes for generic usage | |
$GLOBALS['TCA']['tt_content']['palettes'] = array_merge_recursive( | |
$GLOBALS['TCA']['tt_content']['palettes'], | |
[ | |
'header_minimal' => [ | |
'label' => $GLOBALS['TCA']['tt_content']['palettes']['header']['label'], | |
'showitem' => ' | |
header, | |
', | |
], | |
'headers_minimal' => [ | |
'label' => $GLOBALS['TCA']['tt_content']['palettes']['headers']['label'], | |
'showitem' => ' | |
header, | |
--linebreak--, | |
subheader, | |
', | |
], | |
'frames_custom' => [ | |
'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.frames', | |
'showitem' => ' | |
frame_class;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:frame_class_formlabel, | |
space_after_class;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:space_after_class_formlabel, | |
', | |
], | |
'cta' => [ | |
'label' => $ll . 'palette.cta', | |
'showitem' => ' | |
cta_link, | |
cta_text, | |
', | |
], | |
] | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mod.wizards.newContentElement.wizardItems { | |
goldgas_base.header = LLL:EXT:goldgas_base/Resources/Private/Language/locallang_be.xlf:content_element_wizard.goldgas_base.header | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment