diff --git a/core/modules/layout_builder/css/layout-builder-content-translation.css b/core/modules/layout_builder/css/layout-builder-content-translation.css new file mode 100644 index 000000000000..9508ee0e3fc8 --- /dev/null +++ b/core/modules/layout_builder/css/layout-builder-content-translation.css @@ -0,0 +1,4 @@ +.layout-builder-translation-warning { + background: left 2px url(../../../misc/icons/e29700/warning.svg) no-repeat; + padding-left: 20px; +} diff --git a/core/modules/layout_builder/layout_builder.libraries.yml b/core/modules/layout_builder/layout_builder.libraries.yml index d77b6213685a..57b65605ca11 100644 --- a/core/modules/layout_builder/layout_builder.libraries.yml +++ b/core/modules/layout_builder/layout_builder.libraries.yml @@ -27,3 +27,9 @@ fourcol_section: css: theme: layouts/fourcol_section/fourcol_section.css: {} + +drupal.layout_builder_content_translation_admin: + version: VERSION + css: + theme: + css/layout-builder-content-translation.css: {} diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index d369096505e8..a60e74bdaadd 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -15,6 +15,7 @@ use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; use Drupal\field\FieldConfigInterface; +use Drupal\field\FieldStorageConfigInterface; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay; use Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage; use Drupal\layout_builder\Form\DefaultsEntityForm; @@ -367,3 +368,72 @@ function layout_builder_entity_translation_create(EntityInterface $translation) $translation->set(OverridesSectionStorage::FIELD_NAME, []); } } + +/** + * Implements hook_form_FORM_ID_alter(). + * + * @see layout_builder_module_implements_alter() + */ +function layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { + if (isset($form['settings'])) { + $form['settings']['#process'][] = '_layout_builder_process_language_content_settings_form'; + } +} + +function _layout_builder_process_language_content_settings_form(&$element, &$form_state, &$form) { + // Add a new wrapper around the element. + foreach (Element::children($element) as $entity_type_id) { + foreach (Element::children($element[$entity_type_id]) as $bundle) { + if (!empty($element[$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME])) { + $layout_field_checkbox = &$element[$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME]; + $layout_field_checkbox['#original_label'] = $layout_field_checkbox['#label']; + // Change #label to a placeholder value that we can find later in + // layout_builder_preprocess_language_content_settings_table(). + // We will replace the title with #original_label in that function. + $layout_field_checkbox['#label'] = "__LAYOUT_BUILDER_LABEL_PLACE_HOLDER:$entity_type_id:$bundle"; + $layout_field_checkbox['#attached']['library'][] = 'layout_builder/drupal.layout_builder_content_translation_admin'; + } + } + } + return $element; +} + +/** + * Implements hook_theme_registry_alter(). + */ +function layout_builder_theme_registry_alter(&$theme_registry) { + if (!empty($theme_registry['language_content_settings_table']['preprocess functions'])) { + $preprocess_functions = &$theme_registry['language_content_settings_table']['preprocess functions']; + $key = array_search('layout_builder_preprocess_language_content_settings_table', $preprocess_functions); + if ($key !== FALSE) { + unset($preprocess_functions[$key]); + $preprocess_functions[] = 'layout_builder_preprocess_language_content_settings_table'; + } + } +} + +/** + * Implements hook_preprocess_HOOK() for language-content-settings-table.html.twig. + */ +function layout_builder_preprocess_language_content_settings_table(&$variables) { + foreach ($variables['build']['#rows'] as &$row) { + if (isset($row['data'][1]['data']['field']['#plain_text']) && strpos($row['data'][1]['data']['field']['#plain_text'], '__LAYOUT_BUILDER_LABEL_PLACE_HOLDER:') === 0) { + list(, $entity_type_id, $bundle) = explode(':', $row['data'][1]['data']['field']['#plain_text']); + $checkbox = $variables["element"][$bundle]["fields"][OverridesSectionStorage::FIELD_NAME]; + + $field_element = &$row['data'][1]['data']['field']; + $field_element = [ + 'label' => [ + '#plain_text' => $checkbox['#original_label'], + ], + 'description' => [ + '#type' => 'container', + '#markup' => t('Warning: Layout Builder does not support translating layouts. (online documentation.'), + '#attributes' => [ + 'class' => ['layout-builder-translation-warning'], + ], + ], + ]; + } + } +}