Example #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 build(RouteMatchInterface $route_match)
 {
     $book_nids = array();
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     $book = $route_match->getParameter('node')->book;
     $depth = 1;
     // We skip the current node.
     while (!empty($book['p' . ($depth + 1)])) {
         $book_nids[] = $book['p' . $depth];
         $depth++;
     }
     $parent_books = $this->nodeStorage->loadMultiple($book_nids);
     if (count($parent_books) > 0) {
         $depth = 1;
         while (!empty($book['p' . ($depth + 1)])) {
             if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) {
                 if ($parent_book->access('view', $this->account)) {
                     $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id()));
                 }
             }
             $depth++;
         }
     }
     return $links;
 }
 /**
  * Checks if the user has access to underlying storage for a Panels display.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account)
 {
     $panels_storage_type = $route_match->getParameter('panels_storage_type');
     $panels_storage_id = $route_match->getParameter('panels_storage_id');
     $op = $route->getRequirement('_panels_storage_access');
     return $this->panelsStorage->access($panels_storage_type, $panels_storage_id, $op, $account);
 }
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $entity_type = $this->getDerivativeId();
     if ($this->routematch->getMasterRouteMatch()->getParameter($entity_type)) {
         return array('#theme' => 'links__entity__printable', '#links' => $this->linkBuilder->buildLinks($this->routematch->getMasterRouteMatch()->getParameter($entity_type)));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = new Breadcrumb();
     $breadcrumb->addLink(Link::createFromRoute($this->t('Home'), '<front>'));
     $term = $route_match->getParameter('taxonomy_term');
     // Breadcrumb needs to have terms cacheable metadata as a cacheable
     // dependency even though it is not shown in the breadcrumb because e.g. its
     // parent might have changed.
     $breadcrumb->addCacheableDependency($term);
     // @todo This overrides any other possible breadcrumb and is a pure
     //   hard-coded presumption. Make this behavior configurable per
     //   vocabulary or term.
     $parents = $this->termStorage->loadAllParents($term->id());
     // Remove current term being accessed.
     array_shift($parents);
     foreach (array_reverse($parents) as $term) {
         $term = $this->entityManager->getTranslationFromContext($term);
         $breadcrumb->addCacheableDependency($term);
         $breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id())));
     }
     // This breadcrumb builder is based on a route parameter, and hence it
     // depends on the 'route' cache context.
     $breadcrumb->addCacheContexts(['route']);
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id)
 {
     // The URL of this entity form contains only the ID of the field_config
     // but we are actually editing a field_storage_config entity.
     $field_config = FieldConfig::load($route_match->getRawParameter('field_config'));
     return $field_config->getFieldStorageDefinition();
 }
 /**
  * Checks access to the translation overview for the entity and bundle.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $entity_type_id
  *   The entity type ID.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(RouteMatchInterface $route_match, AccountInterface $account, $entity_type_id)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     $entity = $route_match->getParameter($entity_type_id);
     if ($entity && $entity->isTranslatable()) {
         // Get entity base info.
         $bundle = $entity->bundle();
         // Get entity access callback.
         $definition = $this->entityManager->getDefinition($entity_type_id);
         $translation = $definition->get('translation');
         $access_callback = $translation['content_translation']['access_callback'];
         $access = call_user_func($access_callback, $entity);
         if ($access->isAllowed()) {
             return $access;
         }
         // Check "translate any entity" permission.
         if ($account->hasPermission('translate any entity')) {
             return AccessResult::allowed()->cachePerPermissions()->inheritCacheability($access);
         }
         // Check per entity permission.
         $permission = "translate {$entity_type_id}";
         if ($definition->getPermissionGranularity() == 'bundle') {
             $permission = "translate {$bundle} {$entity_type_id}";
         }
         return AccessResult::allowedIfHasPermission($account, $permission)->inheritCacheability($access);
     }
     // No opinion.
     return AccessResult::neutral();
 }
 /**
  * Checks translation access for the entity and operation on the given route.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   The route to check against.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The parametrized route.
  * @param \Drupal\Core\Session\AccountInterface $account
  *   The currently logged in account.
  * @param string $source
  *   (optional) For a create operation, the language code of the source.
  * @param string $target
  *   (optional) For a create operation, the language code of the translation.
  * @param string $language
  *   (optional) For an update or delete operation, the language code of the
  *   translation being updated or deleted.
  * @param string $entity_type_id
  *   (optional) The entity type ID.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL)
 {
     /* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
     if ($entity = $route_match->getParameter($entity_type_id)) {
         if ($account->hasPermission('translate any entity')) {
             return AccessResult::allowed()->cachePerRole();
         }
         $operation = $route->getRequirement('_access_content_translation_manage');
         /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */
         $handler = $this->entityManager->getHandler($entity->getEntityTypeId(), 'translation');
         // Load translation.
         $translations = $entity->getTranslationLanguages();
         $languages = $this->languageManager->getLanguages();
         switch ($operation) {
             case 'create':
                 $source_language = $this->languageManager->getLanguage($source) ?: $entity->language();
                 $target_language = $this->languageManager->getLanguage($target) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $is_new_translation = $source_language->getId() != $target_language->getId() && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()]);
                 return AccessResult::allowedIf($is_new_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
             case 'update':
             case 'delete':
                 $language = $this->languageManager->getLanguage($language) ?: $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
                 $has_translation = isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]);
                 return AccessResult::allowedIf($has_translation)->cachePerRole()->cacheUntilEntityChanges($entity)->andIf($handler->getTranslationAccess($entity, $operation));
         }
     }
     // No opinion.
     return AccessResult::neutral();
 }
