Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Lendude on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.4.x
Issue links:
Description:
In order to prevent the deletion of the whole View when a dependency is removed, Views plugins can now react to dependency removal by implementing Drupal\views\Plugin\DependentWithRemovalPluginInterface
and implementing the onDependencyRemoval
method.
Example from \Drupal\views\Plugin\views\field\EntityField
:
/**
* {@inheritdoc}
*/
public function onDependencyRemoval(array $dependencies) {
// See if this handler is responsible for any of the dependencies being
// removed. If this is the case, indicate that this handler needs to be
// removed from the View.
$remove = FALSE;
// Get all the current dependencies for this handler.
$current_dependencies = $this->calculateDependencies();
foreach ($current_dependencies as $group => $dependency_list) {
// Check if any of the handler dependencies match the dependencies being
// removed.
foreach ($dependency_list as $config_key) {
if (isset($dependencies[$group]) && array_key_exists($config_key, $dependencies[$group])) {
// This handlers dependency matches a dependency being removed,
// indicate that this handler needs to be removed.
$remove = TRUE;
break 2;
}
}
}
return $remove;
}
Impacts:
Module developers