You are here

protected function Webform::updatePath in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Entity/Webform.php \Drupal\webform\Entity\Webform::updatePath()

Saves a path alias to the database.

Parameters

string $source: The internal system path.

string $alias: The URL alias.

string $langcode: (optional) The language code of the alias.

1 call to Webform::updatePath()
Webform::updatePaths in src/Entity/Webform.php
Update submit and confirm paths (i.e. URL aliases) associated with this webform.

File

src/Entity/Webform.php, line 2471

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

protected function updatePath($source, $alias, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED) {
  $path_alias_storage = \Drupal::entityTypeManager()
    ->getStorage('path_alias');

  // Check if the path alias is already setup.
  $path_aliases = $path_alias_storage
    ->loadByProperties([
    'path' => $source,
    'langcode' => $langcode,
  ]);
  if ($path_aliases) {

    /** @var \Drupal\path_alias\PathAliasInterface $path_alias */
    $path_alias = reset($path_aliases);
    if ($path_alias
      ->getAlias() === $alias) {
      return;
    }
  }
  else {
    $path_alias = $path_alias_storage
      ->create([
      'path' => $source,
      'langcode' => $langcode,
    ]);
  }
  $path_alias
    ->setAlias($alias);
  $path_alias
    ->save();
}