From 5ba5e92cc7763607718ff18961cbbd2c1e685635 Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 27 Oct 2025 10:26:50 +0530 Subject: [PATCH 1/2] [3547382] Provided an update script to update from the old to the new layout. --- .../civictheme/civictheme.post_update.php | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/web/themes/contrib/civictheme/civictheme.post_update.php b/web/themes/contrib/civictheme/civictheme.post_update.php index b2f29ad39..a45eb65eb 100644 --- a/web/themes/contrib/civictheme/civictheme.post_update.php +++ b/web/themes/contrib/civictheme/civictheme.post_update.php @@ -986,3 +986,72 @@ function civictheme_post_update_remove_civictheme_iframe_field_c_p_attributes(): return (string) new TranslatableMarkup("Removed civictheme_iframe field 'field_c_p_attributes' instance and storage if they existed."); } + +/** + * Migrate deprecated layouts to civictheme_three_columns. + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @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); +} From 76839a69c1d21db611e6a1655c02fd90cfb803ea Mon Sep 17 00:00:00 2001 From: Joshua Fernandes Date: Mon, 27 Oct 2025 10:31:39 +0530 Subject: [PATCH 2/2] [3547382] SuppressWarnings(PHPMD.CyclomaticComplexity) --- web/themes/contrib/civictheme/civictheme.post_update.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/themes/contrib/civictheme/civictheme.post_update.php b/web/themes/contrib/civictheme/civictheme.post_update.php index a45eb65eb..a678617d1 100644 --- a/web/themes/contrib/civictheme/civictheme.post_update.php +++ b/web/themes/contrib/civictheme/civictheme.post_update.php @@ -991,6 +991,7 @@ function civictheme_post_update_remove_civictheme_iframe_field_c_p_attributes(): * 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 {