diff --git a/core/modules/config_translation/src/FormElement/TextFormat.php b/core/modules/config_translation/src/FormElement/TextFormat.php index f9f6bc61bc..e349b281ee 100644 --- a/core/modules/config_translation/src/FormElement/TextFormat.php +++ b/core/modules/config_translation/src/FormElement/TextFormat.php @@ -2,6 +2,7 @@ namespace Drupal\config_translation\FormElement; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Language\LanguageInterface; /** @@ -27,14 +28,15 @@ public function getSourceElement(LanguageInterface $source_language, $source_con * {@inheritdoc} */ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) { - return [ + return NestedArray::mergeDeep(parent::getTranslationElement($translation_language, $source_config, $translation_config), [ '#type' => 'text_format', // Override the #default_value property from the parent class. '#default_value' => $translation_config['value'], '#format' => $translation_config['format'], // @see \Drupal\config_translation\Element\FormElementBase::getTranslationElement() '#allowed_formats' => [$source_config['format']], - ] + parent::getTranslationElement($translation_language, $source_config, $translation_config); + '#attributes' => ['class' => ['js-text-full', 'text-full']], + ]); } } diff --git a/core/modules/config_translation/src/FormElement/Textarea.php b/core/modules/config_translation/src/FormElement/Textarea.php index 4308969e2d..4caaf0e005 100644 --- a/core/modules/config_translation/src/FormElement/Textarea.php +++ b/core/modules/config_translation/src/FormElement/Textarea.php @@ -2,6 +2,7 @@ namespace Drupal\config_translation\FormElement; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Language\LanguageInterface; /** @@ -18,10 +19,11 @@ public function getTranslationElement(LanguageInterface $translation_language, $ $rows_newlines = substr_count($translation_config, "\n") + 1; $rows = max($rows_words, $rows_newlines); - return [ + return NestedArray::mergeDeep(parent::getTranslationElement($translation_language, $source_config, $translation_config), [ '#type' => 'textarea', '#rows' => $rows, - ] + parent::getTranslationElement($translation_language, $source_config, $translation_config); + '#attributes' => ['class' => ['js-text-full', 'text-full']], + ]); } } diff --git a/core/modules/config_translation/src/FormElement/Textfield.php b/core/modules/config_translation/src/FormElement/Textfield.php index cff1037183..f9a7e2129b 100644 --- a/core/modules/config_translation/src/FormElement/Textfield.php +++ b/core/modules/config_translation/src/FormElement/Textfield.php @@ -2,6 +2,7 @@ namespace Drupal\config_translation\FormElement; +use Drupal\Component\Utility\NestedArray; use Drupal\Core\Language\LanguageInterface; /** @@ -13,9 +14,10 @@ class Textfield extends FormElementBase { * {@inheritdoc} */ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) { - return [ + return NestedArray::mergeDeep(parent::getTranslationElement($translation_language, $source_config, $translation_config), [ '#type' => 'textfield', - ] + parent::getTranslationElement($translation_language, $source_config, $translation_config); + '#attributes' => ['class' => ['js-text-full', 'text-full']], + ]); } } diff --git a/core/modules/text/config/schema/text.data_types.schema.yml b/core/modules/text/config/schema/text.data_types.schema.yml new file mode 100644 index 0000000000..0026fe74c4 --- /dev/null +++ b/core/modules/text/config/schema/text.data_types.schema.yml @@ -0,0 +1,19 @@ +# See the 'text_format' type in core.data_types.schema.yml. +text_format_with_summary: + label: 'Default' + type: mapping + translatable: true + # Integrate with the Configuration Translation module. + form_element_class: 'Drupal\text\FormElement\TextFormatWithSummary' + mapping: + value: + type: text + label: 'Body' + translatable: true + summary: + type: string + label: 'Summary' + translatable: true + format: + type: string + label: 'Text format' diff --git a/core/modules/text/config/schema/text.schema.yml b/core/modules/text/config/schema/text.schema.yml index dfc92cd2ba..4e1f1db797 100644 --- a/core/modules/text/config/schema/text.schema.yml +++ b/core/modules/text/config/schema/text.schema.yml @@ -21,15 +21,8 @@ field.field_settings.text: label: 'Text (formatted) settings' field.value.text: - type: mapping + type: text_format label: 'Default value' - mapping: - value: - type: label - label: 'Value' - format: - type: string - label: 'Text format' field.storage_settings.text_long: label: 'Text (formatted, long) settings' @@ -40,15 +33,8 @@ field.field_settings.text_long: type: mapping field.value.text_long: - type: mapping + type: text_format label: 'Default value' - mapping: - value: - type: text - label: 'Value' - format: - type: string - label: 'Text format' field.storage_settings.text_with_summary: label: 'Text (formatted, long, with summary) settings' @@ -63,18 +49,8 @@ field.field_settings.text_with_summary: label: 'Summary input' field.value.text_with_summary: - type: mapping + type: text_format_with_summary label: 'Default value' - mapping: - value: - type: text - label: 'Body' - summary: - type: string - label: 'Summary' - format: - type: string - label: 'Text format' field.formatter.settings.text_default: type: mapping diff --git a/core/modules/text/src/FormElement/TextFormatWithSummary.php b/core/modules/text/src/FormElement/TextFormatWithSummary.php new file mode 100644 index 0000000000..fc9a6f443f --- /dev/null +++ b/core/modules/text/src/FormElement/TextFormatWithSummary.php @@ -0,0 +1,41 @@ + 'textarea', + '#default_value' => $translation_config['summary'], + '#title' => t('Summary'), + '#description' => t('Leave blank to use trimmed value of full text as the summary.'), + '#attached' => [ + 'library' => ['text/drupal.text'], + ], + '#attributes' => ['class' => ['js-text-summary', 'text-summary']], + '#prefix' => '
', + '#suffix' => '
', + '#weight' => -10, + ]; + + return $element; + } + +}