getRouteName example


  public function onException(ExceptionEvent $event) {
    $exception = $event->getThrowable();

    // If this is not a 404, we don't need to check for a redirection.     if (!($exception instanceof NotFoundHttpException)) {
      return;
    }

    $previous_exception = $exception->getPrevious();
    if ($previous_exception instanceof ParamNotConvertedException) {
      $route_name = $previous_exception->getRouteName();
      $parameters = $previous_exception->getRawParameters();
      if ($route_name === 'entity.node.canonical' && isset($parameters['node'])) {
        // If the node_translation_redirect state is not set, we don't need to check         // for a redirection.         if (!$this->state->get('node_translation_redirect')) {
          return;
        }
        $old_nid = $parameters['node'];
        $collection = $this->keyValue->get('node_translation_redirect');
        if ($old_nid && $value = $collection->get($old_nid)) {
          [$nid$langcode] = $value;
          
/** * Tests the getRouteName() method. * * @depends testFromUri * @dataProvider providerFromUri * * @covers ::getRouteName */
  public function testGetRouteName($uri) {
    $url = Url::fromUri($uri);
    $this->expectException(\UnexpectedValueException::class);
    $url->getRouteName();
  }

  /** * Tests the getRouteParameters() method. * * @depends testFromUri * @dataProvider providerFromUri * * @covers ::getRouteParameters */
  public function testGetRouteParameters($uri) {
    


  /** * @covers ::createFromRequest * @covers ::__construct */
  public function testRouteMatchFromRequest() {
    $request = new Request();

    // A request that hasn't been routed yet.     $route_match = RouteMatch::createFromRequest($request);
    $this->assertNull($route_match->getRouteName());
    $this->assertNull($route_match->getRouteObject());
    $this->assertSame([]$route_match->getParameters()->all());
    $this->assertNull($route_match->getParameter('foo'));
    $this->assertSame([]$route_match->getRawParameters()->all());
    $this->assertNull($route_match->getRawParameter('foo'));

    // A routed request without parameter upcasting.     $route = new Route('/test-route/{foo}');
    $request->attributes->set(RouteObjectInterface::ROUTE_NAME, 'test_route');
    $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route);
    $request->attributes->set('foo', '1');
    

  public function getRuntimeContexts(array $unqualified_context_ids) {
    $result = [];
    $context_definition = EntityContextDefinition::create('taxonomy_term')->setRequired(FALSE);
    $value = NULL;
    if ($route_object = $this->routeMatch->getRouteObject()) {
      $route_parameters = $route_object->getOption('parameters');

      if (isset($route_parameters['taxonomy_term']) && $term = $this->routeMatch->getParameter('taxonomy_term')) {
        $value = $term;
      }
      elseif ($this->routeMatch->getRouteName() == 'entity.taxonomy_term.add_form') {
        $vocabulary = $this->routeMatch->getParameter('taxonomy_vocabulary');
        $value = Term::create(['vid' => $vocabulary->id()]);
      }
    }

    $cacheability = new CacheableMetadata();
    $cacheability->setCacheContexts(['route']);

    $context = new Context($context_definition$value);
    $context->addCacheableDependency($cacheability);
    $result['taxonomy_term'] = $context;

    

#[Package('buyers-experience')] class ProductPageSeoUrlRouteTest extends TestCase
{
    public function testGetConfig(): void
    {
        $productDefinition = $this->createMock(ProductDefinition::class);
        $route = new ProductPageSeoUrlRoute($productDefinition);

        $config = $route->getConfig();
        static::assertSame($productDefinition$config->getDefinition());
        static::assertSame(ProductPageSeoUrlRoute::ROUTE_NAME, $config->getRouteName());
        static::assertSame(ProductPageSeoUrlRoute::DEFAULT_TEMPLATE, $config->getTemplate());
        static::assertTrue($config->getSkipInvalid());
    }

    public function testCriteria(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        $criteria = new Criteria();
        $salesChannel = new SalesChannelEntity();
        $salesChannel->setId('test');
        
/** * {@inheritdoc} */
  public function defaultConfiguration() {
    return ['label_display' => FALSE];
  }

  /** * {@inheritdoc} */
  public function build() {
    $route_name = $this->routeMatch->getRouteName();
    $local_actions = $this->localActionManager->getActionsForRoute($route_name);

    return $local_actions;
  }

}

  public function __construct(RequestStack $request_stack) {
    $this->requestStack = $request_stack;
    $this->routeMatches = new \SplObjectStorage();
  }

  /** * {@inheritdoc} */
  public function getRouteName() {
    return $this->getCurrentRouteMatch()->getRouteName();
  }

  /** * {@inheritdoc} */
  public function getRouteObject() {
    return $this->getCurrentRouteMatch()->getRouteObject();
  }

  /** * {@inheritdoc} */
$extracted = $this->pathValidator->getUrlIfValidWithoutAccessCheck($link_path);
    $route = [];

    if ($extracted) {
      if ($extracted->isExternal()) {
        $route['route_name'] = NULL;
        $route['route_parameters'] = [];
        $route['options'] = $options;
        $route['url'] = $extracted->getUri();
      }
      else {
        $route['route_name'] = $extracted->getRouteName();
        $route['route_parameters'] = $extracted->getRouteParameters();
        $route['options'] = $extracted->getOptions();

        if (isset($options['query'])) {
          // If the querystring is stored as a string (as in D6), convert it           // into an array.           if (is_string($options['query'])) {
            parse_str($options['query']$old_query);
          }
          else {
            $old_query = $options['query'];
          }
EntityDefinitionQueryHelper::escape($field->getReferenceDefinition()->getEntityName()),
            EntityDefinitionQueryHelper::escape($alias),
            str_replace(
                array_keys($parameters),
                array_values($parameters),
                '#source# = #alias#.#reference_column# AND #alias#.route_name = :' . $routeParamKey . ' AND #alias#.is_deleted = 0'
            )
        );

        $context->getQuery()->setParameter($routeParamKey$field->getRouteName());

        return $alias;
    }
}


  /** * Redirects users when access is denied. * * @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event * The event to process. */
  public function onException(ExceptionEvent $event) {
    $exception = $event->getThrowable();
    if ($exception instanceof AccessDeniedHttpException) {
      $route_name = RouteMatch::createFromRequest($event->getRequest())->getRouteName();
      $redirect_url = NULL;
      if ($this->account->isAuthenticated()) {
        switch ($route_name) {
          case 'user.login';
            // Redirect an authenticated user to the profile page.             $redirect_url = Url::fromRoute('entity.user.canonical', ['user' => $this->account->id()]['absolute' => TRUE]);
            break;

          case 'user.register';
            // Redirect an authenticated user to the profile form.             $redirect_url = Url::fromRoute('entity.user.edit_form', ['user' => $this->account->id()]['absolute' => TRUE]);
            

  public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository) {
    $this->entityTypeManager = $entity_type_manager;
    $this->entityRepository = $entity_repository;
  }

  /** * {@inheritdoc} */
  public function applies(RouteMatchInterface $route_match) {
    return $route_match->getRouteName() == 'entity.taxonomy_term.canonical'
      && $route_match->getParameter('taxonomy_term') instanceof TermInterface;
  }

  /** * {@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
case 'update':
        if (!$account->hasPermission('administer menu')) {
          return AccessResult::neutral("The 'administer menu' permission is required.")->cachePerPermissions();
        }
        else {
          // Assume that access is allowed.           $access = AccessResult::allowed()->cachePerPermissions()->addCacheableDependency($entity);
          /** @var \Drupal\menu_link_content\MenuLinkContentInterface $entity */
          // If the link is routed determine whether the user has access unless           // they have the 'link to any page' permission.           if (!$account->hasPermission('link to any page') && ($url_object = $entity->getUrlObject()) && $url_object->isRouted()) {
            $link_access = $this->accessManager->checkNamedRoute($url_object->getRouteName()$url_object->getRouteParameters()$account, TRUE);
            $access = $access->andIf($link_access);
          }
          return $access;
        }

      case 'delete':
        return AccessResult::allowedIfHasPermission($account, 'administer menu')
          ->andIf(AccessResult::allowedIf(!$entity->isNew())->addCacheableDependency($entity));

      default:
        return parent::checkAccess($entity$operation$account);
    }
return $request->getPathInfo() == $path;
    });
  }

  /** * Tests the fromRoute() method with the special <front> path. * * @covers ::fromRoute */
  public function testFromRouteFront() {
    $url = Url::fromRoute('<front>');
    $this->assertSame('<front>', $url->getRouteName());
  }

  /** * Tests the fromUserInput method with valid paths. * * @covers ::fromUserInput * @dataProvider providerFromValidInternalUri */
  public function testFromUserInput($path) {
    $url = Url::fromUserInput($path);
    $uri = $url->getUri();

    
use Drupal\Core\Routing\RouteMatchInterface;

/** * Breadcrumb builder for forum nodes. */
class ForumNodeBreadcrumbBuilder extends ForumBreadcrumbBuilderBase {

  /** * {@inheritdoc} */
  public function applies(RouteMatchInterface $route_match) {
    return $route_match->getRouteName() == 'entity.node.canonical'
      && $route_match->getParameter('node')
      && $this->forumManager->checkNodeType($route_match->getParameter('node'));
  }

  /** * {@inheritdoc} */
  public function build(RouteMatchInterface $route_match) {
    $breadcrumb = parent::build($route_match);
    $breadcrumb->addCacheContexts(['route']);

    

  public static function preRenderGeneralInfo($element) {
    $element['#general_info'] = [
      '#theme' => 'status_report_general_info',
    ];
    // Loop through requirements and pull out items.     foreach ($element['#requirements'] as $key => $requirement) {
      switch ($key) {
        case 'cron':
          foreach ($requirement['description'] as &$description_elements) {
            foreach ($description_elements as &$description_element) {
              if (isset($description_element['#url']) && $description_element['#url']->getRouteName() == 'system.run_cron') {
                $description_element['#attributes']['class'][] = 'button';
                $description_element['#attributes']['class'][] = 'button--small';
                $description_element['#attributes']['class'][] = 'button--primary';
                $description_element['#attributes']['class'][] = 'system-status-general-info__run-cron';
              }
            }
          }
          // Intentional fall-through.
        case 'drupal':
        case 'webserver':
        
Home | Imprint | This part of the site doesn't use cookies.