diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php index d923f1ba4f..97852f6e9d 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItemBase.php @@ -32,7 +32,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) { '#type' => 'checkboxes', '#title' => $this->t('Allowed text formats'), '#options' => $this->get('format')->getPossibleOptions(), - '#default_value' => $settings['allowed_formats'], + '#default_value' => !empty($settings['allowed_formats']) ? $settings['allowed_formats'] : [], '#description' => $this->t('Select the allowed text formats. If no formats are selected, all available text formats will be displayed to the user.'), '#element_validate' => [[static::class, 'validateAllowedFormats']], ]; diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php index 1dcb00b96b..4882d632e5 100644 --- a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php +++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php @@ -103,4 +103,18 @@ public function errorElement(array $element, ConstraintViolationInterface $viola return ($element === FALSE) ? FALSE : $element[$violation->arrayPropertyPath[0]]; } + /** + * {@inheritdoc} + */ + public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + $get_settings = isset($form_state->cleanValues()->getValues()['settings']['allowed_formats']) ? $form_state->cleanValues()->getValues()['settings']['allowed_formats'] : ''; + if ($values[0]['value'] !== '' && isset($values[0]['value']) && !empty($get_settings)) { + foreach ($get_settings as $key => $format_type) { + $text = check_markup($values[0]['value'], $format_type)->__toString(); + } + $values[0]['value'] = $text; + } + return $values; + } + }