You are here

protected function MongodbMenuTreeStorage::doSave in MongoDB 8

Saves a link without clearing caches.

Parameters

array $link: A definition, according to $definitionFields, for a \Drupal\Core\Menu\MenuLinkInterface plugin.

Return value

array The menu names affected by the save operation. This will be one menu name if the link is saved to the sane menu, or two if it is saved to a new menu.

Throws

\Exception Thrown if the storage back-end does not exist and could not be created.

\Drupal\Component\Plugin\Exception\PluginException Thrown if the definition is invalid, for example, if the specified parent would cause the links children to be moved to greater than the maximum depth.

Overrides MenuTreeStorage::doSave

File

src/MongodbMenuTreeStorage.php, line 148
Contains \Drupal\mongodb\MongodbMenuTreeStorage .

Class

MongodbMenuTreeStorage

Namespace

Drupal\mongodb

Code

protected function doSave(array $link) {
  $original = $this
    ->loadFull($link['id']);

  // @todo Should we just return here if the link values match the original
  //   values completely?
  //   https://www.drupal.org/node/2302137
  $affected_menus = array();
  if ($original) {
    $mlid = $original['mlid'];
    $link['has_children'] = $original['has_children'];
    $affected_menus[$original['menu_name']] = $original['menu_name'];
  }
  else {

    // Generate a new mlid.
    $mlid = $this->mongo
      ->nextId('menu_links');
  }
  $link['mlid'] = $mlid;
  $fields = $this
    ->preSave($link, $original);
  $fields['mlid'] = $mlid;

  // We may be moving the link to a new menu.
  $affected_menus[$fields['menu_name']] = $fields['menu_name'];
  $newobj['$set']['value'] = $fields;
  $this
    ->mongoCollection()
    ->update([
    'value.mlid' => $fields['mlid'],
  ], $newobj, [
    'upsert' => TRUE,
  ]);
  if ($original) {
    $this
      ->updateParentalStatus($original);
  }
  $this
    ->updateParentalStatus($link);
  return $affected_menus;
}