public function MenuTokenTreeStorage::rebuildNonDestructive in Menu Token 8
Same name and namespace in other branches
- 9.1.x src/Service/MenuTokenTreeStorage.php \Drupal\menu_token\Service\MenuTokenTreeStorage::rebuildNonDestructive()
File
- src/Service/MenuTokenTreeStorage.php, line 16
Class
- MenuTokenTreeStorage
- Provides a menu tree storage using the database.
Namespace
Drupal\menu_token\Service
Code
public function rebuildNonDestructive(array $definitions) {
$links = [];
$children = [];
$top_links = [];
$before_menus = $this
->getMenuNames();
if ($definitions) {
foreach ($definitions as $id => $link) {
$link['discovered'] = 1;
if (!empty($link['parent'])) {
$children[$link['parent']][$id] = $id;
}
else {
$top_links[$id] = $id;
$link['parent'] = '';
}
$links[$id] = $link;
}
}
foreach ($top_links as $id) {
$this
->saveRecursive($id, $children, $links);
}
foreach ($children as $orphan_links) {
foreach ($orphan_links as $id) {
$parent = $this
->loadFull($links[$id]['parent']);
if ($parent) {
$links[$links[$id]['parent']] = $parent;
}
else {
$links[$id]['parent'] = '';
}
$this
->saveRecursive($id, $children, $links);
}
}
$this
->resetDefinitions();
$affected_menus = $this
->getMenuNames() + $before_menus;
$cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.');
$this->cacheTagsInvalidator
->invalidateTags($cache_tags);
$this
->resetDefinitions();
$this->menuCacheBackend
->invalidateAll();
}