[ 'renderType' => 'localizationStateSelector', ], 'otherLanguageContent' => [ 'renderType' => 'otherLanguageContent', 'after' => [ 'localizationStateSelector', ], ], 'defaultLanguageDifferences' => [ 'renderType' => 'defaultLanguageDifferences', 'after' => [ 'otherLanguageContent', ], ], ]; /** * Render code editor element * * @return array As defined in initializeResultArray() of AbstractNode * @throws InvalidModeException * @throws \InvalidArgumentException * @throws \BadFunctionCallException */ public function render(): array { $this->resultArray = $this->initializeResultArray(); $this->resultArray['javaScriptModules'][] = JavaScriptModuleInstruction::create('@typo3/backend/code-editor/element/code-mirror-element.js'); // Compile and register code editor configuration GeneralUtility::makeInstance(CodeEditor::class)->registerConfiguration(); $addonRegistry = GeneralUtility::makeInstance(AddonRegistry::class); $registeredAddons = $addonRegistry->getAddons(); foreach ($registeredAddons as $addon) { foreach ($addon->getCssFiles() as $cssFile) { $this->resultArray['stylesheetFiles'][] = $cssFile; } } $parameterArray = $this->data['parameterArray']; $attributes = [ 'wrap' => 'off', 'data-formengine-validation-rules' => $this->getValidationDataAsJsonString($parameterArray['fieldConf']['config']), ]; if (isset($parameterArray['fieldConf']['config']['rows']) && MathUtility::canBeInterpretedAsInteger($parameterArray['fieldConf']['config']['rows'])) { $attributes['rows'] = $parameterArray['fieldConf']['config']['rows']; } $settings = []; if ($parameterArray['fieldConf']['config']['readOnly'] ?? false) { $settings['readonly'] = true; } if ($parameterArray['fieldConf']['config']['appearance']['lineWrapping'] ?? false) { $settings['linewrapping'] = true; } $editorHtml = $this->getHTMLCodeForEditor( $parameterArray['itemFormElName'], 'form-control font-monospace enable-tab', $parameterArray['itemFormElValue'], $attributes, $settings, [ 'target' => 0, 'effectivePid' => $this->data['effectivePid'] ?? 0, ] ); $fieldInformationResult = $this->renderFieldInformation(); $fieldInformationHtml = $fieldInformationResult['html']; $this->resultArray = $this->mergeChildReturnIntoExistingResult($this->resultArray, $fieldInformationResult, false); $fieldControlResult = $this->renderFieldControl(); $fieldControlHtml = $fieldControlResult['html']; $this->resultArray = $this->mergeChildReturnIntoExistingResult($this->resultArray, $fieldControlResult, false); $fieldWizardResult = $this->renderFieldWizard(); $fieldWizardHtml = $fieldWizardResult['html']; $this->resultArray = $this->mergeChildReturnIntoExistingResult($this->resultArray, $fieldWizardResult, false); $html = []; $html[] = '
'; $html[] = $fieldInformationHtml; $html[] = '
'; $html[] = '
'; $html[] = '
'; $html[] = $editorHtml; $html[] = '
'; if (!empty($fieldControlHtml)) { $html[] = '
'; $html[] = '
'; $html[] = $fieldControlHtml; $html[] = '
'; $html[] = '
'; } if (!empty($fieldWizardHtml)) { $html[] = '
'; $html[] = $fieldWizardHtml; $html[] = '
'; } $html[] = '
'; $html[] = '
'; $html[] = '
'; $this->resultArray['html'] = $this->wrapWithFieldsetAndLegend(implode(LF, $html)); return $this->resultArray; } /** * Generates HTML with code editor * * @param string $name Name attribute of HTML tag * @param string $class Class attribute of HTML tag * @param string $content Content of the editor * @param array $attributes Any additional editor parameters * * @return string Generated HTML code for editor * @throws \TYPO3\CMS\Backend\CodeEditor\Exception\InvalidModeException */ protected function getHTMLCodeForEditor( string $name, string $class = '', string $content = '', array $attributes = [], array $settings = [], array $hiddenfields = [] ): string { $code = []; $mode = $this->getMode(); $addonRegistry = GeneralUtility::makeInstance(AddonRegistry::class); $registeredAddons = $addonRegistry->getAddons(); $attributes['class'] = $class; $attributes['id'] = 't3editor_' . md5($name); $attributes['name'] = $name; $settings = array_merge($addonRegistry->compileSettings($registeredAddons), $settings); $addons = []; $keymaps = []; foreach ($registeredAddons as $addon) { $module = $addon->getModule(); $keymap = $addon->getKeymap(); if ($module) { $addons[] = $module; } if ($keymap) { $keymaps[] = $keymap; } } $codeMirrorConfig = array_merge($settings, [ 'name' => $name, 'mode' => GeneralUtility::jsonEncodeForHtmlAttribute($mode->getModule(), false), 'addons' => GeneralUtility::jsonEncodeForHtmlAttribute($addons, false), 'keymaps' => GeneralUtility::jsonEncodeForHtmlAttribute($keymaps, false), ]); $code[] = ''; $code[] = GeneralUtility::renderTextarea($content, $attributes); if (!empty($hiddenfields)) { foreach ($hiddenfields as $attributeName => $value) { $code[] = ''; } } $code[] = ''; return implode(LF, $code); } /** * @throws InvalidModeException */ protected function getMode(): Mode { $config = $this->data['parameterArray']['fieldConf']['config']; $registry = GeneralUtility::makeInstance(ModeRegistry::class); if (!isset($config['format'])) { return $registry->getDefaultMode(); } $identifier = $config['format']; if (str_contains($config['format'], '/')) { $parts = explode('/', $config['format']); $identifier = end($parts); } return $registry->getByFormatCode($identifier); } }