MenuLinkContent::postSave

public MenuLinkContent::postSave(EntityStorageInterface $storage, $update = TRUE)

Acts on a saved entity before the insert or update hook is invoked.

Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.

Parameters

\Drupal\Core\Entity\EntityStorageInterface $storage: The entity storage object.

bool $update: TRUE if the entity has been updated, or FALSE if it has been inserted.

Overrides Entity::postSave

File

core/modules/menu_link_content/src/Entity/MenuLinkContent.php, line 192

Class

MenuLinkContent
Defines the menu link content entity class.

Namespace

Drupal\menu_link_content\Entity

Code

public function postSave(EntityStorageInterface $storage, $update = TRUE) {
  parent::postSave($storage, $update);

  /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
  $menu_link_manager = \Drupal::service('plugin.manager.menu.link');

  // The menu link can just be updated if there is already an menu link entry
  // on both entity and menu link plugin level.
  $definition = $this->getPluginDefinition();
  // Even when $update is FALSE, for top level links it is possible the link
  // already is in the storage because of the getPluginDefinition() call
  // above, see https://www.drupal.org/node/2605684#comment-10515450 for the
  // call chain. Because of this the $update flag is ignored and only the
  // existence of the definition (equals to being in the tree storage) is
  // checked.
  if ($menu_link_manager->getDefinition($this->getPluginId(), FALSE)) {
    // When the entity is saved via a plugin instance, we should not call
    // the menu tree manager to update the definition a second time.
    if (!$this->insidePlugin) {
      $menu_link_manager->updateDefinition($this->getPluginId(), $definition, FALSE);
    }
  }
  else {
    $menu_link_manager->addDefinition($this->getPluginId(), $definition);
  }
}
doc_Drupal
2016-10-29 09:26:33
Comments
Leave a Comment

Please login to continue.