Example #9
0
 /**
  * Handler a response for a given view and display.
  *
  * @param string $view_id
  *   The ID of the view
  * @param string $display_id
  *   The ID of the display.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match.
  * @return null|void
  */
 public function handle($view_id, $display_id, RouteMatchInterface $route_match)
 {
     $args = array();
     $route = $route_match->getRouteObject();
     $map = $route->hasOption('_view_argument_map') ? $route->getOption('_view_argument_map') : array();
     foreach ($map as $attribute => $parameter_name) {
         // Allow parameters be pulled from the request.
         // The map stores the actual name of the parameter in the request. Views
         // which override existing controller, use for example 'node' instead of
         // arg_nid as name.
         if (isset($map[$attribute])) {
             $attribute = $map[$attribute];
         }
         if ($arg = $route_match->getRawParameter($attribute)) {
         } else {
             $arg = $route_match->getParameter($attribute);
         }
         if (isset($arg)) {
             $args[] = $arg;
         }
     }
     /** @var \Drupal\views\Plugin\views\display\DisplayPluginBase $class */
     $class = $route->getOption('_view_display_plugin_class');
     if ($route->getOption('returns_response')) {
         /** @var \Drupal\views\Plugin\views\display\ResponseDisplayPluginInterface $class */
         return $class::buildResponse($view_id, $display_id, $args);
     } else {
         $build = $class::buildBasicRenderable($view_id, $display_id, $args, $route);
         Page::setPageRenderArray($build);
         return $build;
     }
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function processOutbound($route_name, Route $route, array &$parameters, BubbleableMetadata $bubbleable_metadata = NULL)
 {
     if ($route_name === '<current>') {
         if ($current_route = $this->routeMatch->getRouteObject()) {
             $requirements = $current_route->getRequirements();
             // Setting _method and _schema is deprecated since 2.7. Using
             // setMethods() and setSchemes() are now the recommended ways.
             unset($requirements['_method']);
             unset($requirements['_schema']);
             $route->setRequirements($requirements);
             $route->setPath($current_route->getPath());
             $route->setSchemes($current_route->getSchemes());
             $route->setMethods($current_route->getMethods());
             $route->setOptions($current_route->getOptions());
             $route->setDefaults($current_route->getDefaults());
             $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
             if ($bubbleable_metadata) {
                 $bubbleable_metadata->addCacheContexts(['route']);
             }
         } else {
             // If we have no current route match available, point to the frontpage.
             $route->setPath('/');
         }
     }
 }
Example #11
0
 /**
  * {@inheritdoc}
  */
 public function getRouteParameters(RouteMatchInterface $route_match)
 {
     $parameters = isset($this->pluginDefinition['route_parameters']) ? $this->pluginDefinition['route_parameters'] : array();
     $route = $this->routeProvider()->getRouteByName($this->getRouteName());
     $variables = $route->compile()->getVariables();
     // Normally the \Drupal\Core\ParamConverter\ParamConverterManager has
     // processed the Request attributes, and in that case the _raw_variables
     // attribute holds the original path strings keyed to the corresponding
     // slugs in the path patterns. For example, if the route's path pattern is
     // /filter/tips/{filter_format} and the path is /filter/tips/plain_text then
     // $raw_variables->get('filter_format') == 'plain_text'.
     $raw_variables = $route_match->getRawParameters();
     foreach ($variables as $name) {
         if (isset($parameters[$name])) {
             continue;
         }
         if ($raw_variables && $raw_variables->has($name)) {
             $parameters[$name] = $raw_variables->get($name);
         } elseif ($value = $route_match->getRawParameter($name)) {
             $parameters[$name] = $value;
         }
     }
     // The UrlGenerator will throw an exception if expected parameters are
     // missing. This method should be overridden if that is possible.
     return $parameters;
 }
 /**
  * Displays the 'Edit existing entity_test' form.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match object to get entity type from.
  * @param string $entity_type_id
  *   The entity type ID.
  *
  * @return array
  *   The processed form for the edited entity.
  *
  * @see \Drupal\entity_test\Routing\EntityTestRoutes::routes()
  */
 public function testEdit(RouteMatchInterface $route_match, $entity_type_id)
 {
     $entity = $route_match->getParameter($entity_type_id);
     $form = $this->entityFormBuilder()->getForm($entity);
     $form['#title'] = $entity->label();
     return $form;
 }
Example #13
0
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $book_nids = array();
     $breadcrumb = new Breadcrumb();
     $links = array(Link::createFromRoute($this->t('Home'), '<front>'));
     $book = $route_match->getParameter('node')->book;
     $depth = 1;
     // We skip the current node.
     while (!empty($book['p' . ($depth + 1)])) {
         $book_nids[] = $book['p' . $depth];
         $depth++;
     }
     $parent_books = $this->nodeStorage->loadMultiple($book_nids);
     if (count($parent_books) > 0) {
         $depth = 1;
         while (!empty($book['p' . ($depth + 1)])) {
             if (!empty($parent_books[$book['p' . $depth]]) && ($parent_book = $parent_books[$book['p' . $depth]])) {
                 $access = $parent_book->access('view', $this->account, TRUE);
                 $breadcrumb->addCacheableDependency($access);
                 if ($access->isAllowed()) {
                     $breadcrumb->addCacheableDependency($parent_book);
                     $links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id()));
                 }
             }
             $depth++;
         }
     }
     $breadcrumb->setLinks($links);
     $breadcrumb->addCacheContexts(['route.book_navigation']);
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = array();
     $breadcrumb[] = $this->l($this->t('Home'), '<front>');
     $entity = $this->entityManager->getStorage($route_match->getParameter('entity_type'))->load($route_match->getParameter('entity_id'));
     $breadcrumb[] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo());
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function build(RouteMatchInterface $route_match)
 {
     $breadcrumb = array();
     $breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>');
     $entity = $route_match->getParameter('entity');
     $breadcrumb[] = new Link($entity->label(), $entity->urlInfo());
     return $breadcrumb;
 }
 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     if ($route_match->getRouteObject() !== null) {
         $URI = $route_match->getRouteObject()->getPath();
         // Use this theme on a certain route.
         return substr($URI, 1, 4) == 'view';
     }
 }
 /**
  * {@inheritdoc}
  */
 public function applies(RouteMatchInterface $route_match)
 {
     if ($route_match->getRouteName() == 'diff.revisions_diff') {
         if ($route_match->getParameter('filter') == 'raw-plain') {
             return TRUE;
         }
     }
 }
