function PathAliasTestTrait::createPathAlias

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::createPathAlias()
  2. 8.9.x core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::createPathAlias()
  3. 11.x core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php \Drupal\Tests\Traits\Core\PathAliasTestTrait::createPathAlias()

Creates a new path alias.

Parameters

string $path: The system path.

string $alias: The alias for the system path.

string $langcode: (optional) A language code for the path alias. Defaults to \Drupal\Core\Language\LanguageInterface::LANGCODE_NOT_SPECIFIED.

Return value

\Drupal\path_alias\PathAliasInterface A path alias entity.

20 calls to PathAliasTestTrait::createPathAlias()
AliasTest::testLookupByAlias in core/modules/path_alias/tests/src/Kernel/AliasTest.php
@covers ::lookupByAlias
AliasTest::testLookupBySystemPath in core/modules/path_alias/tests/src/Kernel/AliasTest.php
@covers ::lookupBySystemPath
AliasTest::testLookupPath in core/modules/path_alias/tests/src/Kernel/AliasTest.php
@covers \Drupal\path_alias\AliasManager::getPathByAlias @covers \Drupal\path_alias\AliasManager::getAliasByPath
AliasTest::testPreloadPathAlias in core/modules/path_alias/tests/src/Kernel/AliasTest.php
@covers ::preloadPathAlias
AliasTest::testWhitelist in core/modules/path_alias/tests/src/Kernel/AliasTest.php
Tests the alias whitelist.

... See full list

File

core/tests/Drupal/Tests/Traits/Core/PathAliasTestTrait.php, line 30

Class

PathAliasTestTrait
Provides methods to create and assert path_alias entities.

Namespace

Drupal\Tests\Traits\Core

Code

protected function createPathAlias($path, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
    
    /** @var \Drupal\path_alias\PathAliasInterface $path_alias */
    $path_alias = \Drupal::entityTypeManager()->getStorage('path_alias')
        ->create([
        'path' => $path,
        'alias' => $alias,
        'langcode' => $langcode,
    ]);
    $path_alias->save();
    return $path_alias;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.