getRouteParameters example

protected function setupFactoryAndLocalTaskPlugins(array $definitions$active_plugin_id) {
    $map = [];
    $access_manager_map = [];

    foreach ($definitions as $plugin_id => $info) {
      $info += ['access' => AccessResult::allowed()];

      $mock = $this->prophesize(LocalTaskInterface::class);
      $mock->willImplement(CacheableDependencyInterface::class);
      $mock->getRouteName()->willReturn($info['route_name']);
      $mock->getTitle()->willReturn($info['title']);
      $mock->getRouteParameters(Argument::cetera())->willReturn([]);
      $mock->getOptions(Argument::cetera())->willReturn([]);
      $mock->getActive()->willReturn($plugin_id === $active_plugin_id);
      $mock->getWeight()->willReturn($info['weight'] ?? 0);
      $mock->getCacheContexts()->willReturn($info['cache_contexts'] ?? []);
      $mock->getCacheTags()->willReturn($info['cache_tags'] ?? []);
      $mock->getCacheMaxAge()->willReturn($info['cache_max_age'] ?? Cache::PERMANENT);

      $access_manager_map[] = [$info['route_name'][]$this->account, TRUE, $info['access']];

      $map[] = [$info['id'][]$mock->reveal()];
    }

    
if (!$salesChannelContext->getSalesChannel()->isHreflangActive()) {
            return new HreflangCollection();
        }

        $domains = $this->fetchSalesChannelDomains($salesChannelContext->getSalesChannel()->getId());

        if ($parameter->getRoute() === 'frontend.home.page') {
            return $this->getHreflangForHomepage($domains$salesChannelContext->getSalesChannel()->getHreflangDefaultDomainId());
        }

        $pathInfo = $this->router->generate($parameter->getRoute()$parameter->getRouteParameters(), RouterInterface::ABSOLUTE_PATH);

        $languageToDomainMapping = $this->getLanguageToDomainMapping($domains);
        $seoUrls = $this->fetchSeoUrls($pathInfo$salesChannelContext->getSalesChannel()->getId()array_keys($languageToDomainMapping));

        // We need at least two links         if (\count($seoUrls) <= 1) {
            return new HreflangCollection();
        }

        $hreflangCollection = new HreflangCollection();

        
$field->field_alias = 'key';
    $row = new ResultRow(['key' => 'value']);

    $expected_url->setOptions($expected_url->getOptions() + static::DEFAULT_URL_OPTIONS);
    $expected_link_url->setUrlGenerator($this->urlGenerator);

    $expected_url_options = $expected_url->getOptions();
    unset($expected_url_options['attributes']);

    $this->urlGenerator->expects($this->once())
      ->method('generateFromRoute')
      ->with($expected_url->getRouteName()$expected_url->getRouteParameters()$expected_url_options, TRUE)
      ->willReturn((new GeneratedUrl())->setGeneratedUrl($url_path));

    $result = $field->advancedRender($row);
    $this->assertEquals($final_html$result);
  }

  /** * Data provider for ::testRenderAsLinkWithUrlAndOptions(). * * @return array * Array of test data. */
/** * Tests the getRouteParameters() method. * * @depends testFromUri * @dataProvider providerFromUri * * @covers ::getRouteParameters */
  public function testGetRouteParameters($uri) {
    $url = Url::fromUri($uri);
    $this->expectException(\UnexpectedValueException::class);
    $url->getRouteParameters();
  }

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


  /** * {@inheritdoc} */
  public function getUrlObject($title_attribute = TRUE) {
    $options = $this->getOptions();
    if ($title_attribute && $description = $this->getDescription()) {
      $options['attributes']['title'] = $description;
    }
    if (empty($this->pluginDefinition['url'])) {
      return new Url($this->getRouteName()$this->getRouteParameters()$options);
    }
    else {
      return Url::fromUri($this->pluginDefinition['url']$options);
    }
  }

  /** * {@inheritdoc} */
  public function getFormClass() {
    return $this->pluginDefinition['form_class'];
  }
