Skip to content

Conversation

@joshua-salsadigital
Copy link
Collaborator

@joshua-salsadigital joshua-salsadigital commented Oct 27, 2025

https://www.drupal.org/project/civictheme/issues/3547382

Checklist before requesting a review

  • I have formatted the subject to include ticket number as Issue #123456 by drupal_org_username: Issue title
  • I have added a link to the issue tracker
  • I have provided information in Changed section about WHY something was done if this was not a normal implementation
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have run new and existing relevant tests locally with my changes, and they passed
  • I have provided screenshots, where applicable

Changed

  1. PART 1 - Provide an update script to update from the old to the new layout
  2. PART 2 - Issue #3547382 by richardgaunt, joshua1234511: Remove deprecated layouts - Contained and edge to Edge [PART 2] #1442

Screenshots

Summary by CodeRabbit

  • Chores
    • Automated system update migrates existing single-column layouts to three-column layout configurations during the upgrade process.

@joshua-salsadigital joshua-salsadigital self-assigned this Oct 27, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 27, 2025

Walkthrough

A new post-update migration routine is added that upgrades deprecated single-column layouts to three-column layouts across all LayoutBuilderEntityViewDisplay configurations. The migration updates allowed layout registrations and revises layout section identifiers and region mappings accordingly.

Changes

Cohort / File(s) Summary
Post-update migration routine
web/themes/contrib/civictheme/civictheme.post_update.php
Introduces civictheme_post_update_migrate_one_column_layouts() function to migrate deprecated single-column layouts to civictheme_three_columns layout. Loads all LayoutBuilderEntityViewDisplay instances, processes layout-builder-enabled displays, removes old layout registrations from allowed_layouts, appends new three-column layout, updates layout section IDs, adjusts section labels, and remaps component regions (content → main). Returns concatenated status messages.

Sequence Diagram(s)

sequenceDiagram
    participant System as System/Drush
    participant PostUpdate as Post-update Hook
    participant Storage as Entity Storage
    participant Display as LayoutBuilderEntityViewDisplay
    participant Config as Updated Config

    System->>PostUpdate: Execute post-update
    activate PostUpdate
    
    PostUpdate->>Storage: Load all LayoutBuilderEntityViewDisplay instances
    activate Storage
    Storage-->>PostUpdate: Return all display configs
    deactivate Storage
    
    loop For each display
        PostUpdate->>Display: Check if layout builder enabled
        alt Layout builder enabled
            PostUpdate->>Display: Check for deprecated layouts
            alt Contains deprecated layouts
                PostUpdate->>Display: Remove civictheme_one_column/-contained<br/>from allowed_layouts
                PostUpdate->>Display: Append civictheme_three_columns
                PostUpdate->>Display: Replace layout section IDs
                PostUpdate->>Display: Update component regions<br/>(content → main)
                PostUpdate->>Config: Save updated display
                activate Config
                Config-->>PostUpdate: Confirmed
                deactivate Config
                note over PostUpdate: Log update message
            else No deprecated layouts
                note over PostUpdate: Skip display
            end
        else Layout builder not enabled
            note over PostUpdate: Skip display
        end
    end
    
    PostUpdate-->>System: Return all update messages
    deactivate PostUpdate
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Areas requiring extra attention:

  • Logic for identifying and replacing deprecated layout identifiers across different display configurations
  • Correctness of region mapping transformation (content → main) to ensure no data loss
  • Edge cases where displays may have mixed or partially deprecated layouts
  • Verification that allowed_layouts array manipulation preserves existing valid layout entries

Suggested labels

State: Needs review

Suggested reviewers

  • richardgaunt

Poem

🐰 With columns three, we hop away,

From deprecated layouts of yesterday,

The single-column path now passes,

As migration magic through builders classes,

A fluffy refactor, clean and bright! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Remove deprecated layouts - Contained and edge to Edge [PART 1]" directly corresponds to the main change in the changeset, which adds a post-update migration routine that transitions deprecated single-column layouts to the new civictheme_three_columns layout. The title clearly communicates the deprecation/removal of old layout types and explicitly marks this as part of a multi-part effort, making it specific and informative. A teammate scanning the version history would immediately understand this is about deprecating and migrating away from old layout types.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/3547382-part1

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
web/themes/contrib/civictheme/civictheme.post_update.php (1)

997-1058: Consider extracting common logic for future updates.

This function shares significant logic with civictheme_post_update_enable_three_column_layout() (lines 685-762). While post-update hooks typically remain immutable once deployed, and this duplication appears intentional to provide a corrected migration path, consider extracting the common layout transformation logic into a reusable helper method (e.g., in CivicthemeUpdateHelper) if similar updates are anticipated in the future.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ee502b and 76839a6.

📒 Files selected for processing (1)
  • web/themes/contrib/civictheme/civictheme.post_update.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build-and-push
  • GitHub Check: build-and-push
  • GitHub Check: commit
🔇 Additional comments (3)
web/themes/contrib/civictheme/civictheme.post_update.php (3)

997-1006: LGTM: Function setup is clean.

The function correctly initializes the outdated layouts list, loads all LayoutBuilderEntityViewDisplay entities, and sets up tracking variables.


1028-1049: LGTM: Section replacement logic is sound.

The transformation correctly:

  • Replaces outdated layout IDs with 'civictheme_three_columns'
  • Preserves the is_contained setting based on the original layout
  • Maps components from the 'content' region to 'main' region (required for three-column layouts)

1050-1058: LGTM: Conditional save and message handling.

The function correctly saves only modified entity displays and returns descriptive messages. The empty return when nothing is updated is acceptable.

}
}
if ($replaced) {
$allowed_layouts[] = 'civictheme_three_columns';
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 | 🟡 Minor

Prevent potential duplicate entry in allowed_layouts.

Before appending 'civictheme_three_columns', verify it doesn't already exist in $allowed_layouts to maintain idempotency and prevent duplicates.

Apply this diff:

       if ($replaced) {
-        $allowed_layouts[] = 'civictheme_three_columns';
+        if (!in_array('civictheme_three_columns', $allowed_layouts, TRUE)) {
+          $allowed_layouts[] = 'civictheme_three_columns';
+        }
         $entity_view_mode_restriction['allowed_layouts'] = array_values($allowed_layouts);
🤖 Prompt for AI Agents
In web/themes/contrib/civictheme/civictheme.post_update.php around line 1022,
the code unconditionally appends 'civictheme_three_columns' to $allowed_layouts
which can create duplicate entries; update the code to check if
'civictheme_three_columns' is not already present in $allowed_layouts (e.g.,
using in_array or array_search) before appending so the operation is idempotent
and avoids duplicates.

@joshua-salsadigital joshua-salsadigital added the State: Needs review Pull requests needs a review from assigned developers label Oct 27, 2025
@joshua-salsadigital joshua-salsadigital changed the title Issue #3547382 by richardgaunt, joshua1234511: Remove deprecated layouts - Contained and edge to Edge Issue #3547382 by richardgaunt, joshua1234511: Remove deprecated layouts - Contained and edge to Edge [PART 1] Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

State: Needs review Pull requests needs a review from assigned developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants