diff --git a/web/themes/contrib/civictheme/civictheme.layouts.yml b/web/themes/contrib/civictheme/civictheme.layouts.yml index 3578b396f..967d37e50 100644 --- a/web/themes/contrib/civictheme/civictheme.layouts.yml +++ b/web/themes/contrib/civictheme/civictheme.layouts.yml @@ -20,31 +20,3 @@ civictheme_three_columns: label: 'Sidebar Top Right' sidebar_bottom_right: label: 'Sidebar Bottom Right' - -# Deprecated and will be removed in 1.9. Switch to civictheme_three_columns. -civictheme_one_column: - label: 'Deprecated. Single column - edge to edge content.' - library: civictheme/layouts - category: 'CivicTheme Layouts' - path: templates/layout/ - template: layout--single-column - default_region: content - icon_map: - - [ content ] - regions: - content: - label: Main content - -# Deprecated and will be removed in 1.9. Switch to civictheme_three_columns. -civictheme_one_column_contained: - label: 'Deprecated. Single column - contained content' - library: civictheme/layouts - category: 'CivicTheme Layouts' - path: templates/layout/ - template: layout--single-column-contained - default_region: content - icon_map: - - [ content ] - regions: - content: - label: Main content diff --git a/web/themes/contrib/civictheme/civictheme.post_update.php b/web/themes/contrib/civictheme/civictheme.post_update.php index 5cc271b02..db437f1e0 100644 --- a/web/themes/contrib/civictheme/civictheme.post_update.php +++ b/web/themes/contrib/civictheme/civictheme.post_update.php @@ -1093,3 +1093,73 @@ function civictheme_post_update_migrate_one_column_layouts(): string { } return implode("\n", $messages); } + +/** + * Migrate deprecated layouts to civictheme_three_columns. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.StaticAccess) + */ +function civictheme_post_update_migrate_one_column_layouts(): string { + $outdated_layouts = [ + 'civictheme_one_column', + 'civictheme_one_column_contained', + ]; + + $messages = []; + $entity_displays = LayoutBuilderEntityViewDisplay::loadMultiple(); + $updated_entity_displays = []; + foreach ($entity_displays as $entity_display) { + if (!$entity_display->isLayoutBuilderEnabled()) { + continue; + } + // Update allowed layouts if the deprecated ones are present. + $entity_view_mode_restriction = $entity_display->getThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction'); + if (!empty($entity_view_mode_restriction['allowed_layouts'])) { + $allowed_layouts = $entity_view_mode_restriction['allowed_layouts']; + $replaced = FALSE; + foreach ($allowed_layouts as $idx => $layout_name) { + if (in_array($layout_name, $outdated_layouts)) { + unset($allowed_layouts[$idx]); + $replaced = TRUE; + } + } + if ($replaced) { + $allowed_layouts[] = 'civictheme_three_columns'; + $entity_view_mode_restriction['allowed_layouts'] = array_values($allowed_layouts); + $entity_display->setThirdPartySetting('layout_builder_restrictions', 'entity_view_mode_restriction', $entity_view_mode_restriction); + $updated_entity_displays[$entity_display->id()] = $entity_display->id(); + } + } + // Replace layouts in layout builder sections. + $layout_builder_sections = $entity_display->getThirdPartySetting('layout_builder', 'sections'); + if (!empty($layout_builder_sections)) { + foreach ($layout_builder_sections as $index => $section) { + $layout_name = $section->getLayoutId(); + if (in_array($layout_name, $outdated_layouts)) { + $section_as_array = $section->toArray(); + $section_as_array['layout_id'] = 'civictheme_three_columns'; + $section_as_array['layout_settings']['label'] = 'CivicTheme Three Columns'; + $section_as_array['layout_settings']['is_contained'] = ($layout_name === 'civictheme_one_column_contained'); + // Move all components to 'main'. + foreach ($section_as_array['components'] as &$component) { + if ($component['region'] === 'content') { + $component['region'] = 'main'; + } + } + $layout_builder_sections[$index] = Section::fromArray($section_as_array); + $updated_entity_displays[$entity_display->id()] = $entity_display->id(); + } + } + $entity_display->setThirdPartySetting('layout_builder', 'sections', $layout_builder_sections); + } + if (in_array($entity_display->id(), $updated_entity_displays)) { + $entity_display->save(); + $messages[] = (string) (new TranslatableMarkup('Updated @display_id display, replaced deprecated CivicTheme single-column layouts with civictheme_three_columns.', [ + '@display_id' => $entity_display->id(), + ])); + } + } + return implode("\n", $messages); +} diff --git a/web/themes/contrib/civictheme/templates/layout/layout--single-column-contained.html.twig b/web/themes/contrib/civictheme/templates/layout/layout--single-column-contained.html.twig deleted file mode 100644 index 9fd3cc634..000000000 --- a/web/themes/contrib/civictheme/templates/layout/layout--single-column-contained.html.twig +++ /dev/null @@ -1,25 +0,0 @@ -{# -/** - * @file - * CivicTheme implementation to display a one-column contained layout. - * - * Available variables: - * - content: The content for this layout. - * - modifier_class: CSS modifying class - * - * @deprecated in CivicTheme 1.8.0, will be removed in CivicTheme 1.9.0. Use - * layout--three-columns.html.twig instead. - */ -#} - -{% if content %} -
-
- {% block content_block %} -
- {{ content }} -
- {% endblock %} -
-
-{% endif %} diff --git a/web/themes/contrib/civictheme/templates/layout/layout--single-column.html.twig b/web/themes/contrib/civictheme/templates/layout/layout--single-column.html.twig deleted file mode 100644 index ae90fc672..000000000 --- a/web/themes/contrib/civictheme/templates/layout/layout--single-column.html.twig +++ /dev/null @@ -1,25 +0,0 @@ -{# -/** - * @file - * CivicTheme implementation to display a one-column edge to edge layout. - * - * Available variables: - * - content: The content for this layout. - * - modifier_class: CSS modifying class - * - * @deprecated in CivicTheme 1.8.0, will be removed in CivicTheme 1.9.0. Use - * layout--three-columns.html.twig instead. - */ -#} - -{% if content %} -
-
- {% block content_block %} -
- {{ content }} -
- {% endblock %} -
-
-{% endif %}