From 10a62ac8d7a1218c740f975843865500474221eb Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 16:06:58 -0400 Subject: [PATCH 01/15] Patch https://www.drupal.org/files/issues/2019-03-27/3043646-11.patch --- .../layout_builder/layout_builder.module | 107 +++++++++++++++++- 1 file changed, 103 insertions(+), 4 deletions(-) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index d369096505e8..641829041526 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; @@ -186,14 +187,30 @@ function layout_builder_entity_build_defaults_alter(array &$build, EntityInterfa * Implements hook_builder_module_implements_alter(). */ function layout_builder_module_implements_alter(&$implementations, $hook) { - if ($hook === 'entity_view_alter') { + switch ($hook) { // Ensure that this module's implementation of hook_entity_view_alter() runs // last so that other modules that use this hook to render extra fields will // run before it. - $group = $implementations['layout_builder']; - unset($implementations['layout_builder']); - $implementations['layout_builder'] = $group; + case 'entity_view_alter': + $group = $implementations['layout_builder']; + unset($implementations['layout_builder']); + $implementations['layout_builder'] = $group; + break; + + // The form_alter hook in the content_translation module needs to run + // before Layout Builder's so field information is available in the form. + // + // The hook here can't be more specific, as the $hook that's passed in to + // this function is form_alter, and not form_FORM_ID_alter. + case 'form_alter': + if (isset($implementations['content_translation'])) { + $group = $implementations['layout_builder']; + unset($implementations['layout_builder']); + $implementations['layout_builder'] = $group; + } + break; } + } /** @@ -367,3 +384,85 @@ function layout_builder_entity_translation_create(EntityInterface $translation) $translation->set(OverridesSectionStorage::FIELD_NAME, []); } } + +/** + * Implements hook_form_alter(). + * + * Used instead of hook_form_FORM_ID_alter() so this can happen after + * content_translation_form_alter(). + * + * @see layout_builder_module_implements_alter() + */ +function layout_builder_form_alter(&$form, FormStateInterface $form_state, $form_id) { + if ($form_id === 'language_content_settings_form') { + _layout_builder_form_language_content_settings_form_alter($form, $form_state, $form_id); + } +} + +/** + * This acts as if it implements hook_form_FORM_ID_alter(). + * + * In most cases, Layout fields are not included in the content translation + * settings form. This is good because they are not translatable. However, + * they may appear on some sites that began using Layout Builder in Drupal 8.6. + * For those cases, the form is altered to add warning messages to alert the + * user that content translation is not supported on these fields. + * + * @see layout_builder_form_alter() + */ +function _layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { + if (!\Drupal::hasService('content_translation.manager')) { + return; + } + + $content_translation_manager = \Drupal::service('content_translation.manager'); + $message_display = 'warning'; + $message_text = t('(* unsupported) The Layout field does not support translation.'); + $map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('layout_section'); + foreach ($map as $entity_type_id => $info) { + if (!$content_translation_manager->isEnabled($entity_type_id)) { + continue; + } + $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id); + + /* @var \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition */ + foreach ($field_storage_definitions as $name => $storage_definition) { + if ($storage_definition->getType() == 'layout_section') { + + // For configurable fields, check all bundles on which the field exists, + // for base fields that are translatable, check all bundles, + // untranslatable base fields do not show up at all. + $bundles = []; + if ($storage_definition instanceof FieldStorageConfigInterface) { + $bundles = $storage_definition->getBundles(); + } + elseif ($storage_definition->isTranslatable()) { + $bundles = Element::children($form['settings'][$entity_type_id]); + } + foreach ($bundles as $bundle) { + if (!$content_translation_manager->isEnabled($entity_type_id, $bundle)) { + continue; + } + + // Add warning to label. If translations are enabled on the field, + // the message should display as an error instead of just a warning. + if (isset($form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'])) { + $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'] = t('@field_label (* unsupported)', ['@field_label' => $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']]); + } + if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][$name]['#default_value'])) { + $message_display = 'error'; + } + } + } + } + } + + $form['settings']['lb_message'] = [ + '#type' => 'container', + '#markup' => $message_text, + '#attributes' => [ + 'class' => ['messages messages--' . $message_display], + ], + '#weight' => 0, + ]; +} From 1f9c7e935b996a3ef1b31e3581a490a192f38ec8 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 16:12:51 -0400 Subject: [PATCH 02/15] Remove top message --- core/modules/layout_builder/layout_builder.module | 9 --------- 1 file changed, 9 deletions(-) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 641829041526..87942f55ff4c 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -456,13 +456,4 @@ function _layout_builder_form_language_content_settings_form_alter(&$form, FormS } } } - - $form['settings']['lb_message'] = [ - '#type' => 'container', - '#markup' => $message_text, - '#attributes' => [ - 'class' => ['messages messages--' . $message_display], - ], - '#weight' => 0, - ]; } From 2cd33c6c00ae82fcad8acbd2a5cc1418fa6a7c64 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 18:01:36 -0400 Subject: [PATCH 03/15] wip --- core/modules/layout_builder/layout_builder.module | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 87942f55ff4c..04f1e91efd89 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -447,6 +447,7 @@ function _layout_builder_form_language_content_settings_form_alter(&$form, FormS // Add warning to label. If translations are enabled on the field, // the message should display as an error instead of just a warning. if (isset($form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'])) { + $label = $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']; $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'] = t('@field_label (* unsupported)', ['@field_label' => $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']]); } if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][$name]['#default_value'])) { @@ -457,3 +458,5 @@ function _layout_builder_form_language_content_settings_form_alter(&$form, FormS } } } + +function From 325ff866a62fc14c469044116a40e04a50ecdd7e Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 19:24:24 -0400 Subject: [PATCH 04/15] so ugly --- .../content_translation.admin.inc | 3 ++ .../layout_builder/layout_builder.module | 41 ++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index a7bfc1d244dd..20a62c89e8e7 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -255,6 +255,8 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'class' => ['operations'], ], ], + '#field_name' => $field_name, + '#bundle' => $bundle, 'class' => ['field-settings'], ]; @@ -295,6 +297,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia ], ], 'class' => ['column-settings'], + '#_field_name' => $field_name, ]; } } diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 04f1e91efd89..8040de2ad168 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -459,4 +459,43 @@ function _layout_builder_form_language_content_settings_form_alter(&$form, FormS } } -function +/** + * 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) { + $a = 'b'; + foreach ($variables["build"]["#rows"] as &$row) { + if (isset($row['#field_name']) && $row['#field_name'] === OverridesSectionStorage::FIELD_NAME) { + if (isset($row['data'][1]['data']['field']['#plain_text'])) { + $field = &$row['data'][1]['data']['field']; + $field['label'] = ['#plain_text' => $field['#plain_text']]; + $field[] = [ + '#type' => 'container', + '#markup' => t('Warning: The Layout Builder does not support translating layouts.'), + // @todo our render for link images etc would have to go here. + // _content_translation_preprocess_language_content_settings_table + // make any solution using this preprocess a very bad solution + // it also so makes it so _layout_builder_form_language_content_settings_form_alter + // won't work either. ☹️ + // And if even this solution needs a change to _content_translation_preprocess_language_content_settings_table + ]; + unset($field['#plain_text']); + } + } + } +} + From 3cb39966d811d999eb217f346ec39645f560bc68 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 19:25:49 -0400 Subject: [PATCH 05/15] so ugly --- core/modules/content_translation/content_translation.admin.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 20a62c89e8e7..35744106284b 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -256,7 +256,6 @@ function _content_translation_preprocess_language_content_settings_table(&$varia ], ], '#field_name' => $field_name, - '#bundle' => $bundle, 'class' => ['field-settings'], ]; From b161e343f6c04c056cb7b7adf43aee073ae55a91 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 20:39:52 -0400 Subject: [PATCH 06/15] wip --- .../layout_builder/layout_builder.module | 76 ++++--------------- 1 file changed, 16 insertions(+), 60 deletions(-) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 8040de2ad168..4985d7d2e81a 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -187,6 +187,9 @@ function layout_builder_entity_build_defaults_alter(array &$build, EntityInterfa * Implements hook_builder_module_implements_alter(). */ function layout_builder_module_implements_alter(&$implementations, $hook) { + if (!isset($implementations['layout_builder'])) { + return; + } switch ($hook) { // Ensure that this module's implementation of hook_entity_view_alter() runs // last so that other modules that use this hook to render extra fields will @@ -386,31 +389,11 @@ function layout_builder_entity_translation_create(EntityInterface $translation) } /** - * Implements hook_form_alter(). - * - * Used instead of hook_form_FORM_ID_alter() so this can happen after - * content_translation_form_alter(). + * Implements hook_form_FORM_ID_alter(). * * @see layout_builder_module_implements_alter() */ -function layout_builder_form_alter(&$form, FormStateInterface $form_state, $form_id) { - if ($form_id === 'language_content_settings_form') { - _layout_builder_form_language_content_settings_form_alter($form, $form_state, $form_id); - } -} - -/** - * This acts as if it implements hook_form_FORM_ID_alter(). - * - * In most cases, Layout fields are not included in the content translation - * settings form. This is good because they are not translatable. However, - * they may appear on some sites that began using Layout Builder in Drupal 8.6. - * For those cases, the form is altered to add warning messages to alert the - * user that content translation is not supported on these fields. - * - * @see layout_builder_form_alter() - */ -function _layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { +function layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { if (!\Drupal::hasService('content_translation.manager')) { return; } @@ -450,9 +433,6 @@ function _layout_builder_form_language_content_settings_form_alter(&$form, FormS $label = $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']; $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'] = t('@field_label (* unsupported)', ['@field_label' => $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']]); } - if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][$name]['#default_value'])) { - $message_display = 'error'; - } } } } @@ -460,42 +440,18 @@ function _layout_builder_form_language_content_settings_form_alter(&$form, FormS } /** - * Implements hook_theme_registry_alter(). + * This acts as if it implements hook_form_FORM_ID_alter(). + * + * In most cases, Layout fields are not included in the content translation + * settings form. This is good because they are not translatable. However, + * they may appear on some sites that began using Layout Builder in Drupal 8.6. + * For those cases, the form is altered to add warning messages to alert the + * user that content translation is not supported on these fields. + * + * @see layout_builder_form_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'; - } - } -} +function _layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { -/** - * Implements hook_preprocess_HOOK() for language-content-settings-table.html.twig. - */ -function layout_builder_preprocess_language_content_settings_table(&$variables) { - $a = 'b'; - foreach ($variables["build"]["#rows"] as &$row) { - if (isset($row['#field_name']) && $row['#field_name'] === OverridesSectionStorage::FIELD_NAME) { - if (isset($row['data'][1]['data']['field']['#plain_text'])) { - $field = &$row['data'][1]['data']['field']; - $field['label'] = ['#plain_text' => $field['#plain_text']]; - $field[] = [ - '#type' => 'container', - '#markup' => t('Warning: The Layout Builder does not support translating layouts.'), - // @todo our render for link images etc would have to go here. - // _content_translation_preprocess_language_content_settings_table - // make any solution using this preprocess a very bad solution - // it also so makes it so _layout_builder_form_language_content_settings_form_alter - // won't work either. ☹️ - // And if even this solution needs a change to _content_translation_preprocess_language_content_settings_table - ]; - unset($field['#plain_text']); - } - } - } } + From 5888eeae17e5406accc7220ceda2e0759e345ccd Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 20:54:42 -0400 Subject: [PATCH 07/15] sucks --- .../layout_builder/layout_builder.module | 61 +++---------------- 1 file changed, 7 insertions(+), 54 deletions(-) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 4985d7d2e81a..1c114d1bd69d 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -394,64 +394,17 @@ function layout_builder_entity_translation_create(EntityInterface $translation) * @see layout_builder_module_implements_alter() */ function layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { - if (!\Drupal::hasService('content_translation.manager')) { + if (!isset($form['settings'])) { return; } - - $content_translation_manager = \Drupal::service('content_translation.manager'); - $message_display = 'warning'; - $message_text = t('(* unsupported) The Layout field does not support translation.'); - $map = \Drupal::service('entity_field.manager')->getFieldMapByFieldType('layout_section'); - foreach ($map as $entity_type_id => $info) { - if (!$content_translation_manager->isEnabled($entity_type_id)) { - continue; - } - $field_storage_definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id); - - /* @var \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition */ - foreach ($field_storage_definitions as $name => $storage_definition) { - if ($storage_definition->getType() == 'layout_section') { - - // For configurable fields, check all bundles on which the field exists, - // for base fields that are translatable, check all bundles, - // untranslatable base fields do not show up at all. - $bundles = []; - if ($storage_definition instanceof FieldStorageConfigInterface) { - $bundles = $storage_definition->getBundles(); - } - elseif ($storage_definition->isTranslatable()) { - $bundles = Element::children($form['settings'][$entity_type_id]); - } - foreach ($bundles as $bundle) { - if (!$content_translation_manager->isEnabled($entity_type_id, $bundle)) { - continue; - } - - // Add warning to label. If translations are enabled on the field, - // the message should display as an error instead of just a warning. - if (isset($form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'])) { - $label = $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']; - $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label'] = t('@field_label (* unsupported)', ['@field_label' => $form['settings'][$entity_type_id][$bundle]['fields'][$name]['#label']]); - } - } + foreach (Element::children($form['settings']) as $entity_type_id) { + foreach (Element::children($form['settings'][$entity_type_id]) as $bundle) { + if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME])) { + $layout_field_checkbox = &$form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME]; + $layout_field_checkbox['#label'] .= t("(Warning: Layout Builder doesn't translated layouts.)") . '

