public function MenuTreeStorage::rebuild in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::rebuild()
- 9 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::rebuild()
File
- core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 144
Class
- MenuTreeStorage
- Provides a menu tree storage using the database.
Namespace
Drupal\Core\Menu
Code
public function rebuild(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);
}
}
$result = $this
->findNoLongerExistingLinks($definitions);
if ($result) {
$this
->purgeMultiple($result);
}
$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();
}