// Remove all such items.
if($result){ $this->purgeMultiple($result); } $this->resetDefinitions(); $affected_menus = $this->getMenuNames() + $before_menus; // Invalidate any cache tagged with any menu name.
$cache_tags = Cache::buildTags('config:system.menu', $affected_menus, '.'); $this->cacheTagsInvalidator->invalidateTags($cache_tags); $this->resetDefinitions(); // Every item in the cache bin should have one of the menu cache tags but it
// is not guaranteed, so invalidate everything in the bin.
$this->menuCacheBackend->invalidateAll(); }
/**
* Purges multiple menu links that no longer exist.
*
* @param array $ids
* An array of menu link IDs.
*/
// all definitions in all languages indexed
if(!$offset->hasNextLanguage()){ return null; }
// all definitions are indexed in current language, start again with next language
$offset->selectNextLanguage(); $offset->resetDefinitions(); $offset->setLastId(null);
// Modify and reset a standard menu link.
$instance = $this->getStandardMenuLink(); $old_weight = $instance->getWeight(); // Edit the static menu link.
$edit = []; $edit['weight'] = 10; $id = $instance->getPluginId(); $this->drupalGet("admin/structure/menu/link/{$id}/edit"); $this->submitForm($edit, 'Save'); $this->assertSession()->statusCodeEquals(200); $this->assertSession()->pageTextContains('The menu link has been saved.'); $menu_link_manager->resetDefinitions();
/**
* Adds a custom menu using CRUD functions.
*/ publicfunctionaddCustomMenuCRUD(){ // Add a new custom menu.
protectedfunctionassertMenuLink(array $expected_item, $menu_plugin_id){ // Retrieve the menu link.
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */ $menu_link_manager = \Drupal::service('plugin.manager.menu.link'); $menu_link_manager->resetDefinitions(); // Reset the static load cache.
\Drupal::entityTypeManager()->getStorage('menu_link_content')->resetCache(); $definition = $menu_link_manager->getDefinition($menu_plugin_id);
$entity = NULL;
// Pull the path from the menu link content.
if(str_starts_with($menu_plugin_id, 'menu_link_content')){ [, $uuid] = explode(':', $menu_plugin_id, 2); /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $entity */ $entity = \Drupal::service('entity.repository')