Beispiel #1
4
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $config = $this->configuration;
     $cacheability = new CacheableMetadata();
     $tabs = ['#theme' => 'menu_local_tasks'];
     // Add only selected levels for the printed output.
     if ($config['primary']) {
         $links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 0);
         $cacheability = $cacheability->merge($links['cacheability']);
         // Do not display single tabs.
         $tabs += ['#primary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : []];
     }
     if ($config['secondary']) {
         $links = $this->localTaskManager->getLocalTasks($this->routeMatch->getRouteName(), 1);
         $cacheability = $cacheability->merge($links['cacheability']);
         // Do not display single tabs.
         $tabs += ['#secondary' => count(Element::getVisibleChildren($links['tabs'])) > 1 ? $links['tabs'] : []];
     }
     $build = [];
     $cacheability->applyTo($build);
     if (empty($tabs['#primary']) && empty($tabs['#secondary'])) {
         return $build;
     }
     return $build + $tabs;
 }
 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     if (strpos($route_match->getRouteName(), 'view.tmgmt_local_manage_translate_task') === 0 || strpos($route_match->getRouteName(), 'view.tmgmt_local_task_overview') === 0 || $route_match->getParameter('tmgmt_local_task') instanceof LocalTaskInterface || $route_match->getParameter('tmgmt_local_task_item') instanceof LocalTaskItemInterface) {
         return TRUE;
     }
     return FALSE;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 protected function blockAccess(AccountInterface $account)
 {
     $route_name = $this->routeMatch->getRouteName();
     if ($account->isAnonymous() && !in_array($route_name, array('user.login', 'user.logout'))) {
         return AccessResult::allowed()->addCacheContexts(['route.name', 'user.roles:anonymous']);
     }
     return AccessResult::forbidden();
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $route_name = $this->routeMatch->getRouteName();
     $local_actions = $this->localActionManager->getActionsForRoute($route_name);
     if (empty($local_actions)) {
         return [];
     }
     return $local_actions;
 }
Beispiel #5
0
 /**
  * Returns the help associated with the active menu item.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  */
 protected function getActiveHelp(Request $request)
 {
     // Do not show on a 403 or 404 page.
     if ($request->attributes->has('exception')) {
         return '';
     }
     $help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
     return $help ? implode("\n", $help) : '';
 }
 /**
  * {@inheritdoc}
  */
 public function isApplicable()
 {
     // Remove on Admin routes.
     $is_admin_route = $this->adminContext->isAdminRoute();
     // Remove on Block Demo page.
     $is_admin_demo_route = $this->routeMatch->getRouteName() === 'block.admin_demo';
     // @todo Check if there is actually a different admin theme.
     //   https://www.drupal.org/node/2784853
     return $this->account->hasPermission('administer blocks') && !$is_admin_route && !$is_admin_demo_route;
 }
Beispiel #7
0
 /**
  * Ensures that the theme registry was not initialized.
  */
 public function onView(GetResponseEvent $event)
 {
     $current_route = $this->currentRouteMatch->getRouteName();
     $entity_autcomplete_route = array('system.entity_autocomplete');
     if (in_array($current_route, $entity_autcomplete_route)) {
         if ($this->container->initialized('theme.registry')) {
             throw new \Exception('registry initialized');
         }
     }
 }
 /**
  * Adds the route name as a cache tag to all cacheable responses.
  *
  * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
  *   The event to process.
  */
 public function onResponse(FilterResponseEvent $event)
 {
     $response = $event->getResponse();
     if ($response instanceof CacheableResponseInterface) {
         $cacheability_metadata = $response->getCacheableMetadata();
         // If the route specifies a 'base route name', use that. Otherwise fall
         // back to the route name. The 'base route name' is specified in
         // \Drupal\page_manager\Routing\PageManagerRoutes.
         $route_name = $this->routeMatch->getParameter('base_route_name') ?: $this->routeMatch->getRouteName();
         $cacheability_metadata->addCacheTags(['page_manager_route_name:' . $route_name]);
     }
 }