HTML is escaped!

'; } } - } -} - -/** - * This acts as if it implements hook_form_FORM_ID_alter(). - * - * In most cases, Layout fields are not included in the content translation - * settings form. This is good because they are not translatable. However, - * they may appear on some sites that began using Layout Builder in Drupal 8.6. - * For those cases, the form is altered to add warning messages to alert the - * user that content translation is not supported on these fields. - * - * @see layout_builder_form_alter() - */ -function _layout_builder_form_language_content_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { + } } - From 12ec20d7000bed75b53a2b8e79b446c1c51b65a0 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 21:31:58 -0400 Subject: [PATCH 08/15] move description --- .../content_translation.admin.inc | 13 +++++++++++-- core/modules/layout_builder/layout_builder.module | 3 +-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 35744106284b..ec471e11d3ba 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -229,6 +229,8 @@ function _content_translation_preprocess_language_content_settings_table(&$varia foreach ($field_names as $field_name) { $field_element = &$element[$bundle]['fields'][$field_name]; + $column_description = isset($field_element['#description']) ? $field_element['#description'] : ''; + unset($field_element['#description']); $rows[] = [ 'data' => [ [ @@ -245,7 +247,15 @@ function _content_translation_preprocess_language_content_settings_table(&$varia '#plain_text' => $element[$bundle]['settings']['#label'], ], 'field' => [ - '#plain_text' => $field_element['#label'], + [ + 'label' => [ + '#plain_text' => $field_element['#label'], + 'description' => [ + '#type' => 'container', + '#markup' => $column_description, + ], + ], + ], ], ], 'class' => ['field'], @@ -296,7 +306,6 @@ function _content_translation_preprocess_language_content_settings_table(&$varia ], ], 'class' => ['column-settings'], - '#_field_name' => $field_name, ]; } } diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 1c114d1bd69d..10594cd51ea3 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -401,10 +401,9 @@ function layout_builder_form_language_content_settings_form_alter(&$form, FormSt foreach (Element::children($form['settings'][$entity_type_id]) as $bundle) { if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME])) { $layout_field_checkbox = &$form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME]; - $layout_field_checkbox['#label'] .= t("(Warning: Layout Builder doesn't translated layouts.)") . '

