You are here

protected function WebformSubmissionForm::getConfirmationUrl in Webform 6.x

Get the webform's confrmation URL.

Return value

\Drupal\Core\Url|false The url object, or FALSE if the path is not valid.

See also

\Drupal\Core\Path\PathValidatorInterface::getUrlIfValid

1 call to WebformSubmissionForm::getConfirmationUrl()
WebformSubmissionForm::setConfirmation in src/WebformSubmissionForm.php
Set webform state confirmation redirect and message.

File

src/WebformSubmissionForm.php, line 2404

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function getConfirmationUrl() {
  $confirmation_url = trim($this
    ->getWebformSetting('confirmation_url', ''));
  if (strpos($confirmation_url, '/') === 0) {

    // Get redirect URL using an absolute URL for the absolute  path.
    $redirect_url = Url::fromUri($this
      ->getRequest()
      ->getSchemeAndHttpHost() . $confirmation_url);
  }
  elseif (preg_match('#^[a-z]+(?:://|:)#', $confirmation_url)) {

    // Get redirect URL from URI (i.e. http://, https:// or ftp://)
    // and Drupal custom URIs (i.e internal:).
    $redirect_url = Url::fromUri($confirmation_url);
  }
  elseif (strpos($confirmation_url, '<') === 0) {

    // Get redirect URL from special paths: '<front>' and '<none>'.
    $redirect_url = $this->pathValidator
      ->getUrlIfValid($confirmation_url);
  }
  else {

    // Get redirect URL by validating the Drupal relative path which does not
    // begin with a forward slash (/).
    $confirmation_url = $this->aliasManager
      ->getPathByAlias('/' . $confirmation_url);
    $redirect_url = $this->pathValidator
      ->getUrlIfValid($confirmation_url);
  }

  // If redirect url is FALSE, display and log a warning.
  if (!$redirect_url) {
    $webform = $this
      ->getWebform();
    $t_args = [
      '@webform' => $webform
        ->label(),
      '%url' => $this
        ->getWebformSetting('confirmation_url'),
    ];

    // Display warning to use who can update the webform.
    if ($webform
      ->access('update')) {
      $this
        ->messenger()
        ->addWarning($this
        ->t('Confirmation URL %url is not valid.', $t_args));
    }

    // Log warning.
    $this
      ->getLogger('webform')
      ->warning('@webform: Confirmation URL %url is not valid.', $t_args);
  }
  return $redirect_url;
}