Beispiel #9
0
 /**
  * {@inheritdoc}
  */
 public function isFrontPage()
 {
     // Cache the result as this is called often.
     if (!isset($this->isCurrentFrontPage)) {
         $this->isCurrentFrontPage = FALSE;
         // Ensure that the code can also be executed when there is no active
         // route match, like on exception responses.
         if ($this->routeMatch->getRouteName()) {
             $url = Url::fromRouteMatch($this->routeMatch);
             $this->isCurrentFrontPage = $url->getRouteName() && '/' . $url->getInternalPath() === $this->getFrontPagePath();
         }
     }
     return $this->isCurrentFrontPage;
 }
 /**
  * {@inheritdoc}
  */
 protected function determineBlockContext()
 {
     if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) {
         $context = new Context(new ContextDefinition($route_contexts['node']['type']));
         if ($node = $this->routeMatch->getParameter('node')) {
             $context->setContextValue($node);
         }
         $this->addContext('node', $context);
     } elseif ($this->routeMatch->getRouteName() == 'node.add') {
         $node_type = $this->routeMatch->getParameter('node_type');
         $context = new Context(new ContextDefinition('entity:node'));
         $context->setContextValue(Node::create(array('type' => $node_type->id())));
         $this->addContext('node', $context);
     }
 }
Beispiel #11
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     $account = $this->currentUser();
     $account_is_user = $this->user->id() == $account->id();
     if ($form_state['values']['set'] == 'new') {
         // Save a new shortcut set with links copied from the user's default set.
         /* @var \Drupal\shortcut\Entity\ShortcutSet $set */
         $set = $this->shortcutSetStorage->create(array('id' => $form_state['values']['id'], 'label' => $form_state['values']['label']));
         $set->save();
         $replacements = array('%user' => $this->user->label(), '%set_name' => $set->label(), '@switch-url' => $this->url($this->routeMatch->getRouteName(), array('user' => $this->user->id())));
         if ($account_is_user) {
             // Only administrators can create new shortcut sets, so we know they have
             // access to switch back.
             drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
         } else {
             drupal_set_message($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
         }
         $form_state['redirect_route'] = array('route_name' => 'shortcut.set_customize', 'route_parameters' => array('shortcut_set' => $set->id()));
     } else {
         // Switch to a different shortcut set.
         /* @var \Drupal\shortcut\Entity\ShortcutSet $set */
         $set = $this->shortcutSetStorage->load($form_state['values']['set']);
         $replacements = array('%user' => $this->user->label(), '%set_name' => $set->label());
         drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
     }
     // Assign the shortcut set to the provided user account.
     $this->shortcutSetStorage->assignUser($set, $this->user);
 }
Beispiel #12
0
  /**
   * Displays add links for the available bundles.
   *
   * Redirects to the add form if there's only one bundle available.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
   *   The route match.
   *
   * @return \Symfony\Component\HttpFoundation\RedirectResponse|array
   *   If there's only one available bundle, a redirect response.
   *   Otherwise, a render array with the add links for each bundle.
   */
  public function addPage(RouteMatchInterface $routeMatch) {
    $routeName = $routeMatch->getRouteName();
    $defaults = $routeMatch->getRouteObject()->getDefaults();
    if (empty($defaults['_bundle_type'])) {
      throw new \InvalidArgumentException(sprintf('The route "%s" must have a "_bundle_type" default parameter.', $routeName));
    }

    $formRouteName = str_replace('.add_page', '.add_form', $routeName);
    $bundleType = $defaults['_bundle_type'];
    $bundles = $this->entityManager()->getStorage($bundleType)->loadMultiple();
    // Filter out the bundles the user doesn't have access to.
    $accessControlHandler = $this->entityManager()->getAccessControlHandler($bundleType);
    $bundles = array_filter($bundles, function($bundle) use ($accessControlHandler) {
      return $accessControlHandler->createAccess($bundle->id());
    });
    // Redirect if there's only one bundle available.
    if (count($bundles) == 1) {
      $bundle = reset($bundles);

      return $this->redirect($formRouteName, [$bundleType => $bundle->id()]);
    }

    return [
      '#theme' => 'commerce_add_list',
      '#bundles' => $bundles,
      '#bundle_type' => $bundleType,
      '#form_route_name' => $formRouteName,
    ];
  }
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // Do not show on a 403 or 404 page.
     if ($this->request->attributes->has('exception')) {
         return [];
     }
     $help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
     $build = [];
     // Remove any empty strings from $help.
     foreach (array_filter($help) as $item) {
         // Convert strings to #markup render arrays so that they will XSS admin
         // filtered.
         $build[] = is_array($item) ? $item : ['#markup' => $item];
     }
     return $build;
 }
 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     if ($route_match->getRouteName() == 'diff.revisions_diff') {
         if ($route_match->getParameter('filter') == 'raw-plain') {
             return TRUE;
         }
     }
 }
