getPathFromRoute example

/** * {@inheritdoc} */
  public function getContext(): SymfonyRequestContext {
    return $this->urlGenerator->getContext();
  }

  /** * {@inheritdoc} */
  public function getPathFromRoute($name$parameters = []) {
    return $this->urlGenerator->getPathFromRoute($name$parameters);
  }

  /** * Bubbles the bubbleable metadata to the current render context. * * @param \Drupal\Core\GeneratedUrl $generated_url * The generated URL whose bubbleable metadata to bubble. * @param array $options * (optional) The URL options. Defaults to none. */
  protected function bubble(GeneratedUrl $generated_url, array $options = []) {
    

  public function getInternalPath() {
    if ($this->unrouted) {
      throw new \UnexpectedValueException('Unrouted URIs do not have internal representations.');
    }

    if (!isset($this->internalPath)) {
      $this->internalPath = $this->urlGenerator()->getPathFromRoute($this->getRouteName()$this->getRouteParameters());
    }
    return $this->internalPath;
  }

  /** * Checks this Url object against applicable access check services. * * Determines whether the route is accessible or not. * * @param \Drupal\Core\Session\AccountInterface|null $account * (optional) Run access checks for this account. NULL for the current user. * @param bool $return_as_object * (optional) Defaults to FALSE. * * @return bool|\Drupal\Core\Access\AccessResultInterface * The access result. Returns a boolean if $return_as_object is FALSE (this * is the default) and otherwise an AccessResultInterface object. * When a boolean is returned, the result of AccessInterface::isAllowed() is * returned, i.e. TRUE means access is explicitly allowed, FALSE means * access is either explicitly forbidden or "no opinion". */
$this->assertEquals('/hello/world', $url);
    // No cacheability to test; UrlGenerator::generate() doesn't support     // collecting cacheability metadata.
    $this->routeProcessorManager->expects($this->exactly(3))
      ->method('processOutbound')
      ->with($this->anything());

    // Check that the two generate methods return the same result.     $this->assertGenerateFromRoute('test_1', [][]$url(new BubbleableMetadata())->setCacheMaxAge(Cache::PERMANENT));

    $path = $this->generator->getPathFromRoute('test_1');
    $this->assertEquals('test/one', $path);
  }

  /** * Confirms that generated routes will have aliased paths using interface constants. */
  public function testAliasGenerationUsingInterfaceConstants() {
    $url = $this->generator->generate('test_1', [], UrlGenerator::ABSOLUTE_PATH);
    $this->assertEquals('/hello/world', $url);
    // No cacheability to test; UrlGenerator::generate() doesn't support     // collecting cacheability metadata.
Home | Imprint | This part of the site doesn't use cookies.