getInternalPath example

'title' => 'username profile',
      'menu_name' => 'menu_test',
      'link' => [['uri' => 'entity:user/' . $user->id()]],
      'bundle' => 'menu_test',
    ]);
    $menu_link_content->save();

    // Create "collection" menu link pointing to the user listing page.     $menu_link_content_collection = MenuLinkContent::create([
      'title' => 'users listing',
      'menu_name' => 'menu_test',
      'link' => [['uri' => 'internal:/' . $user->toUrl('collection')->getInternalPath()]],
      'bundle' => 'menu_test',
    ]);
    $menu_link_content_collection->save();

    // Check is menu links present in the menu.     $menu_tree_condition = (new MenuTreeParameters())->addCondition('route_name', 'entity.user.canonical');
    $this->assertCount(1, \Drupal::menuTree()->load('menu_test', $menu_tree_condition));
    $menu_tree_condition_collection = (new MenuTreeParameters())->addCondition('route_name', 'entity.user.collection');
    $this->assertCount(1, \Drupal::menuTree()->load('menu_test', $menu_tree_condition_collection));

    // Delete the user.
/** * Tests the getInternalPath() method. * * @depends testFromUri * @dataProvider providerFromUri * * @covers ::getInternalPath */
  public function testGetInternalPath($uri) {
    $url = Url::fromUri($uri);
    $this->expectException(\Exception::class);
    $url->getInternalPath();
  }

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

  protected function processRoute(Route $route) {
  }

  /** * {@inheritdoc} */
  public function getBasePath() {
    return Url::fromRoute($this->getBaseRouteName()$this->getBaseRouteParameters())->getInternalPath();
  }

  /** * {@inheritdoc} */
  public function getOverviewRouteName() {
    return 'config_translation.item.overview.' . $this->getBaseRouteName();
  }

  /** * {@inheritdoc} */
      // drupal.active-link library know the query in a standardized manner.       if (!empty($variables['options']['query'])) {
        $query = $variables['options']['query'];
        ksort($query);
        $variables['options']['attributes']['data-drupal-link-query'] = Json::encode($query);
      }

      // Add a "data-drupal-link-system-path" attribute to let the       // drupal.active-link library know the path in a standardized manner.       if ($url->isRouted() && !isset($variables['options']['attributes']['data-drupal-link-system-path'])) {
        // @todo System path is deprecated - use the route name and parameters.         $system_path = $url->getInternalPath();

        // Special case for the front page.         if ($url->getRouteName() === '<front>') {
          $system_path = '<front>';
        }

        if (!empty($system_path)) {
          $variables['options']['attributes']['data-drupal-link-system-path'] = $system_path;
        }
      }
    }

    
'title' => 'Testing create()',
      'type' => 'foo',
      'path' => ['alias' => '/foo'],
    ]);
    $this->assertFalse($node->get('path')->isEmpty());
    $this->assertEquals('/foo', $node->get('path')->alias);

    $node->save();
    $this->assertFalse($node->get('path')->isEmpty());
    $this->assertEquals('/foo', $node->get('path')->alias);

    $stored_alias = $alias_repository->lookupBySystemPath('/' . $node->toUrl()->getInternalPath()$node->language()->getId());
    $this->assertEquals('/foo', $stored_alias['alias']);

    $node_storage->resetCache();

    /** @var \Drupal\node\NodeInterface $loaded_node */
    $loaded_node = $node_storage->load($node->id());
    $this->assertFalse($loaded_node->get('path')->isEmpty());
    $this->assertEquals('/foo', $loaded_node->get('path')->alias);
    $node_storage->resetCache();
    $loaded_node = $node_storage->load($node->id());
    $this->assertEquals('/foo', $loaded_node->get('path')[0]->get('alias')->getValue());

    
/** * {@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;
  }

  /** * Gets the current front page path. * * @return string * The front page path. */
  
foreach ($urls as $url) {
      // Clone the URL so that there is no leak of internal state into the       // other ones.       $url = clone $url;
      $url_generator = $this->createMock('Drupal\Core\Routing\UrlGeneratorInterface');
      $url_generator->expects($this->once())
        ->method('getPathFromRoute')
        ->willReturnMap($map);
      $url->setUrlGenerator($url_generator);

      $url->getInternalPath();
      $url->getInternalPath();
    }
  }

  /** * Tests the toString() method. * * @param \Drupal\Core\Url[] $urls * An array of Url objects. * * @depends testUrlFromRequest * * @covers ::toString */