Beispiel #15
0
 /**
  * {@inheritdoc}
  */
 public function getRuntimeContexts(array $unqualified_context_ids)
 {
     $result = [];
     $context = new Context(new ContextDefinition('entity:node', NULL, FALSE));
     if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['node'])) {
         if ($node = $this->routeMatch->getParameter('node')) {
             $context->setContextValue($node);
         }
     } elseif ($this->routeMatch->getRouteName() == 'node.add') {
         $node_type = $this->routeMatch->getParameter('node_type');
         $context->setContextValue(Node::create(array('type' => $node_type->id())));
     }
     $cacheability = new CacheableMetadata();
     $cacheability->setCacheContexts(['route']);
     $context->addCacheableDependency($cacheability);
     $result['node'] = $context;
     return $result;
 }
 /**
  * @inheritdoc
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $geocoder = $route_match->getParameter('service');
     $current_route = $route_match->getRouteName();
     $links = [Link::createFromRoute($this->t('Home'), '<front>'), Link::createFromRoute($this->t('Administration'), 'system.admin'), Link::createFromRoute($this->t('Configuration'), 'system.admin_config'), Link::createFromRoute($this->t('Dmaps'), 'dmaps.settings'), Link::createFromRoute($this->t('Geocoding'), 'dmaps.locations.geocoding_options'), Link::createFromRoute($this->t('Geocoding %service', ['%service' => $geocoder]), $current_route, ['iso' => $route_match->getParameter('iso'), 'service' => $geocoder])];
     $breadcrumb->setLinks($links);
     return $breadcrumb;
 }
Beispiel #17
0
 /**
  * Checks current request route against a list of routes we want to ignore.
  *
  * @return bool
  *   TRUE if we should ignore this request, FALSE otherwise.
  */
 private function isIgnoreableRoute()
 {
     $routes_to_ignore = array('cas.service', 'cas.proxyCallback', 'cas.login', 'cas.legacy_login', 'cas.logout', 'system.cron');
     $current_route = $this->routeMatcher->getRouteName();
     if (in_array($current_route, $routes_to_ignore)) {
         return TRUE;
     }
     return FALSE;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $route_name = $route_match->getRouteName();
     if ($route_name == 'node.view' && $route_match->getParameter('node') && isset($route_match->getParameter('node')->taxonomy_catalog)) {
         return $this->catalogBreadcrumb($route_match->getParameter('node'));
     } elseif (substr($route_name, 0, 16) == 'view.uc_catalog.' && $route_match->getParameter('arg_term_node_tid_depth')) {
         return $this->catalogTermBreadcrumb($route_match->getParameter('arg_term_node_tid_depth'));
     }
 }
