protected function MenuTreeStorage::doSave in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::doSave()
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.
2 calls to MenuTreeStorage::doSave()
- MenuTreeStorage::save in core/
lib/ Drupal/ Core/ Menu/ MenuTreeStorage.php - Saves a plugin definition to the storage.
- MenuTreeStorage::saveRecursive in core/
lib/ Drupal/ Core/ Menu/ MenuTreeStorage.php - Saves menu links recursively.
File
- core/
lib/ Drupal/ Core/ Menu/ MenuTreeStorage.php, line 289 - Contains \Drupal\Core\Menu\MenuTreeStorage.
Class
- MenuTreeStorage
- Provides a menu tree storage using the database.
Namespace
Drupal\Core\MenuCode
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();
$transaction = $this->connection
->startTransaction();
try {
if ($original) {
$link['mlid'] = $original['mlid'];
$link['has_children'] = $original['has_children'];
$affected_menus[$original['menu_name']] = $original['menu_name'];
}
else {
// Generate a new mlid.
$options = array(
'return' => Database::RETURN_INSERT_ID,
) + $this->options;
$link['mlid'] = $this->connection
->insert($this->table, $options)
->fields(array(
'id' => $link['id'],
'menu_name' => $link['menu_name'],
))
->execute();
}
$fields = $this
->preSave($link, $original);
// We may be moving the link to a new menu.
$affected_menus[$fields['menu_name']] = $fields['menu_name'];
$query = $this->connection
->update($this->table, $this->options);
$query
->condition('mlid', $link['mlid']);
$query
->fields($fields)
->execute();
if ($original) {
$this
->updateParentalStatus($original);
}
$this
->updateParentalStatus($link);
} catch (\Exception $e) {
$transaction
->rollback();
throw $e;
}
return $affected_menus;
}