function LayoutBuilderEntityViewDisplay::onDependencyRemoval

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

Overrides EntityDisplayBase::onDependencyRemoval

File

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

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.