Beispiel #19
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // Do not show on a 403 or 404 page.
     if ($this->request->attributes->has('exception')) {
         return [];
     }
     $implementations = $this->moduleHandler->getImplementations('help');
     $build = [];
     $args = [$this->routeMatch->getRouteName(), $this->routeMatch];
     foreach ($implementations as $module) {
         // Don't add empty strings to $build array.
         if ($help = $this->moduleHandler->invoke($module, 'help', $args)) {
             // Convert strings to #markup render arrays so that they will XSS admin
             // filtered.
             $build[] = is_array($help) ? $help : ['#markup' => $help];
         }
     }
     return $build;
 }
 /**
  * Returns the default revision of the entity this route is for.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  *
  * @return \Drupal\Core\Entity\ContentEntityInterface
  *   returns the Entity in question.
  *
  * @throws \Exception
  *   A generic exception is thrown if the entity couldn't be loaded. This
  *   almost always implies a developer error, so it should get turned into
  *   an HTTP 500.
  */
 protected function loadEntity(Route $route, RouteMatchInterface $route_match)
 {
     $entity_type = $route->getOption('_content_moderation_entity_type');
     if ($entity = $route_match->getParameter($entity_type)) {
         if ($entity instanceof EntityInterface) {
             return $entity;
         }
     }
     throw new \Exception(sprintf('%s is not a valid entity route. The LatestRevisionCheck access checker may only be used with a route that has a single entity parameter.', $route_match->getRouteName()));
 }
 /**
  * {@inheritdoc}
  */
 public function getRuntimeContexts(array $unqualified_context_ids)
 {
     $result = [];
     $context_definition = new ContextDefinition('entity:support_ticket', NULL, FALSE);
     $value = NULL;
     if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['support_ticket'])) {
         if ($support_ticket = $this->routeMatch->getParameter('support_ticket')) {
             $value = $support_ticket;
         }
     } elseif ($this->routeMatch->getRouteName() == 'support_ticket.add') {
         $support_ticket_type = $this->routeMatch->getParameter('support_ticket_type');
         $value = SupportTicket::create(array('type' => $support_ticket_type->id()));
     }
     $cacheability = new CacheableMetadata();
     $cacheability->setCacheContexts(['route']);
     $context = new Context($context_definition, $value);
     $context->addCacheableDependency($cacheability);
     $result['support_ticket'] = $context;
     return $result;
 }
 /**
  * Builds the local actions for this listing.
  *
  * @return array
  *   An array of local actions for this listing.
  */
 protected function buildLocalActions()
 {
     $build = $this->localActionManager->getActionsForRoute($this->routeMatch->getRouteName());
     // Without this workaround, the action links will be rendered as <li> with
     // no wrapping <ul> element.
     if (!empty($build)) {
         $build['#prefix'] = '<ul class="action-links">';
         $build['#suffix'] = '</ul>';
     }
     return $build;
 }