HTML is escaped!

'; + $layout_field_checkbox['#description'] = t('Warning: Layout Builder does not support translating layouts. (online documentation.'); } } - } } From cbf77b790a30685a796f8c72d6e261ae3b255c45 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 21:34:13 -0400 Subject: [PATCH 09/15] nits --- core/modules/content_translation/content_translation.admin.inc | 1 - core/modules/layout_builder/layout_builder.module | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index ec471e11d3ba..f541434be204 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -265,7 +265,6 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'class' => ['operations'], ], ], - '#field_name' => $field_name, 'class' => ['field-settings'], ]; diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 10594cd51ea3..16b0ad207aec 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -401,7 +401,7 @@ function layout_builder_form_language_content_settings_form_alter(&$form, FormSt foreach (Element::children($form['settings'][$entity_type_id]) as $bundle) { if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME])) { $layout_field_checkbox = &$form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME]; - $layout_field_checkbox['#description'] = t('Warning: Layout Builder does not support translating layouts. (online documentation.'); + $layout_field_checkbox['#description'] = t('Warning: Layout Builder does not support translating layouts. (online documentation.'); } } } From 2210e55ea39053abbfeacf07cc51e11b5fc46bc9 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 21:38:14 -0400 Subject: [PATCH 10/15] remove content_translation changes --- .../content_translation.admin.inc | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index f541434be204..a7bfc1d244dd 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -229,8 +229,6 @@ function _content_translation_preprocess_language_content_settings_table(&$varia foreach ($field_names as $field_name) { $field_element = &$element[$bundle]['fields'][$field_name]; - $column_description = isset($field_element['#description']) ? $field_element['#description'] : ''; - unset($field_element['#description']); $rows[] = [ 'data' => [ [ @@ -247,15 +245,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia '#plain_text' => $element[$bundle]['settings']['#label'], ], 'field' => [ - [ - 'label' => [ - '#plain_text' => $field_element['#label'], - 'description' => [ - '#type' => 'container', - '#markup' => $column_description, - ], - ], - ], + '#plain_text' => $field_element['#label'], ], ], 'class' => ['field'], From e59664aecdeabf558e6ab6d41757d3742bb9d260 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 21:52:37 -0400 Subject: [PATCH 11/15] Revert "remove content_translation changes" This reverts commit 2210e55ea39053abbfeacf07cc51e11b5fc46bc9. --- .../content_translation.admin.inc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index a7bfc1d244dd..f541434be204 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -229,6 +229,8 @@ function _content_translation_preprocess_language_content_settings_table(&$varia foreach ($field_names as $field_name) { $field_element = &$element[$bundle]['fields'][$field_name]; + $column_description = isset($field_element['#description']) ? $field_element['#description'] : ''; + unset($field_element['#description']); $rows[] = [ 'data' => [ [ @@ -245,7 +247,15 @@ function _content_translation_preprocess_language_content_settings_table(&$varia '#plain_text' => $element[$bundle]['settings']['#label'], ], 'field' => [ - '#plain_text' => $field_element['#label'], + [ + 'label' => [ + '#plain_text' => $field_element['#label'], + 'description' => [ + '#type' => 'container', + '#markup' => $column_description, + ], + ], + ], ], ], 'class' => ['field'], From 9cd8b8f740998e0fa7c94fb2b717c7337510fe26 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 22:28:40 -0400 Subject: [PATCH 12/15] css --- .../content_translation/content_translation.admin.inc | 5 ++++- .../css/layout-builder-content-translation.css | 6 ++++++ core/modules/layout_builder/layout_builder.libraries.yml | 6 ++++++ core/modules/layout_builder/layout_builder.module | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 core/modules/layout_builder/css/layout-builder-content-translation.css diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index f541434be204..03c74b6af29c 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -253,6 +253,9 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'description' => [ '#type' => 'container', '#markup' => $column_description, + '#attributes' => [ + 'class' => ['description'], + ], ], ], ], @@ -265,7 +268,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'class' => ['operations'], ], ], - 'class' => ['field-settings'], + 'class' => ['field-settings', "field-settings-$field_name"], ]; if (!empty($element[$bundle]['columns'][$field_name])) { 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..3cebe6b3c4b1 --- /dev/null +++ b/core/modules/layout_builder/css/layout-builder-content-translation.css @@ -0,0 +1,6 @@ +.language-content-settings-form .field-settings-layout_builder__layout .description { + background-image: url(../../../misc/icons/e29700/warning.svg); + background-repeat: 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 16b0ad207aec..88f569769ea3 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -402,6 +402,7 @@ function layout_builder_form_language_content_settings_form_alter(&$form, FormSt if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME])) { $layout_field_checkbox = &$form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME]; $layout_field_checkbox['#description'] = t('Warning: Layout Builder does not support translating layouts. (online documentation.'); + $layout_field_checkbox['#attached']['library'][] = 'layout_builder/drupal.layout_builder_content_translation_admin'; } } } From 526064e4c827fdfbbc1d8cb75283ec08bbcdcfb1 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 23:05:33 -0400 Subject: [PATCH 13/15] theme alter back --- .../layout_builder/layout_builder.module | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index 88f569769ea3..ed2c62b7cb7b 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -408,3 +408,41 @@ function layout_builder_form_language_content_settings_form_alter(&$form, FormSt } } +/** + * 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['#field_name']) && $row['#field_name'] === OverridesSectionStorage::FIELD_NAME) { + if (isset($row['data'][1]['data']['field']['#plain_text'])) { + $field = &$row['data'][1]['data']['field']; + $field['label'] = ['#plain_text' => $field['#plain_text']]; + $field[] = [ + '#type' => 'container', + '#markup' => t('Warning: The Layout Builder does not support translating layouts.'), + // @todo our render for link images etc would have to go here. + // _content_translation_preprocess_language_content_settings_table + // make any solution using this preprocess a very bad solution + // it also so makes it so _layout_builder_form_language_content_settings_form_alter + // won't work either. ☹️ + // And if even this solution needs a change to _content_translation_preprocess_language_content_settings_table + ]; + unset($field['#plain_text']); + } + } + } +} From 46d1327b49b140ae92fd34b1ebba953234461026 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Wed, 27 Mar 2019 23:07:25 -0400 Subject: [PATCH 14/15] undo layout_builder_module_implements_alter --- .../layout_builder/layout_builder.module | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/core/modules/layout_builder/layout_builder.module b/core/modules/layout_builder/layout_builder.module index ed2c62b7cb7b..930156218976 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -187,33 +187,14 @@ function layout_builder_entity_build_defaults_alter(array &$build, EntityInterfa * Implements hook_builder_module_implements_alter(). */ function layout_builder_module_implements_alter(&$implementations, $hook) { - if (!isset($implementations['layout_builder'])) { - return; - } - switch ($hook) { + if ($hook === 'entity_view_alter') { // Ensure that this module's implementation of hook_entity_view_alter() runs // last so that other modules that use this hook to render extra fields will // run before it. - case 'entity_view_alter': - $group = $implementations['layout_builder']; - unset($implementations['layout_builder']); - $implementations['layout_builder'] = $group; - break; - - // The form_alter hook in the content_translation module needs to run - // before Layout Builder's so field information is available in the form. - // - // The hook here can't be more specific, as the $hook that's passed in to - // this function is form_alter, and not form_FORM_ID_alter. - case 'form_alter': - if (isset($implementations['content_translation'])) { - $group = $implementations['layout_builder']; - unset($implementations['layout_builder']); - $implementations['layout_builder'] = $group; - } - break; + $group = $implementations['layout_builder']; + unset($implementations['layout_builder']); + $implementations['layout_builder'] = $group; } - } /** From f7ffdbdf675ee410bf8c513d1a2d3b6dc61e6074 Mon Sep 17 00:00:00 2001 From: Ted Bowman Date: Thu, 28 Mar 2019 00:12:21 -0400 Subject: [PATCH 15/15] no content_translation change --- .../content_translation.admin.inc | 17 +----- .../layout-builder-content-translation.css | 6 +-- .../layout_builder/layout_builder.module | 54 +++++++++++-------- 3 files changed, 36 insertions(+), 41 deletions(-) diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 03c74b6af29c..a7bfc1d244dd 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -229,8 +229,6 @@ function _content_translation_preprocess_language_content_settings_table(&$varia foreach ($field_names as $field_name) { $field_element = &$element[$bundle]['fields'][$field_name]; - $column_description = isset($field_element['#description']) ? $field_element['#description'] : ''; - unset($field_element['#description']); $rows[] = [ 'data' => [ [ @@ -247,18 +245,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia '#plain_text' => $element[$bundle]['settings']['#label'], ], 'field' => [ - [ - 'label' => [ - '#plain_text' => $field_element['#label'], - 'description' => [ - '#type' => 'container', - '#markup' => $column_description, - '#attributes' => [ - 'class' => ['description'], - ], - ], - ], - ], + '#plain_text' => $field_element['#label'], ], ], 'class' => ['field'], @@ -268,7 +255,7 @@ function _content_translation_preprocess_language_content_settings_table(&$varia 'class' => ['operations'], ], ], - 'class' => ['field-settings', "field-settings-$field_name"], + 'class' => ['field-settings'], ]; if (!empty($element[$bundle]['columns'][$field_name])) { diff --git a/core/modules/layout_builder/css/layout-builder-content-translation.css b/core/modules/layout_builder/css/layout-builder-content-translation.css index 3cebe6b3c4b1..9508ee0e3fc8 100644 --- a/core/modules/layout_builder/css/layout-builder-content-translation.css +++ b/core/modules/layout_builder/css/layout-builder-content-translation.css @@ -1,6 +1,4 @@ -.language-content-settings-form .field-settings-layout_builder__layout .description { - background-image: url(../../../misc/icons/e29700/warning.svg); - background-repeat: no-repeat; +.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.module b/core/modules/layout_builder/layout_builder.module index 930156218976..a60e74bdaadd 100644 --- a/core/modules/layout_builder/layout_builder.module +++ b/core/modules/layout_builder/layout_builder.module @@ -375,18 +375,27 @@ function layout_builder_entity_translation_create(EntityInterface $translation) * @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'])) { - return; + if (isset($form['settings'])) { + $form['settings']['#process'][] = '_layout_builder_process_language_content_settings_form'; } - foreach (Element::children($form['settings']) as $entity_type_id) { - foreach (Element::children($form['settings'][$entity_type_id]) as $bundle) { - if (!empty($form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME])) { - $layout_field_checkbox = &$form['settings'][$entity_type_id][$bundle]['fields'][OverridesSectionStorage::FIELD_NAME]; - $layout_field_checkbox['#description'] = t('Warning: Layout Builder does not support translating layouts. (online documentation.'); +} + +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; } /** @@ -408,22 +417,23 @@ function layout_builder_theme_registry_alter(&$theme_registry) { */ function layout_builder_preprocess_language_content_settings_table(&$variables) { foreach ($variables['build']['#rows'] as &$row) { - if (isset($row['#field_name']) && $row['#field_name'] === OverridesSectionStorage::FIELD_NAME) { - if (isset($row['data'][1]['data']['field']['#plain_text'])) { - $field = &$row['data'][1]['data']['field']; - $field['label'] = ['#plain_text' => $field['#plain_text']]; - $field[] = [ + 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: The Layout Builder does not support translating layouts.'), - // @todo our render for link images etc would have to go here. - // _content_translation_preprocess_language_content_settings_table - // make any solution using this preprocess a very bad solution - // it also so makes it so _layout_builder_form_language_content_settings_form_alter - // won't work either. ☹️ - // And if even this solution needs a change to _content_translation_preprocess_language_content_settings_table - ]; - unset($field['#plain_text']); - } + '#markup' => t('Warning: Layout Builder does not support translating layouts. (online documentation.'), + '#attributes' => [ + 'class' => ['layout-builder-translation-warning'], + ], + ], + ]; } } }