You are here

protected function MenuLinkItem::doSave in Menu Link (Field) 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Field/FieldType/MenuLinkItem.php \Drupal\menu_link\Plugin\Field\FieldType\MenuLinkItem::doSave()

Saves the plugin definition.

1 call to MenuLinkItem::doSave()
MenuLinkItem::postSave in src/Plugin/Field/FieldType/MenuLinkItem.php
Defines custom post-save behavior for field values.

File

src/Plugin/Field/FieldType/MenuLinkItem.php, line 227

Class

MenuLinkItem
Defines a menu link field type which stores the link, parent and menu.

Namespace

Drupal\menu_link\Plugin\Field\FieldType

Code

protected function doSave() {
  $menu_link_per_translation = $this
    ->getSetting('menu_link_per_translation');

  // We only update the menu link definition when working with the original
  // language value of the field, otherwise, we can never properly update or
  // remove the menu link.
  // @todo - use the FieldTranslationSynchronizer
  // https://www.drupal.org/node/2403455
  if (!$menu_link_per_translation && $this
    ->getLangcode() != $this
    ->getEntity()
    ->getUntranslated()
    ->language()
    ->getId()) {
    return;
  }
  $langcode = $menu_link_per_translation ? $this
    ->getLangcode() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
  $plugin_id = $this
    ->getMenuPluginId($langcode);

  // 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 ($menu_plugin_definition = $this
    ->getMenuPluginDefinition($langcode)) {
    if (!$this->menuPluginManager
      ->hasDefinition($plugin_id)) {
      $this->menuPluginManager
        ->addDefinition($plugin_id, $menu_plugin_definition);
    }
    else {
      $this->menuPluginManager
        ->updateDefinition($plugin_id, $menu_plugin_definition, FALSE);
    }
  }
  else {
    $this->menuPluginManager
      ->removeDefinition($plugin_id, FALSE);
  }
}