Example #18
0
 /**
  * Check if the filter is used for the given filter.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route
  *   The route.
  *
  * @return \Drupal\Core\Access\AccessResult
  *   An access result.
  */
 public function access(RouteMatchInterface $route)
 {
     $filter = $route->getParameter('filter_format');
     if (!$filter || empty($filter->filters()->get('video_embed_wysiwyg')->getConfiguration()['status'])) {
         return AccessResult::forbidden()->addCacheableDependency($filter);
     }
     return AccessResult::allowed()->addCacheableDependency($filter);
 }
Example #19
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();
 }
Example #20
0
  /**
   * Constructs a new Entity Clone form.
   *
   * @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The route match service.
   * @param \Drupal\Core\StringTranslation\TranslationManager $string_translation
   *   The string translation manager.
   *
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   */
  public function __construct(EntityTypeManager $entity_type_manager, RouteMatchInterface $route_match, TranslationManager $string_translation) {
    $this->entityTypeManager = $entity_type_manager;
    $this->stringTranslationManager = $string_translation;

    $parameter_name = $route_match->getRouteObject()->getOption('_entity_clone_entity_type_id');
    $this->entity = $route_match->getParameter($parameter_name);

    $this->entityTypeDefinition = $entity_type_manager->getDefinition($this->entity->getEntityTypeId());
  }
