Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions web/themes/contrib/civictheme/civictheme.layouts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
70 changes: 70 additions & 0 deletions web/themes/contrib/civictheme/civictheme.post_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Comment on lines +1097 to +1165
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Remove duplicate function declaration.

This function civictheme_post_update_migrate_one_column_layouts() is already declared at lines 1034-1095. PHP does not allow function redeclaration and will throw a fatal error: "Cannot redeclare function". This prevents the entire file from loading.

🔎 Remove the duplicate function declaration

Delete lines 1097-1165 entirely, as the function is already defined earlier in the file.

-
-/**
- * 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);
-}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* 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);
}
🤖 Prompt for AI Agents
In web/themes/contrib/civictheme/civictheme.post_update.php around lines 1097 to
1165 there is a duplicate declaration of
civictheme_post_update_migrate_one_column_layouts() (the same function exists at
lines ~1034-1095) which will cause a PHP fatal "Cannot redeclare" error; remove
the entire duplicate block (lines 1097-1165) so only the original function
definition remains, then run PHP linting to confirm no remaining
duplicate/syntax issues.

This file was deleted.

This file was deleted.