You are here

public function Webform::updatePaths in Webform 6.x

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

Update submit and confirm paths (i.e. URL aliases) associated with this webform.

Overrides WebformInterface::updatePaths

1 call to Webform::updatePaths()
Webform::postSave in src/Entity/Webform.php
Acts on a saved entity before the insert or update hook is invoked.

File

src/Entity/Webform.php, line 2404

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function updatePaths() {

  // Path module must be enabled for URL aliases to be updated.
  if (!\Drupal::moduleHandler()
    ->moduleExists('path')) {
    return;
  }

  // If 'Allow users to post submission from a dedicated URL' is disabled,
  // delete all existing paths.
  if (empty($this
    ->getSetting('page'))) {
    $this
      ->deletePaths();
    return;
  }
  $page_submit_path = $this
    ->getSetting('page_submit_path');
  $default_page_base_path = \Drupal::config('webform.settings')
    ->get('settings.default_page_base_path');

  // Skip generating paths if submit path and base path are empty.
  if (empty($page_submit_path) && empty($default_page_base_path)) {
    return;
  }

  // Update webform base, confirmation, submissions and drafts paths.
  $path_base_alias = $page_submit_path ?: $default_page_base_path . '/' . str_replace('_', '-', $this
    ->id());
  $path_suffixes = [
    '',
    '/confirmation',
    '/submissions',
    '/drafts',
  ];
  foreach ($path_suffixes as $path_suffix) {
    $path_source = '/webform/' . $this
      ->id() . $path_suffix;
    $path_alias = $path_base_alias . $path_suffix;
    if ($path_suffix === '/confirmation' && $this
      ->getSetting('page_confirm_path')) {
      $path_alias = $this
        ->getSetting('page_confirm_path');
    }
    $this
      ->updatePath($path_source, $path_alias, $this->langcode);
    $this
      ->updatePath($path_source, $path_alias, LanguageInterface::LANGCODE_NOT_SPECIFIED);
  }
}