enrichDefinitionWithRichTextOptions($definition); } } return $formEditorDefinitions; } /** * Enrich a single definition with RTE options for its editors and property collections. */ protected function enrichDefinitionWithRichTextOptions(array &$definition): void { if (is_array($definition['editors'] ?? null)) { $this->enrichEditorsWithRichTextOptions($definition['editors']); } if (is_array($definition['propertyCollections'] ?? null)) { $this->enrichPropertyCollectionsWithRichTextOptions($definition['propertyCollections']); } } /** * Enrich property collections (e.g., finishers, validators) with RTE options. * * Property collections have an additional numeric level in their structure: * propertyCollections -> collectionName (e.g., 'finishers') -> numeric index -> editors */ protected function enrichPropertyCollectionsWithRichTextOptions(array &$propertyCollections): void { foreach ($propertyCollections as &$collectionItems) { if (!is_array($collectionItems)) { continue; } foreach ($collectionItems as &$collectionItem) { if (is_array($collectionItem['editors'] ?? null)) { $this->enrichEditorsWithRichTextOptions($collectionItem['editors']); } } } } /** * Enrich editors array with RTE options if enableRichtext is set. * * Iterates through all editors and adds RTE configuration options * to textarea editors that have rich text enabled. */ protected function enrichEditorsWithRichTextOptions(array &$editors): void { foreach ($editors as &$editor) { if ($this->shouldEnrichEditorWithRichText($editor)) { $editor['rteOptions'] = $this->resolveRichTextOptions($editor); } } } /** * Check if an editor should be enriched with RTE options. * * An editor qualifies for RTE enrichment if it is a textarea editor * and has the enableRichtext flag set to true. */ protected function shouldEnrichEditorWithRichText(array $editor): bool { return ($editor['templateName'] ?? '') === 'Inspector-TextareaEditor' && ($editor['enableRichtext'] ?? false) === true; } /** * Resolve CKEditor configuration options for the given editor. * * Retrieves the RTE preset configuration and resolves it into * a complete CKEditor configuration that can be used in the form editor. */ protected function resolveRichTextOptions(array $editor): array { $presetName = $editor['richtextConfiguration'] ?? 'form-label'; return $this->richTextConfigurationService->resolveCkEditorConfiguration($presetName); } }