Example #21
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;
 }
 /**
  * Checks new registrations are permitted on an event.
  */
 public function access(Route $route, RouteMatchInterface $route_match, AccountInterface $account, RegistrationTypeInterface $registration_type = NULL)
 {
     if ($event = $route->getDefault('event')) {
         $context = ['event' => $route_match->getParameter($event)];
         $access_control_handler = $this->entityManager->getAccessControlHandler('registration');
         return $access_control_handler->createAccess($registration_type, $account, $context, TRUE);
     }
     return AccessResult::forbidden();
 }
 /**
  * @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;
 }
Example #24
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) : '';
 }
Example #25
0
 /**
  * Prints the loaded structure of the current entity.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *    A RouteMatch object.
  *
  * @return array
  *    Array of page elements to render.
  */
 public function entityTokens(RouteMatchInterface $route_match)
 {
     $output = [];
     $parameter_name = $route_match->getRouteObject()->getOption('_token_entity_type_id');
     $entity = $route_match->getParameter($parameter_name);
     if ($entity && $entity instanceof EntityInterface) {
         $output = $this->renderTokenTree($entity);
     }
     return $output;
 }
Example #26
0
 /**
  * Determines whether the active route is an admin one.
  *
  * @param \Symfony\Component\Routing\Route $route
  *   (optional) The route to determine whether it is an admin one. Per default
  *   this falls back to the route object on the active request.
  *
  * @return bool
  *   Returns TRUE if the route is an admin one, otherwise FALSE.
  */
 public function isAdminRoute(Route $route = NULL)
 {
     if (!$route) {
         $route = $this->routeMatch->getRouteObject();
         if (!$route) {
             return FALSE;
         }
     }
     return (bool) $route->getOption('_admin_route');
 }
 /**
  * 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()));
 }
Example #28
0
 /**
  * {@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;
 }
 /**
  * {@inheritdoc}
  */
 public function processOutbound($route_name, Route $route, array &$parameters)
 {
     if ($route_name === '<current>' && ($current_route = $this->routeMatch->getRouteObject())) {
         $route->setPath($current_route->getPath());
         $route->setRequirements($current_route->getRequirements());
         $route->setOptions($current_route->getOptions());
         $route->setDefaults($current_route->getDefaults());
         $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all());
     }
 }
Example #30
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');
         }
     }
 }