You are here

public function Webform::deletePaths in Webform 8.5

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

Update submit and confirm paths associated with this webform.

Overrides WebformInterface::deletePaths

1 call to Webform::deletePaths()
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 2441

Class

Webform
Defines the webform entity.

Namespace

Drupal\webform\Entity

Code

public function deletePaths() {

  // Path module must be enabled for URL aliases to be updated.
  if (!\Drupal::moduleHandler()
    ->moduleExists('path')) {
    return;
  }
  $path_alias_storage = \Drupal::entityTypeManager()
    ->getStorage('path_alias');
  $query = $path_alias_storage
    ->getQuery('OR');

  // Delete webform base, confirmation, submissions and drafts paths.
  $path_suffixes = [
    '',
    '/confirmation',
    '/submissions',
    '/drafts',
  ];
  foreach ($path_suffixes as $path_suffix) {
    $query
      ->condition('path', '/webform/' . $this
      ->id() . $path_suffix);
  }
  if ($ids = $query
    ->execute()) {
    $path_alias_storage
      ->delete($path_alias_storage
      ->loadMultiple($ids));
  }
}