'#default_value' => $items[$delta]->alias,
      '#required' => $element['#required'],
      '#maxlength' => 255,
      '#description' => $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'),
    ];
    $element['pid'] = [
      '#type' => 'value',
      '#value' => $items[$delta]->pid,
    ];
    $element['source'] = [
      '#type' => 'value',
      '#value' => !$entity->isNew() ? '/' . $entity->toUrl()->getInternalPath() : NULL,
    ];
    $element['langcode'] = [
      '#type' => 'value',
      '#value' => $items[$delta]->langcode,
    ];

    // If the advanced settings tabs-set is available (normally rendered in the     // second column on wide-resolutions), place the field as a details element     // in this tab-set.     if (isset($form['advanced'])) {
      $element += [
        
// Default the langcode to the current language if this is a new entity or     // there is no alias for an existent entity.     // @todo Set the langcode to not specified for untranslatable fields     // in https://www.drupal.org/node/2689459.     $value = ['langcode' => $this->getLangcode()];

    $entity = $this->getEntity();
    if (!$entity->isNew()) {
      /** @var \Drupal\path_alias\AliasRepositoryInterface $path_alias_repository */
      $path_alias_repository = \Drupal::service('path_alias.repository');

      if ($path_alias = $path_alias_repository->lookupBySystemPath('/' . $entity->toUrl()->getInternalPath()$this->getLangcode())) {
        $value = [
          'alias' => $path_alias['alias'],
          'pid' => $path_alias['id'],
          'langcode' => $path_alias['langcode'],
        ];
      }
    }

    $this->list[0] = $this->createItem(0, $value);
  }

  
$entity = $this->getEntity();

    // If specified, rely on the langcode property for the language, so that the     // existing language of an alias can be kept. That could for example be     // unspecified even if the field/entity has a specific langcode.     $alias_langcode = ($this->langcode && $this->pid) ? $this->langcode : $this->getLangcode();

    // If we have an alias, we need to create or update a path alias entity.     if ($this->alias) {
      if (!$update || !$this->pid) {
        $path_alias = $path_alias_storage->create([
          'path' => '/' . $entity->toUrl()->getInternalPath(),
          'alias' => $this->alias,
          'langcode' => $alias_langcode,
        ]);
        $path_alias->save();
        $this->pid = $path_alias->id();
      }
      elseif ($this->pid) {
        $path_alias = $path_alias_storage->load($this->pid);

        if ($this->alias != $path_alias->getAlias()) {
          $path_alias->setAlias($this->alias);
          
$this->newUrl = Url::fromRoute($route_name$args$options);
    $this->oldUrl = Url::fromRoute($bc_route_name$args$options);
  }

  /** * Returns the deprecated path. * * @return string * The internal path of the old URL. */
  public function oldPath(): string {
    return $this->oldUrl->getInternalPath();
  }

  /** * Returns the updated path. * * @return string * The internal path of the new URL. */
  public function newPath(): string {
    return $this->newUrl->getInternalPath();
  }

  
// Verify expected breadcrumbs for menu links.     $trail = $home;
    $tree = [];
    // Logout the user because we want to check the active class as well, which     // is just rendered as anonymous user.     $this->drupalLogout();
    foreach ($tags as $name => $data) {
      $term = $data['term'];
      /** @var \Drupal\menu_link_content\MenuLinkContentInterface $link */
      $link = $data['link'];

      $link_path = $link->getUrlObject()->getInternalPath();
      $tree += [
        $link_path => $link->getTitle(),
      ];
      $this->assertBreadcrumb($link_path$trail$term->getName()$tree, TRUE, 'menu__item--active-trail');
      // Ensure that the tagged node is found.       $this->assertSession()->assertEscaped($parent->getTitle());

      // Additionally make sure that this link appears only once; i.e., the       // untranslated menu links automatically generated from menu router items       // ('taxonomy/term/%') should never be translated and appear in any menu       // other than the breadcrumb trail.
Home | Imprint | This part of the site doesn't use cookies.