diff --git a/Classes/CodeGenerator/TcaCodeGenerator.php b/Classes/CodeGenerator/TcaCodeGenerator.php index 00829f1b..ca4ad495 100644 --- a/Classes/CodeGenerator/TcaCodeGenerator.php +++ b/Classes/CodeGenerator/TcaCodeGenerator.php @@ -18,6 +18,7 @@ namespace MASK\Mask\CodeGenerator; use InvalidArgumentException; +use MASK\Mask\Definition\ElementTcaDefinition; use MASK\Mask\Definition\PaletteDefinition; use MASK\Mask\Definition\TableDefinition; use MASK\Mask\Definition\TableDefinitionCollection; @@ -194,7 +195,21 @@ public function setElementsTca(): void [$prependTabs, $fields] = $this->generateShowItem($prependTabs, $element->key, 'tt_content'); $GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes'][$cTypeKey] = 'mask-ce-' . $element->key; - $GLOBALS['TCA']['tt_content']['types'][$cTypeKey]['columnsOverrides']['bodytext']['config']['enableRichtext'] = 1; + $elementTca = $this->tableDefinitionCollection->loadElement('tt_content', $element->key); + + // Check if the element uses the core bodytext field, and it is of type richtext. + // If so, enable the richtext editor for it. + if ($elementTca instanceof ElementTcaDefinition + && $elementTca->tcaDefinition->hasField('bodytext') + ) { + $bodytext = $elementTca->tcaDefinition->getField('bodytext'); + if ( + !$bodytext->hasFieldType($element->key) + || $bodytext->getFieldType($element->key)->equals(FieldType::RICHTEXT) + ) { + $GLOBALS['TCA']['tt_content']['types'][$cTypeKey]['columnsOverrides']['bodytext']['config']['enableRichtext'] = 1; + } + } $GLOBALS['TCA']['tt_content']['types'][$cTypeKey]['showitem'] = $prependTabs . $defaultPalette . $fields . $defaultTabs . $gridelements; } } @@ -314,12 +329,12 @@ public function generateFieldsTca(string $table): array continue; } - if (!$field->type) { + if (!$field->hasFieldType()) { $field->type = $this->tableDefinitionCollection->getFieldType($field->fullKey, $table); } // Inline: Ignore empty inline fields - if ($field->type && $field->type->isParentField() && !$this->tableDefinitionCollection->hasTable($field->fullKey)) { + if ($field->type->isParentField() && !$this->tableDefinitionCollection->hasTable($field->fullKey)) { continue; } @@ -475,7 +490,7 @@ public function generateTCAColumnsOverrides(string $table): array // Do not generate any overrides for empty inline fields. if ( - $fieldDefinition->type instanceof FieldType + $fieldDefinition->hasFieldType() && $fieldDefinition->type->equals(FieldType::INLINE) && $this->tableDefinitionCollection->loadInlineFields($fieldDefinition->fullKey, $element->key)->toArray() === [] ) { @@ -483,7 +498,7 @@ public function generateTCAColumnsOverrides(string $table): array } // Do not generate any overrides for tabs. - if ($fieldDefinition->type instanceof FieldType && $fieldDefinition->type->equals(FieldType::TAB)) { + if ($fieldDefinition->hasFieldType() && $fieldDefinition->type->equals(FieldType::TAB)) { continue; } diff --git a/Classes/Controller/AjaxController.php b/Classes/Controller/AjaxController.php index cfcee57c..9abf84c5 100644 --- a/Classes/Controller/AjaxController.php +++ b/Classes/Controller/AjaxController.php @@ -654,9 +654,10 @@ public function existingTca(ServerRequestInterface $request): Response $table = $request->getQueryParams()['table']; $type = $request->getQueryParams()['type']; $fields = ['mask' => [], 'core' => []]; + $searchFieldType = FieldType::cast($type); // Return empty result for non-shareable fields. - if (!FieldType::cast($type)->canBeShared()) { + if (!$searchFieldType->canBeShared()) { return new JsonResponse($fields); } @@ -664,7 +665,7 @@ public function existingTca(ServerRequestInterface $request): Response $isMaskField = AffixUtility::hasMaskPrefix($tcaField); // Skip the field, if it is not a mask field, AND it is not in the allow-list // AND it is also not an already defined field in the configuration. - // This may be an extension field or a core field, which was previously allowed. + // This may be an extension field or a core field (which was allowed in former Mask versions). if ( !$isMaskField && !in_array($tcaField, $allowedFields[$table] ?? [], true) @@ -677,7 +678,15 @@ public function existingTca(ServerRequestInterface $request): Response continue; } - if ($this->tableDefinitionCollection->getFieldType($tcaField, $table)->equals($type)) { + // Add the field, if the field type matches with the search type + // OR the field is the bodytext field, and we search for a text or textarea field. + $fieldType = $this->tableDefinitionCollection->getFieldType($tcaField, $table); + if ( + $fieldType->equals($type) + || ( + $tcaField === 'bodytext' && $searchFieldType->isTextareaField() + ) + ) { $key = $isMaskField ? 'mask' : 'core'; if ($isMaskField) { $label = $this->tableDefinitionCollection->findFirstNonEmptyLabel($table, $tcaField); diff --git a/Classes/Controller/FieldsController.php b/Classes/Controller/FieldsController.php index d5271985..4e0dc3d1 100644 --- a/Classes/Controller/FieldsController.php +++ b/Classes/Controller/FieldsController.php @@ -68,7 +68,7 @@ public function loadElement(ServerRequestInterface $request): Response $element = $this->tableDefinitionCollection->loadElement($table, $elementKey); $json['fields'] = []; if ($element) { - $json['fields'] = $this->addFields($element->tcaDefinition->toArray(), $table, $elementKey); + $json['fields'] = $this->addFields($element->getRootTcaFields()->toArray(), $table, $elementKey); } return new JsonResponse($json); @@ -123,7 +123,7 @@ protected function addFields(array $fields, string $table, string $elementKey = $newField['description'] = $this->tableDefinitionCollection->getDescription($elementKey, $newField['key'], $table); } - $fieldType = $this->tableDefinitionCollection->getFieldType($newField['key'], $table); + $fieldType = $this->tableDefinitionCollection->getFieldType($newField['key'], $table, $elementKey); // Convert old date format Y-m-d to d-m-Y $dbType = $field['config']['dbType'] ?? false; diff --git a/Classes/Definition/ElementTcaDefinition.php b/Classes/Definition/ElementTcaDefinition.php index f5b41112..1c2e7e1d 100644 --- a/Classes/Definition/ElementTcaDefinition.php +++ b/Classes/Definition/ElementTcaDefinition.php @@ -32,13 +32,18 @@ final class ElementTcaDefinition public function __construct(ElementDefinition $elementDefinition, TcaDefinition $tcaDefinition) { $this->elementDefinition = $elementDefinition; - $this->tcaDefinition = new TcaDefinition(); + $this->tcaDefinition = $tcaDefinition; + } - foreach ($this->elementDefinition->columns as $field) { - if ($tcaDefinition->hasField($field)) { - $this->tcaDefinition->addField($tcaDefinition->getField($field)); + public function getRootTcaFields(): TcaDefinition + { + $tcaDefinition = new TcaDefinition(); + foreach ($this->elementDefinition->columns as $column) { + if ($this->tcaDefinition->hasField($column)) { + $tcaDefinition->addField($this->tcaDefinition->getField($column)); } } + return $tcaDefinition; } public function toArray(): array diff --git a/Classes/Definition/TableDefinitionCollection.php b/Classes/Definition/TableDefinitionCollection.php index 54834d6e..70d1602b 100644 --- a/Classes/Definition/TableDefinitionCollection.php +++ b/Classes/Definition/TableDefinitionCollection.php @@ -154,16 +154,26 @@ public function loadElement(string $table, string $key): ?ElementTcaDefinition } $element = $elements->getElement($key); - return new ElementTcaDefinition($element, $tableDefinition->tca); + $tcaDefinition = new TcaDefinition(); + foreach ($element->columns as $fieldKey) { + if ($tableDefinition->tca->hasField($fieldKey)) { + $availableTcaField = $tableDefinition->tca->getField($fieldKey); + $tcaDefinition->addField($availableTcaField); + if ($availableTcaField->hasFieldType() && $availableTcaField->type->equals(FieldType::PALETTE)) { + $paletteFields = $this->loadInlineFields($availableTcaField->fullKey, $element->key); + foreach ($paletteFields as $paletteField) { + $tcaDefinition->addField($paletteField); + } + } + } + } + + return new ElementTcaDefinition($element, $tcaDefinition); } /** * Loads all the inline fields of an inline-field, recursively! * Not specifying an element key means, the parent key has to be an inline table. - * - * @param string $parentKey - * @param string $elementKey - * @return NestedTcaFieldDefinitions */ public function loadInlineFields(string $parentKey, string $elementKey): NestedTcaFieldDefinitions { @@ -193,8 +203,8 @@ public function loadInlineFields(string $parentKey, string $elementKey): NestedT continue; } - // This can be called very early, so ignore core fields. - if (!$field->isCoreField) { + // Check if FieldType is available + if ($field->hasFieldType()) { $fieldType = $this->getFieldType($field->fullKey, $tableDefinition->table); if ($fieldType->isParentField()) { foreach ($this->loadInlineFields($field->fullKey, $elementKey) as $inlineField) { @@ -210,31 +220,31 @@ public function loadInlineFields(string $parentKey, string $elementKey): NestedT return $nestedTcaFields; } - public function getFieldType(string $fieldKey, string $table = 'tt_content'): FieldType + public function getFieldType(string $fieldKey, string $table = 'tt_content', string $elmentKey = ''): FieldType { - return FieldType::cast($this->getFieldTypeString($fieldKey, $table)); + return FieldType::cast($this->getFieldTypeString($fieldKey, $table, $elmentKey)); } /** * Returns the formType of a field in an element * @internal */ - public function getFieldTypeString(string $fieldKey, string $table = 'tt_content'): string + public function getFieldTypeString(string $fieldKey, string $table = 'tt_content', string $elementKey = ''): string { - // @todo Allow bodytext to be normal TEXT field. - if ($fieldKey === 'bodytext' && $table === 'tt_content') { - return FieldType::RICHTEXT; - } - $fieldDefinition = $this->loadField($table, $fieldKey); - if ($fieldDefinition !== null && !$fieldDefinition->isCoreField) { + if ($fieldDefinition instanceof TcaFieldDefinition) { // If type is already known, return it. - if ($fieldDefinition->type) { - return (string)$fieldDefinition->type; + if ($fieldDefinition->hasFieldType($elementKey)) { + return (string)$fieldDefinition->getFieldType($elementKey); } - return FieldTypeUtility::getFieldType($fieldDefinition->toArray(), $fieldDefinition->fullKey); + try { + return FieldTypeUtility::getFieldType($fieldDefinition->toArray(), $fieldDefinition->fullKey); + } catch (InvalidArgumentException $e) { + // For core fields this exception might pop up, because in older + // Mask versions no type was defined directly in the definition. + } } // If field could not be found in field definition, check for global TCA. diff --git a/Classes/Definition/TcaFieldDefinition.php b/Classes/Definition/TcaFieldDefinition.php index 57c6e9c4..c9e5bdb5 100644 --- a/Classes/Definition/TcaFieldDefinition.php +++ b/Classes/Definition/TcaFieldDefinition.php @@ -77,6 +77,11 @@ final class TcaFieldDefinition */ public $inlineParentByElement = []; + /** + * @var array + */ + public $bodytextTypeByElement = []; + /** * @var string */ @@ -195,6 +200,11 @@ public static function createFromFieldArray(array $definition): TcaFieldDefiniti $tcaFieldDefinition->type = FieldType::cast(FieldType::RICHTEXT); } + // The core field bodytext used to be hard coded as richtext in Mask versions < v7.2 + if (!$tcaFieldDefinition->type instanceof FieldType && $definition['key'] === 'bodytext') { + $tcaFieldDefinition->type = FieldType::cast(FieldType::RICHTEXT); + } + // If the field is not a core field and the field type couldn't be resolved by now, resolve type by tca config. if (!$tcaFieldDefinition->type instanceof FieldType && !$tcaFieldDefinition->isCoreField) { $tcaFieldDefinition->type = FieldType::cast(FieldTypeUtility::getFieldType($tcaFieldDefinition->toArray(), $tcaFieldDefinition->fullKey)); @@ -215,6 +225,14 @@ public static function createFromFieldArray(array $definition): TcaFieldDefiniti } } + if (!empty($definition['bodytextTypeByElement'])) { + foreach ($definition['bodytextTypeByElement'] as $elementKey => $bodytextType) { + $tcaFieldDefinition->bodytextTypeByElement[$elementKey] = FieldType::cast($bodytextType); + } + // Unset the normal type + $tcaFieldDefinition->type = null; + } + if (isset($definition['label'])) { if (is_array($definition['label'])) { $tcaFieldDefinition->labelByElement = $definition['label']; @@ -550,4 +568,22 @@ protected static function migrateTCA(array $definition, TcaFieldDefinition $tcaF return $definition; } + + public function hasFieldType(string $elementKey = ''): bool + { + return $this->type instanceof FieldType || ($elementKey !== '' && !empty($this->bodytextTypeByElement)); + } + + public function getFieldType(string $elementKey = ''): FieldType + { + if (!$this->hasFieldType($elementKey)) { + throw new \OutOfBoundsException('The field "' . $this->fullKey . '" does not have a defined field type.', 1650054092); + } + + if ($this->type instanceof FieldType) { + return $this->type; + } + + return $this->bodytextTypeByElement[$elementKey] ?? new FieldType(FieldType::RICHTEXT); + } } diff --git a/Classes/Domain/Repository/StorageRepository.php b/Classes/Domain/Repository/StorageRepository.php index 69bcb72d..8812f87a 100644 --- a/Classes/Domain/Repository/StorageRepository.php +++ b/Classes/Domain/Repository/StorageRepository.php @@ -18,6 +18,7 @@ namespace MASK\Mask\Domain\Repository; use MASK\Mask\ConfigurationLoader\ConfigurationLoaderInterface; +use MASK\Mask\Definition\ElementTcaDefinition; use MASK\Mask\Definition\TableDefinitionCollection; use MASK\Mask\Definition\TcaFieldDefinition; use MASK\Mask\Enumeration\FieldType; @@ -302,6 +303,11 @@ protected function addFieldsToJson(array $jsonAdd, array $fields, string $elemen } } + if ($fieldAdd['key'] === 'bodytext') { + $fieldAdd['bodytextTypeByElement'][$elementKey] = $fieldAdd['type']; + unset($fieldAdd['type']); + } + // Add tca entry for field $jsonAdd[$table]['tca'][$field['key']] = $fieldAdd; diff --git a/Classes/Enumeration/FieldType.php b/Classes/Enumeration/FieldType.php index 01402edf..f7c5abed 100644 --- a/Classes/Enumeration/FieldType.php +++ b/Classes/Enumeration/FieldType.php @@ -79,4 +79,9 @@ public function isFileReference(): bool { return in_array($this->value, [self::FILE, self::MEDIA], true); } + + public function isTextareaField(): bool + { + return in_array($this->value, [self::TEXT, self::RICHTEXT], true); + } } diff --git a/Tests/Unit/CodeGenerator/TcaCodeGeneratorTest.php b/Tests/Unit/CodeGenerator/TcaCodeGeneratorTest.php index ed13f885..70982e86 100644 --- a/Tests/Unit/CodeGenerator/TcaCodeGeneratorTest.php +++ b/Tests/Unit/CodeGenerator/TcaCodeGeneratorTest.php @@ -1007,7 +1007,8 @@ public function setElementsTcaDataProvider(): array ], 'mask_element1', '--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,header,bodytext,--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,--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,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', - [] + [], + true, ], 'Hidden elements are ignored' => [ [ @@ -1040,7 +1041,8 @@ public function setElementsTcaDataProvider(): array ], 'mask_element1', '', - [] + [], + false, ], 'Empty inline fields are ignored' => [ [ @@ -1080,7 +1082,8 @@ public function setElementsTcaDataProvider(): array ], 'mask_element1', '--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,header,--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,--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,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', - [] + [], + false, ], 'General tab can be overriden' => [ [ @@ -1120,7 +1123,8 @@ public function setElementsTcaDataProvider(): array ], 'mask_element1', '--div--;My Tab,--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:palette.general;general,header,bodytext,--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,--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,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', - [] + [], + true, ], 'Tabs can be added after elements' => [ [ @@ -1160,7 +1164,8 @@ public function setElementsTcaDataProvider(): array ], 'mask_element1', '--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,header,--div--;My Tab,bodytext,--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,--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,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', - [] + [], + true, ], 'Palettes can be added' => [ [ @@ -1202,7 +1207,10 @@ public function setElementsTcaDataProvider(): array 'key' => 'header' ], 'bodytext' => [ - 'key' => 'bodytext' + 'key' => 'bodytext', + 'inlineParent' => [ + 'element1' => 'tx_mask_my_palette', + ], ] ], 'palettes' => [ @@ -1231,7 +1239,8 @@ public function setElementsTcaDataProvider(): array 'description' => 'Palette Description old position works', 'showitem' => '' ] - ] + ], + true, ], 'Linebreaks converted to --linebreak--' => [ [ @@ -1269,7 +1278,11 @@ public function setElementsTcaDataProvider(): array 'key' => 'header' ], 'bodytext' => [ - 'key' => 'bodytext' + 'key' => 'bodytext', + 'type' => 'richtext', + 'inlineParent' => [ + 'element1' => 'tx_mask_my_palette', + ] ] ], 'palettes' => [ @@ -1289,8 +1302,81 @@ public function setElementsTcaDataProvider(): array 'description' => '', 'showitem' => 'header,--linebreak--,bodytext' ] - ] - ] + ], + true, + ], + 'richtext not added for bodytext, if it is of type text' => [ + [ + 'tt_content' => [ + 'elements' => [ + 'element1' => [ + 'key' => 'element1', + 'label' => 'Element1', + 'shortLabel' => 'Ele 1', + 'columns' => [ + 'header', + 'bodytext' + ], + 'labels' => [ + '', + '' + ] + ] + ], + 'tca' => [ + 'header' => [ + 'key' => 'header' + ], + 'bodytext' => [ + 'key' => 'bodytext', + 'bodytextTypeByElement' => [ + 'element1' => 'text', + ], + ] + ] + ] + ], + 'mask_element1', + '--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,header,bodytext,--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,--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,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', + [], + false, + ], + 'richtext added for bodytext, if it is of type richtext' => [ + [ + 'tt_content' => [ + 'elements' => [ + 'element1' => [ + 'key' => 'element1', + 'label' => 'Element1', + 'shortLabel' => 'Ele 1', + 'columns' => [ + 'header', + 'bodytext' + ], + 'labels' => [ + '', + '' + ] + ] + ], + 'tca' => [ + 'header' => [ + 'key' => 'header' + ], + 'bodytext' => [ + 'key' => 'bodytext', + 'bodytextTypeByElement' => [ + 'element1' => 'richtext', + ], + ] + ] + ] + ], + 'mask_element1', + '--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,header,bodytext,--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,--div--;LLL:EXT:core/Resources/Private/Language/locallang_tca.xlf:sys_category.tabs.category,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', + [], + true, + ], ]; } @@ -1298,7 +1384,7 @@ public function setElementsTcaDataProvider(): array * @dataProvider setElementsTcaDataProvider * @test */ - public function setElementsTca(array $json, string $key, string $showItemExpected, array $paletteExpected): void + public function setElementsTca(array $json, string $key, string $showItemExpected, array $paletteExpected, bool $bodytextIsRichtext): void { $GLOBALS['TCA']['tt_content']['columns']['CType']['config']['items'] = []; $GLOBALS['TCA']['tt_content']['columns']['header']['config']['type'] = 'input'; @@ -1312,6 +1398,7 @@ public function setElementsTca(array $json, string $key, string $showItemExpecte self::assertSame($showItemExpected, $GLOBALS['TCA']['tt_content']['types'][$key]['showitem'] ?? ''); self::assertSame($paletteExpected, $GLOBALS['TCA']['tt_content']['palettes'] ?? []); + self::assertSame($bodytextIsRichtext, ($GLOBALS['TCA']['tt_content']['types'][$key]['columnsOverrides']['bodytext']['config']['enableRichtext'] ?? 0) === 1); } public function generateTableTcaDataProvider(): array diff --git a/Tests/Unit/Definition/TableDefinitionCollectionTest.php b/Tests/Unit/Definition/TableDefinitionCollectionTest.php index eedb6119..bb73d511 100644 --- a/Tests/Unit/Definition/TableDefinitionCollectionTest.php +++ b/Tests/Unit/Definition/TableDefinitionCollectionTest.php @@ -1323,13 +1323,6 @@ public function getFormTypeDataProvider(): array 'tt_content', FieldType::DATE ], - 'Core field bodytext returned as richtext' => [ - [], - [], - 'bodytext', - 'tt_content', - FieldType::RICHTEXT - ], 'Colorpicker resolved' => [ [], [ diff --git a/Tests/Unit/Definition/TcaFieldDefinitionTest.php b/Tests/Unit/Definition/TcaFieldDefinitionTest.php index f13400e1..dfc5b5ee 100644 --- a/Tests/Unit/Definition/TcaFieldDefinitionTest.php +++ b/Tests/Unit/Definition/TcaFieldDefinitionTest.php @@ -328,6 +328,38 @@ public function createFromArrayWorksOnLegacyFormatDataProvider(): iterable 'fullKey' => 'tx_mask_select', ], ]; + + yield 'The core field bodytext without any type defined interpreted as richtext' => [ + 'json' => [ + 'key' => 'bodytext', + ], + 'expected' => [ + 'key' => 'bodytext', + 'fullKey' => 'bodytext', + 'coreField' => 1, + 'type' => 'richtext', + ] + ]; + + yield 'The core field bodytext type can be set by bodytextTypeByElement per element' => [ + 'json' => [ + 'key' => 'bodytext', + 'type' => 'richtext', + 'bodytextTypeByElement' => [ + 'element1' => 'text', + 'element2' => 'richtext', + ], + ], + 'expected' => [ + 'key' => 'bodytext', + 'fullKey' => 'bodytext', + 'coreField' => 1, + 'bodytextTypeByElement' => [ + 'element1' => 'text', + 'element2' => 'richtext', + ], + ] + ]; } /** diff --git a/Tests/UnitDeprecated/Domain/Repository/StorageRepositoryTest.php b/Tests/UnitDeprecated/Domain/Repository/StorageRepositoryTest.php index b5525f73..059f9020 100644 --- a/Tests/UnitDeprecated/Domain/Repository/StorageRepositoryTest.php +++ b/Tests/UnitDeprecated/Domain/Repository/StorageRepositoryTest.php @@ -1295,13 +1295,6 @@ public function getFormTypeDataProvider(): array 'tt_content', FieldType::DATE ], - 'Core field bodytext returned as richtext' => [ - [], - [], - 'bodytext', - 'tt_content', - FieldType::RICHTEXT - ], ]; }