diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index 6408391..430dcef 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -453,7 +453,7 @@ public function onDependencyRemoval(array $dependencies) { } // If there are unresolved deleted dependencies left, disable this // component to avoid the removal of the entire display entity. - if ($renderer->hasUnresolvedDependencies($dependencies)) { + if ($this->checkUnresolvedDependencies($renderer->calculateDependencies(), $dependencies)) { $this->removeComponent($name); $arguments = [ '@display' => $this->getEntityType()->getLabel(), @@ -469,6 +469,37 @@ public function onDependencyRemoval(array $dependencies) { } /** + * Checks if the plugin has unresolved dependencies against the display entity + * removed dependencies. + * + * Note: + * - The two arguments have not the same structure. + * - $removed_dependencies has already sane defaults. All the types of events + * are filled in, even with empty arrays. + * + * @param array[] $plugin_dependencies + * A list of dependencies having the same structure as the return value of + * ConfigEntityInterface::calculateDependencies(). + * @param array[] $removed_dependencies + * A list of dependencies having the same structure as the input argument of + * ConfigEntityInterface::onDependencyRemoval(). + * + * @return bool + * TRUE if there are unresolved dependencies in $plugin_dependencies. + * + * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::calculateDependencies() + * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval() + */ + protected function checkUnresolvedDependencies(array $plugin_dependencies, array $removed_dependencies) { + foreach ($plugin_dependencies as $type => $dependencies) { + if (array_intersect($dependencies, array_keys($removed_dependencies[$type]))) { + return TRUE; + } + } + return FALSE; + } + + /** * {@inheritdoc} */ public function __sleep() { diff --git a/core/lib/Drupal/Core/Field/PluginSettingsBase.php b/core/lib/Drupal/Core/Field/PluginSettingsBase.php index 91a27df..8e12df3 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsBase.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsBase.php @@ -129,16 +129,4 @@ public function onDependencyRemoval(array $dependencies) { return FALSE; } - /** - * {@inheritdoc} - */ - public function hasUnresolvedDependencies(array $removed_dependencies) { - foreach ($this->calculateDependencies() as $type => $dependencies) { - if (array_intersect($dependencies, array_keys($removed_dependencies[$type]))) { - return TRUE; - } - } - return FALSE; - } - } diff --git a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php index 0707284..cc30eed 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php @@ -120,27 +120,4 @@ public function setThirdPartySetting($module, $key, $value); */ public function onDependencyRemoval(array $dependencies); - /** - * Checks if this plugin currently has unresolved dependencies against a given - * set of dependencies being removed. - * - * Typically, this method is used to find out if this plugin resolves all its - * dependencies in onDependencyRemoval(), against a list of dependencies being - * removed. For example, an entity view display invokes this method when - * reacting on dependencies removal. If this method returns TRUE for a - * particular component, that component is disabled to prevent the deletion of - * the entire view display entity. - * - * @param array[] $removed_dependencies - * A list of dependencies that are being removed having the same structure - * as the input argument of ConfigEntityInterface::onDependencyRemoval(). - * - * @return bool - * TRUE if there are unresolved dependencies in this plugin. - * - * @see \Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval() - * @see \Drupal\Core\Entity\EntityDisplayBase - */ - public function hasUnresolvedDependencies(array $removed_dependencies); - }