You are here

public function LayoutBuilderEntityViewDisplay::onDependencyRemoval in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::onDependencyRemoval()
  2. 9 core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::onDependencyRemoval()

Informs the entity that entities it depends on will be deleted.

This method allows configuration entities to remove dependencies instead of being deleted themselves. Configuration entities can use this method to avoid being unnecessarily deleted during an extension uninstallation. For example, entity displays remove references to widgets and formatters if the plugin that supplies them depends on a module that is being uninstalled.

If this method returns TRUE then the entity needs to be re-saved by the caller for the changes to take effect. Implementations should not save the entity.

Parameters

array $dependencies: An array of dependencies that will be deleted keyed by dependency type. Dependency types are, for example, entity, module and theme.

Return value

bool TRUE if the entity has been changed as a result, FALSE if not.

Overrides EntityDisplayBase::onDependencyRemoval

See also

\Drupal\Core\Config\Entity\ConfigDependencyManager

\Drupal\Core\Config\ConfigEntityBase::preDelete()

\Drupal\Core\Config\ConfigManager::uninstall()

\Drupal\Core\Entity\EntityDisplayBase::onDependencyRemoval()

File

core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php, line 375

Class

LayoutBuilderEntityViewDisplay
Provides an entity view display entity that has a layout.

Namespace

Drupal\layout_builder\Entity

Code

public function onDependencyRemoval(array $dependencies) {
  $changed = parent::onDependencyRemoval($dependencies);

  // Loop through all sections and determine if the removed dependencies are
  // used by their layout plugins.
  foreach ($this
    ->getSections() as $delta => $section) {
    $layout_dependencies = $this
      ->getPluginDependencies($section
      ->getLayout());
    $layout_removed_dependencies = $this
      ->getPluginRemovedDependencies($layout_dependencies, $dependencies);
    if ($layout_removed_dependencies) {

      // @todo Allow the plugins to react to their dependency removal in
      //   https://www.drupal.org/project/drupal/issues/2579743.
      $this
        ->removeSection($delta);
      $changed = TRUE;
    }
    else {
      foreach ($section
        ->getComponents() as $uuid => $component) {
        $plugin_dependencies = $this
          ->getPluginDependencies($component
          ->getPlugin());
        $component_removed_dependencies = $this
          ->getPluginRemovedDependencies($plugin_dependencies, $dependencies);
        if ($component_removed_dependencies) {

          // @todo Allow the plugins to react to their dependency removal in
          //   https://www.drupal.org/project/drupal/issues/2579743.
          $section
            ->removeComponent($uuid);
          $changed = TRUE;
        }
      }
    }
  }
  return $changed;
}