You are here

public function EntityHooks::onMenuOverridePostSave 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::onMenuOverridePostSave()

Post save handler for overrides.

Parameters

\Drupal\entity_hierarchy_microsite\Entity\MicrositeMenuItemOverrideInterface $item: Item saved.

bool $update: TRUE if is an update.

File

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

Class

EntityHooks
Defines a class for entity hooks for the module.

Namespace

Drupal\entity_hierarchy_microsite

Code

public function onMenuOverridePostSave(MicrositeMenuItemOverrideInterface $item, $update = FALSE) {
  if ($item
    ->isSyncing()) {
    return;
  }
  $plugin_id = 'entity_hierarchy_microsite:' . $item
    ->getTarget();
  if ($this->menuLinkManager
    ->hasDefinition($plugin_id) && ($original = $this->menuLinkManager
    ->getDefinition($plugin_id))) {
    $definition = [
      'title' => $item
        ->label(),
      'weight' => $item
        ->getWeight(),
      'form_class' => MicrositeMenuItemForm::class,
      'enabled' => $item
        ->isEnabled(),
      'expanded' => $item
        ->isExpanded(),
      'parent' => $item
        ->getParent(),
    ] + $original;
    if (!$update) {
      $definition['metadata'] = [
        'original' => array_intersect_key($original, [
          'title' => TRUE,
          'weight' => TRUE,
          'enabled' => TRUE,
          'expanded' => TRUE,
          'parent' => TRUE,
        ]),
      ] + $original['metadata'];
    }
    $this->menuLinkManager
      ->updateDefinition($plugin_id, $definition);
  }
}