Beispiel #23
0
 /**
  * @inheritDoc
  */
 public function hasData()
 {
     // Allow uninstalling of the module by informing drupal that there isn't any
     // data for it to worry about.
     $routes = array('system.modules_uninstall_confirm', 'system.modules_uninstall');
     if (in_array($this->routeMatch->getRouteName(), $routes)) {
         return FALSE;
     }
     // On all the other occasions let drupal know we have data.
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     $registration = $route_match->getParameter('registration');
     if ($event = $registration->getEvent()) {
         $links[] = new Link($event->label(), $event->urlInfo());
     }
     if ('entity.registration.canonical' != $route_match->getRouteName()) {
         $links[] = new Link($registration->label(), $registration->urlInfo());
     }
     $breadcrumb = new Breadcrumb();
     return $breadcrumb->setLinks($links)->addCacheContexts(['route.name']);
 }
 /**
  * {@inheritdoc}
  */
 public function getRuntimeContexts(array $unqualified_context_ids)
 {
     $result = [];
     $value = NULL;
     if (($route_object = $this->routeMatch->getRouteObject()) && ($route_contexts = $route_object->getOption('parameters')) && isset($route_contexts['rdf_entity'])) {
         /** @var \Drupal\rdf_entity\RdfInterface $collection */
         if ($collection = $this->routeMatch->getParameter('rdf_entity')) {
             if ($collection->bundle() == 'collection') {
                 $value = $collection;
             }
         }
     } elseif (($route_parameters = $this->routeMatch->getParameters()) && in_array($this->routeMatch->getRouteName(), $this->getSupportedRoutes())) {
         foreach ($route_parameters as $route_parameter) {
             if ($route_parameter instanceof ContentEntityInterface) {
                 $bundle = $route_parameter->bundle();
                 $entity_type = $route_parameter->getEntityTypeId();
                 // Check if the object is a og content entity.
                 if (Og::isGroupContent($entity_type, $bundle) && ($groups = $this->membershipManager->getGroupIds($route_parameter, 'rdf_entity', 'collection'))) {
                     // A content can belong to only one rdf_entity.
                     // Check that the content is not an orphaned one.
                     if ($collection_id = reset($groups['rdf_entity'])) {
                         $collection = Rdf::load($collection_id);
                         $value = $collection;
                     }
                 }
             }
         }
     }
     $cacheability = new CacheableMetadata();
     $cacheability->setCacheContexts(['route']);
     $collection_context_definition = new ContextDefinition('entity', $this->t('Organic group provided by collection'), FALSE);
     $context = new Context($collection_context_definition, $value);
     $context->addCacheableDependency($cacheability);
     $result['og'] = $context;
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function getActiveLink($menu_name = NULL)
 {
     // Note: this is a very simple implementation. If you need more control
     // over the return value, such as matching a prioritized list of menu names,
     // you should substitute your own implementation for the 'menu.active_trail'
     // service in the container.
     // The menu links coming from the storage are already sorted by depth,
     // weight and ID.
     $found = NULL;
     $route_name = $this->routeMatch->getRouteName();
     // On a default (not custom) 403 page the route name is NULL. On a custom
     // 403 page we will get the route name for that page, so we can consider
     // it a feature that a relevant menu tree may be displayed.
     if ($route_name) {
         $route_parameters = $this->routeMatch->getRawParameters()->all();
         // Load links matching this route.
         $links = $this->menuLinkManager->loadLinksByRoute($route_name, $route_parameters, $menu_name);
         // Select the first matching link.
         if ($links) {
             $found = reset($links);
         }
     }
     return $found;
 }
Beispiel #27
0
 /**
  * Returns the help associated with the active menu item.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array|string
  *   Render array or string containing the help of the matched route item.
  */
 protected function getActiveHelp(Request $request)
 {
     // Do not show on a 403 or 404 page.
     if ($request->attributes->has('exception')) {
         return '';
     }
     $help = $this->moduleHandler->invokeAll('help', array($this->routeMatch->getRouteName(), $this->routeMatch));
     $build = [];
     foreach ($help as $item) {
         if (!is_array($item)) {
             $item = ['#markup' => $item];
         }
         $build[] = $item;
     }
     return $build;
 }
Beispiel #28
0
 /**
  * {@inheritdoc}
  */
 public function getCurrentRouteMenuTreeParameters($menu_name)
 {
     $route_parameters = $this->routeMatch->getRawParameters()->all();
     ksort($route_parameters);
     $cid = 'current-route-parameters:' . $menu_name . ':route:' . $this->routeMatch->getRouteName() . ':route_parameters:' . serialize($route_parameters);
     if (!isset($this->cachedCurrentRouteParameters[$menu_name])) {
         $cache = $this->cache->get($cid);
         if ($cache && $cache->data) {
             $parameters = $cache->data;
         } else {
             $active_trail = $this->menuActiveTrail->getActiveTrailIds($menu_name);
             $parameters = new MenuTreeParameters();
             $parameters->setActiveTrail($active_trail)->addExpandedParents($active_trail)->addExpandedParents($this->treeStorage->getExpanded($menu_name, $active_trail));
             $this->cache->set($cid, $parameters, CacheBackendInterface::CACHE_PERMANENT, array('menu' => $menu_name));
         }
         $this->cachedCurrentRouteParameters[$menu_name] = $parameters;
     }
     return $this->cachedCurrentRouteParameters[$menu_name];
 }
Beispiel #29
0
 /**
  * Determine the target selector for the OpenDialogCommand.
  *
  * @param array &$options
  *   The 'target' option, if set, is used, and then removed from $options.
  * @param RouteMatchInterface $route_match
  *   When no 'target' option is set in $options, $route_match is used instead
  *   to determine the target.
  *
  * @return string
  *   The target selector.
  */
 protected function determineTargetSelector(array &$options, RouteMatchInterface $route_match)
 {
     // Generate the target wrapper for the dialog.
     if (isset($options['target'])) {
         // If the target was nominated in the incoming options, use that.
         $target = $options['target'];
         // Ensure the target includes the #.
         if (substr($target, 0, 1) != '#') {
             $target = '#' . $target;
         }
         // This shouldn't be passed on to jQuery.ui.dialog.
         unset($options['target']);
     } else {
         // Generate a target based on the route id.
         $route_name = $route_match->getRouteName();
         $target = '#' . Html::getUniqueId("drupal-dialog-{$route_name}");
     }
     return $target;
 }
Beispiel #30
0
 /**
  * Creates a new URL object from a route match.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match.
  *
  * @return $this
  */
 public static function fromRouteMatch(RouteMatchInterface $route_match)
 {
     if ($route_match->getRouteObject()) {
         return new static($route_match->getRouteName(), $route_match->getRawParameters()->all());
     } else {
         throw new \InvalidArgumentException('Route required');
     }
 }