->method('match')
      ->with('/test-path')
      ->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new InputBag(['key' => 'value'])]);
    $this->pathProcessor->expects($this->exactly(2))
      ->method('processInbound')
      ->willReturnArgument(0);

    $url = $this->pathValidator->getUrlIfValid('test-path');
    $this->assertInstanceOf('Drupal\Core\Url', $url);

    $this->assertEquals('test_route', $url->getRouteName());
    $this->assertEquals(['key' => 'value']$url->getRouteParameters());

    // Test with leading /.     $url = $this->pathValidator->getUrlIfValid('/test-path');
    $this->assertInstanceOf('Drupal\Core\Url', $url);

    $this->assertEquals('test_route', $url->getRouteName());
    $this->assertEquals(['key' => 'value']$url->getRouteParameters());
  }

  /** * Tests the getUrlIfValid() method with a query in the path. * * @covers ::getUrlIfValid */
/** * {@inheritdoc} */
  public function getStorageId() {
    return $this->getDisplay()->id();
  }

  /** * {@inheritdoc} */
  public function getRedirectUrl() {
    return Url::fromRoute("entity.entity_view_display.{$this->getDisplay()->getTargetEntityTypeId()}.view_mode", $this->getRouteParameters());
  }

  /** * {@inheritdoc} */
  public function getLayoutBuilderUrl($rel = 'view') {
    return Url::fromRoute("layout_builder.{$this->getStorageType()}.{$this->getDisplay()->getTargetEntityTypeId()}.$rel", $this->getRouteParameters());
  }

  /** * Provides the route parameters needed to generate a URL for this object. * * @return mixed[] * An associative array of parameter names and values. */

    $form_builder = $this->container->get('form_builder');
    $form_builder->submitForm($this$form_state);

    // Valid form state.     $this->assertCount(0, $form_state->getErrors());
    $this->assertEquals(['route_name' => 'entity.user.canonical', 'route_parameters' => ['user' => $this->testUser->id()]]$form_state->getValue('required_validate_route'));
    /** @var \Drupal\Core\Url $url */
    $url = $form_state->getValue('required_validate_url');
    $this->assertInstanceOf(Url::class$url);
    $this->assertEquals('entity.user.canonical', $url->getRouteName());
    $this->assertEquals(['user' => $this->testUser->id()]$url->getRouteParameters());
    $this->assertEquals($form_state->getValue('optional_validate_route')[
      'route_name' => 'entity.user.canonical',
      'route_parameters' => [
        'user' => $this->testUser->id(),
      ],
    ]);

    // Test #required.     $form_state = (new FormState())
      ->setValues([
        'required_non_validate' => 'magic-ponies',
        

  public function testGetRouteParameters($urls) {
    foreach ($urls as $index => $url) {
      $this->assertSame($this->map[$index][1]$url->getRouteParameters());
    }
  }

  /** * Tests the getRouteParameters() with an external URL. * * @covers ::getRouteParameters */
  public function testGetRouteParametersWithExternalUrl() {
    $url = Url::fromUri('http://example.com');
    $this->expectException(\UnexpectedValueException::class);
    

    // Pre-fetch all routes involved in the tree. This reduces the number     // of SQL queries that would otherwise be triggered by the access manager.     if ($route_names) {
      $this->routeProvider->getRoutesByNames($route_names);
    }

    foreach ($tree as $level => $instances) {
      /** @var \Drupal\Core\Menu\LocalTaskInterface[] $instances */
      foreach ($instances as $plugin_id => $child) {
        $route_name = $child->getRouteName();
        $route_parameters = $child->getRouteParameters($this->routeMatch);

        // Given that the active flag depends on the route we have to add the         // route cache context.         $cacheability->addCacheContexts(['route']);
        $active = $this->isRouteActive($current_route_name$route_name$route_parameters);

        // The plugin may have been set active in getLocalTasksForRoute() if         // one of its child tabs is the active tab.         $active = $active || $child->getActive();
        // @todo It might make sense to use link render elements instead.
        
/** * Collects the node links in the menu tree. * * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree * The menu link tree to manipulate. * @param array $node_links * Stores references to menu link elements to effectively set access. */
  protected function collectNodeLinks(array &$tree, array &$node_links) {
    foreach ($tree as $key => &$element) {
      if ($element->link->getRouteName() == 'entity.node.canonical') {
        $nid = $element->link->getRouteParameters()['node'];
        $node_links[$nid][$key] = $element;
        // Deny access by default. checkNodeAccess() will re-add it.         $element->access = AccessResult::neutral();
      }
      if ($element->hasChildren) {
        $this->collectNodeLinks($element->subtree, $node_links);
      }
    }
  }

  /** * 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. */
$definition['menu_name'] = $this->getMenuName();

    if ($url_object = $this->getUrlObject()) {
      $definition['url'] = NULL;
      $definition['route_name'] = NULL;
      $definition['route_parameters'] = [];
      if (!$url_object->isRouted()) {
        $definition['url'] = $url_object->getUri();
      }
      else {
        $definition['route_name'] = $url_object->getRouteName();
        $definition['route_parameters'] = $url_object->getRouteParameters();
      }
      $definition['options'] = $url_object->getOptions();
    }

    $definition['title'] = $this->getTitle();
    $definition['description'] = $this->getDescription();
    $definition['weight'] = $this->getWeight();
    $definition['id'] = $this->getPluginId();
    $definition['metadata'] = ['entity_id' => $this->id()];
    $definition['form_class'] = '\Drupal\menu_link_content\Form\MenuLinkContentForm';
    $definition['enabled'] = $this->isEnabled() ? 1 : 0;
    
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);
    }
if ($entity->isNew()) {
      return;
    }
    $key = $entity->getEntityTypeId();
    $rel = 'canonical';
    if ($entity instanceof ContentEntityInterface && !$entity->isDefaultRevision()) {
      $rel = 'revision';
      $key .= '_revision';
    }
    if ($entity->hasLinkTemplate($rel) && $entity->toUrl($rel)->isRouted()) {
      $build['#contextual_links'][$key] = [
        'route_parameters' => $entity->toUrl($rel)->getRouteParameters(),
      ];
      if ($entity instanceof EntityChangedInterface) {
        $build['#contextual_links'][$key]['metadata'] = [
          'changed' => $entity->getChangedTime(),
        ];
      }
    }
  }

  /** * Specific per-entity building. * * @param array $build * The render array that is being created. * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to be prepared. * @param \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display * The entity view display holding the display options configured for the * entity components. * @param string $view_mode * The view mode that should be used to prepare the entity. */
return 'route:<nolink>';
      }
      $path = 'internal:/' . $path;

      // Convert entity URIs to the entity scheme, if the path matches a route       // of the form "entity.$entity_type_id.canonical".       // @see \Drupal\Core\Url::fromEntityUri()       $url = Url::fromUri($path);
      if ($url->isRouted()) {
        $route_name = $url->getRouteName();
        foreach (array_keys($this->entityTypeManager->getDefinitions()) as $entity_type_id) {
          if ($route_name == "entity.$entity_type_id.canonical" && isset($url->getRouteParameters()[$entity_type_id])) {
            return "entity:$entity_type_id/" . $url->getRouteParameters()[$entity_type_id];
          }
        }
      }
      else {
        // If the URL is not routed, we might want to get something back to do         // other processing. If this is the case, the "validate_route"         // configuration option can be set to FALSE to return the URI.         if (!$this->configuration['validate_route']) {
          return $url->getUri();
        }
        
Home | Imprint | This part of the site doesn't use cookies.