/** * Checks access based on whether the link can be reset. * * @param \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin * The menu link plugin being checked. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */ public function linkIsResettable(MenuLinkInterface $menu_link_plugin) { return AccessResult::allowedIf($menu_link_plugin->isResettable())->setCacheMaxAge(0); }
/** * Resets the menu link to its default settings. * * @param \Drupal\Core\Menu\MenuLinkInterface $instance * The menu link which should be reset. * * @return \Drupal\Core\Menu\MenuLinkInterface * The reset menu link. * * @throws \Drupal\Component\Plugin\Exception\PluginException * Thrown when the menu link is not resettable. */ protected function resetInstance(MenuLinkInterface $instance) { $id = $instance->getPluginId(); if (!$instance->isResettable()) { throw new PluginException("Menu link {$id} is not resettable"); } // Get the original data from disk, reset the override and re-save the menu // tree for this link. $definition = $this->getDefinitions()[$id]; $this->overrides->deleteOverride($id); $this->treeStorage->save($definition); return $this->createInstance($id); }
/** * Checks access based on whether the link can be reset. * * @param \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin * The menu link plugin being checked. * * @return string * AccessInterface::ALLOW when access was granted, otherwise * AccessInterface::DENY. */ public function linkIsResettable(MenuLinkInterface $menu_link_plugin) { return $menu_link_plugin->isResettable() ? AccessInterface::ALLOW : AccessInterface::DENY; }