/** * Perform menu-specific rebuilding. */ protected function menuLinksRebuild() { if ($this->lock->acquire(__FUNCTION__)) { $transaction = db_transaction(); try { // Ensure the menu links are up to date. menu_link_rebuild_defaults(); // Clear the menu cache. menu_cache_clear_all(); // Track which menu items are expanded. _menu_update_expanded_menus(); } catch (\Exception $e) { $transaction->rollback(); watchdog_exception('menu', $e); } $this->lock->release(__FUNCTION__); } else { // Wait for another request that is already doing this work. // We choose to block here since otherwise the router item may not // be available during routing resulting in a 404. $this->lock->wait(__FUNCTION__); } }
/** * {@inheritdoc} */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); // Check the has_children status of the parent. $storage->updateParentalStatus($this); // Entity::postSave() calls Entity::invalidateTagsOnSave(), which only // handles the regular cases. The MenuLink entity has two special cases. $cache_tags = array(); // Case 1: a newly created menu link is *also* added to a menu, so we must // invalidate the associated menu's cache tag. if (!$update) { $cache_tags = $this->getCacheTag(); } // Case 2: a menu link may be moved from one menu to another; the original // menu's cache tag must also be invalidated. if (isset($this->original) && $this->menu_name != $this->original->menu_name) { $cache_tags = NestedArray::mergeDeep($cache_tags, $this->original->getCacheTag()); } Cache::invalidateTags($cache_tags); // Also clear the menu system static caches. menu_reset_static_cache(); // Track which menu items are expanded. _menu_update_expanded_menus(); }