示例#1
0
 /**
  * {@inheritdoc}
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin
  *   The plugin instance to use for this form.
  */
 public function buildForm(array $form, array &$form_state, MenuLinkInterface $menu_link_plugin = NULL)
 {
     $form['menu_link_id'] = array('#type' => 'value', '#value' => $menu_link_plugin->getPluginId());
     $class_name = $menu_link_plugin->getFormClass();
     $form['#plugin_form'] = $this->classResolver->getInstanceFromDefinition($class_name);
     $form['#plugin_form']->setMenuLinkInstance($menu_link_plugin);
     $form += $form['#plugin_form']->buildConfigurationForm($form, $form_state);
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'), '#button_type' => 'primary');
     return $form;
 }
示例#2
0
 /**
  * Resets a standard menu link using the UI.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $menu_link
  *   The Menu link.
  * @param int $old_weight
  *   Original title for menu link.
  */
 function resetMenuLink(MenuLinkInterface $menu_link, $old_weight)
 {
     // Reset menu link.
     $this->drupalPostForm("admin/structure/menu/link/{$menu_link->getPluginId()}/reset", array(), t('Reset'));
     $this->assertResponse(200);
     $this->assertRaw(t('The menu link was reset to its default settings.'), 'Menu link was reset');
     // Verify menu link.
     $instance = \Drupal::service('plugin.manager.menu.link')->createInstance($menu_link->getPluginId());
     $this->assertEqual($old_weight, $instance->getWeight(), 'Resets to the old weight.');
 }
示例#3
0
 /**
  * Provide a single block on the administration overview page.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu item to be displayed.
  *
  * @return array
  *   An array of menu items, as expected by theme_admin_block_content().
  */
 public function getAdminBlock(MenuLinkInterface $instance)
 {
     $content = array();
     // Only find the children of this link.
     $link_id = $instance->getPluginId();
     $parameters = new MenuTreeParameters();
     $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->excludeHiddenLinks();
     $tree = $this->menuTree->load(NULL, $parameters);
     $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
     $tree = $this->menuTree->transform($tree, $manipulators);
     foreach ($tree as $key => $element) {
         /** @var $link \Drupal\Core\Menu\MenuLinkInterface */
         $link = $element->link;
         $content[$key]['title'] = $link->getTitle();
         $content[$key]['options'] = $link->getOptions();
         $content[$key]['description'] = $link->getDescription();
         $content[$key]['url'] = $link->getUrlObject();
     }
     ksort($content);
     return $content;
 }
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $new_definition = $this->extractFormValues($form, $form_state);
     return $this->menuLinkManager->updateDefinition($this->menuLink->getPluginId(), $new_definition);
 }
示例#5
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);
 }
示例#6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->link = $this->menuLinkManager->resetLink($this->link->getPluginId());
     drupal_set_message($this->t('The menu link was reset to its default settings.'));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
示例#7
0
 /**
  * Constructs a new InaccessibleMenuLink.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $wrapped_link
  *   The menu link to wrap.
  */
 public function __construct(MenuLinkInterface $wrapped_link)
 {
     $this->wrappedLink = $wrapped_link;
     $plugin_definition = ['route_name' => '<front>', 'route_parameters' => [], 'url' => NULL] + $this->wrappedLink->getPluginDefinition();
     parent::__construct([], $this->wrappedLink->getPluginId(), $plugin_definition);
 }
示例#8
0
 /**
  * Provide a single block on the administration overview page.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu item to be displayed.
  *
  * @return array
  *   An array of menu items, as expected by admin-block-content.html.twig.
  */
 public function getAdminBlock(MenuLinkInterface $instance)
 {
     $content = array();
     // Only find the children of this link.
     $link_id = $instance->getPluginId();
     $parameters = new MenuTreeParameters();
     $parameters->setRoot($link_id)->excludeRoot()->setTopLevelOnly()->onlyEnabledLinks();
     $tree = $this->menuTree->load(NULL, $parameters);
     $manipulators = array(array('callable' => 'menu.default_tree_manipulators:checkAccess'), array('callable' => 'menu.default_tree_manipulators:generateIndexAndSort'));
     $tree = $this->menuTree->transform($tree, $manipulators);
     foreach ($tree as $key => $element) {
         // Only render accessible links.
         if (!$element->access->isAllowed()) {
             // @todo Bubble cacheability metadata of both accessible and
             //   inaccessible links. Currently made impossible by the way admin
             //   blocks are rendered.
             continue;
         }
         /** @var $link \Drupal\Core\Menu\MenuLinkInterface */
         $link = $element->link;
         $content[$key]['title'] = $link->getTitle();
         $content[$key]['options'] = $link->getOptions();
         $content[$key]['description'] = $link->getDescription();
         $content[$key]['url'] = $link->getUrlObject();
     }
     ksort($content);
     return $content;
 }