Problem/Motivation
Drupal\page_manager\Entity\PageVariant::calculateDependencies() returns $this->getDependencies() (an array) instead of $this:
public function calculateDependencies() {
parent::calculateDependencies();
$this->addDependency('config', $this->getPage()->getConfigDependencyName());
foreach ($this->getSelectionConditions() as $instance) {
$this->calculatePluginDependencies($instance);
}
return $this->getDependencies();
}This violates \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies(), which is documented as:
/**
* Calculates dependencies and stores them in the dependency property.
*
* @return $this
*
* @see \Drupal\Core\Config\Entity\ConfigDependencyManager
*/
public function calculateDependencies();Every other core and contrib implementation returns $this (or the parent's return value, which is $this) to support the common chained-call pattern $entity->calculateDependencies()->getDependencies().
Because PageVariant returns an array instead, any code that chains off the return value fatals. This is not a theoretical edge case — it breaks Drupal core itself. search_post_update_search_help_dependencies() (added in search_update_11402, Drupal 11.4) does exactly this chained call while iterating over all config entities that depend on a given module:
foreach (\Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('module', ['help']) as $entity) {
$dependencies = $entity->getDependencies();
if ($entity->calculateDependencies()->getDependencies() !== $dependencies) {
$entity->save();
}
}If any page_manager.page_variant.* config entity depends (directly or transitively) on a module being scanned — in our case help, via role/permission dependencies pulled in by an access condition — calculateDependencies() returns an array, and ->getDependencies() on that array fatals with:
Error: Call to a member function getDependencies() on array in search_post_update_search_help_dependencies() (line 59 of core/modules/search/search.post_update.php)
This causes drush updatedb / update.php to fail outright, blocking the site from completing Drupal core updates.
Steps to reproduce
Install Page Manager and create a page variant whose selection conditions (or parent page) create a config dependency on a module such as help (e.g. a role-based visibility condition on a role that has the "access help pages" permission).
Update to Drupal core 11.4+ (or any version shipping search_post_update_search_help_dependencies).
Run drush updatedb.
Observe the fatal error above.
More generally, any code calling $page_variant->calculateDependencies()->getDependencies() (a normal, documented pattern for ConfigEntityInterface) will fatal.
Proposed resolution
Change PageVariant::calculateDependencies() to return $this, matching the interface contract:
--- a/src/Entity/PageVariant.php
+++ b/src/Entity/PageVariant.php
@@ -195,7 +195,7 @@ class PageVariant extends ConfigEntityBase implements PageVariantInterface {
$this->calculatePluginDependencies($instance);
}
- return $this->getDependencies();
+ return $this;
}
/**| Comment | File | Size | Author |
|---|---|---|---|
| #2 | page_manager-page_variant_calculateDependencies-3617754-2.patch | 394 bytes | greenskin |
Comments
Comment #2
greenskin commentedComment #3
joelpittetSeems reasonable quick fix, can you make an Mr?