You are here

protected function EntityHooks::updateMenuForMicrosite in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 modules/entity_hierarchy_microsite/src/EntityHooks.php \Drupal\entity_hierarchy_microsite\EntityHooks::updateMenuForMicrosite()

Updates menu for the microsite.

Parameters

\Drupal\entity_hierarchy_microsite\Entity\MicrositeInterface $microsite: Microsite.

3 calls to EntityHooks::updateMenuForMicrosite()
EntityHooks::onMicrositePostSave in modules/entity_hierarchy_microsite/src/EntityHooks.php
React to microsite being saved.
EntityHooks::onNodeInsert in modules/entity_hierarchy_microsite/src/EntityHooks.php
React to node insert.
EntityHooks::onNodeUpdate in modules/entity_hierarchy_microsite/src/EntityHooks.php
React to node update.

File

modules/entity_hierarchy_microsite/src/EntityHooks.php, line 198

Class

EntityHooks
Defines a class for entity hooks for the module.

Namespace

Drupal\entity_hierarchy_microsite

Code

protected function updateMenuForMicrosite(MicrositeInterface $microsite) {
  $menu_max_depth = $this->menuLinkTree
    ->maxDepth();
  foreach ($this->menuLinkDiscovery
    ->getMenuLinkDefinitions($microsite) as $uuid => $definition) {
    $plugin_id = 'entity_hierarchy_microsite:' . $uuid;
    if ($this->menuLinkManager
      ->hasDefinition($plugin_id)) {
      if ($definition['metadata']['entity_hierarchy_depth'] < $menu_max_depth) {
        $this->menuLinkManager
          ->updateDefinition($plugin_id, $definition, FALSE);
        continue;
      }
      $this->menuLinkManager
        ->removeDefinition($plugin_id);
      continue;
    }
    if ($definition['metadata']['entity_hierarchy_depth'] < $menu_max_depth) {
      $this->menuLinkManager
        ->addDefinition($plugin_id, $definition);
    }
  }
}