Generated with the help of an LLM.

Problem/Motivation

PageLayout::calculateDependencies() builds every root source without a guard.
A source plugin that no longer exists throws PluginNotFoundException, and the uninstall of a theme aborts.

Steps to reproduce

  • Store a page layout with a root node using a missing source plugin, next to a component of a theme.
  • Set another default theme and uninstall the first one: it throws.

Proposed resolution

Skip a source that cannot be built and log it, as SourceTree::onDependencyRemoval() does.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mogtofu33 created an issue. See original summary.

juc1’s picture

Assigned: Unassigned » juc1

juc1’s picture

MR with the help of Antigravity AI:

### Summary
When uninstalling a theme or module, Drupal recalculates configuration dependencies on dependent entities. If a Page Layout contains a source plugin that no longer exists or cannot be built, `PageLayout::calculateDependencies()` attempts to instantiate it without error handling. This triggers an unhandled `PluginNotFoundException` and causes the theme uninstallation process to crash with a fatal error.

This can be resolved by wrapping the source plugin instantiation in `PageLayout::calculateDependencies()` in a defensive `try / catch (\Exception $e)` block—mirroring the pattern already used in `SourceTree::onDependencyRemoval()`. If a source cannot be instantiated, a warning is logged to the `display_builder_page_layout` logger channel and that source is skipped, allowing dependency recalculation and extension uninstallation to finish cleanly.

### Technical Details & Files Changed
- **`modules/display_builder_page_layout/src/Entity/PageLayout.php`**:
- Wrapped `$this->sourceManager()->getSource()` in a `try/catch` block.
- Added an `instanceof SourceInterface` check.
- Added a warning log via `\Drupal::logger('display_builder_page_layout')` recording the offending node ID and error message.
- **`modules/display_builder_page_layout/tests/src/Kernel/PageLayoutConfigDependenciesTest.php`**:
- Added `testUnknownSourceDoesNotAbortThemeUninstall()` to reproduce the issue and verify both the graceful handling in `calculateDependencies()` and successful theme uninstallation.
- Asserted warning log presence using `ColinODell\PsrTestLogger\TestLogger`.

### Testing & Quality Assurance
- Automated tests pass (74 kernel tests, 831 assertions).
- PHPCS passes with 0 errors and 0 warnings.
- PHPStan passes with 0 errors.

juc1’s picture

Assigned: juc1 » Unassigned
Status: Active » Needs review

  • mogtofu33 committed 6c4d1f81 on 1.0.x authored by juc1
    fix: #3638881 A page layout holding an unknown source plugin aborts a...
mogtofu33’s picture

Status: Needs review » Fixed

Thanks for the fix, a possible follow-up: an unknown source nested inside a component skips that whole root's dependencies.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.