Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function extractFormValues(array &$form, FormStateInterface $form_state)
 {
     // Start from the complete, original, definition.
     $new_definition = $this->menuLink->getPluginDefinition();
     // Since the ID may not be present in the definition used to construct the
     // plugin, add it here so it's available to any consumers of this method.
     $new_definition['id'] = $form_state->getValue('id');
     $new_definition['enabled'] = $form_state->getValue('enabled') ? 1 : 0;
     $new_definition['weight'] = (int) $form_state->getValue('weight');
     $new_definition['expanded'] = $form_state->getValue('expanded') ? 1 : 0;
     list($menu_name, $parent) = explode(':', $form_state->getValue('menu_parent'), 2);
     if (!empty($menu_name)) {
         $new_definition['menu_name'] = $menu_name;
     }
     if (isset($parent)) {
         $new_definition['parent'] = $parent;
     }
     return $new_definition;
 }
Esempio n. 2
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);
 }
 /**
  * Checks access for one menu link instance.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu link instance.
  *
  * @return bool
  *   TRUE if the current user can access the link, FALSE otherwise.
  */
 protected function menuLinkCheckAccess(MenuLinkInterface $instance)
 {
     // Use the definition here since that's a lot faster than creating a Url
     // object that we don't need.
     $definition = $instance->getPluginDefinition();
     // 'url' should only be populated for external links.
     if (!empty($definition['url']) && empty($definition['route_name'])) {
         $access = TRUE;
     } else {
         $access = $this->accessManager->checkNamedRoute($definition['route_name'], $definition['route_parameters'], $this->account);
     }
     return $access;
 }
 /**
  * Checks access for one menu link instance.
  *
  * @param \Drupal\Core\Menu\MenuLinkInterface $instance
  *   The menu link instance.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 protected function menuLinkCheckAccess(MenuLinkInterface $instance)
 {
     $access_result = NULL;
     if ($this->account->hasPermission('link to any page')) {
         $access_result = AccessResult::allowed();
     } else {
         // Use the definition here since that's a lot faster than creating a Url
         // object that we don't need.
         $definition = $instance->getPluginDefinition();
         // 'url' should only be populated for external links.
         if (!empty($definition['url']) && empty($definition['route_name'])) {
             $access_result = AccessResult::allowed();
         } else {
             $access_result = $this->accessManager->checkNamedRoute($definition['route_name'], $definition['route_parameters'], $this->account, TRUE);
         }
     }
     return $access_result->cachePerPermissions();
 }