diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index e58fed6..6408391 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. - elseif (static::isUnresolved($renderer->calculateDependencies(), $dependencies)) { + if ($renderer->hasUnresolvedDependencies($dependencies)) { $this->removeComponent($name); $arguments = [ '@display' => $this->getEntityType()->getLabel(), @@ -469,37 +469,6 @@ public function onDependencyRemoval(array $dependencies) { } /** - * Checks if the plugin has unresolved dependencies against the display entity - * removed dependencies. - * - * Note: - * 1. The two arguments don't have the same structure. - * 2. $removed_dependencies has already sane defaults. All the types of - * dependencies 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 static function isUnresolved(array $plugin_dependencies, array $removed_dependencies) { - foreach ($plugin_dependencies as $type => $dependencies) { - if (array_diff($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 8e12df3..d161187 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsBase.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsBase.php @@ -129,4 +129,16 @@ public function onDependencyRemoval(array $dependencies) { return FALSE; } + /** + * {@inheritdoc} + */ + public function hasUnresolvedDependencies(array $removed) { + foreach ($this->calculateDependencies() as $type => $dependencies) { + if (array_intersect($dependencies, array_keys($removed[$type]))) { + return TRUE; + } + } + return FALSE; + } + } diff --git a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php index cc30eed..1a27454 100644 --- a/core/lib/Drupal/Core/Field/PluginSettingsInterface.php +++ b/core/lib/Drupal/Core/Field/PluginSettingsInterface.php @@ -120,4 +120,27 @@ 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 + * 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); + }