You are here

protected function PathAliasCreate::doExecute in Rules 8.3

Creates an alias for an existing path.

Parameters

string $source: The existing path that should be aliased.

string $alias: The alias path that should be created.

\Drupal\Core\Language\LanguageInterface $language: (optional) The language.

File

src/Plugin/RulesAction/PathAliasCreate.php, line 87

Class

PathAliasCreate
Provides a 'Create any path alias' action.

Namespace

Drupal\rules\Plugin\RulesAction

Code

protected function doExecute($source, $alias, LanguageInterface $language = NULL) {
  $langcode = isset($language) ? $language
    ->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
  $path_alias = $this->aliasStorage
    ->create([
    'path' => $source,
    'alias' => $alias,
    'langcode' => $langcode,
  ]);
  $path_alias
    ->save();
}