You are here

function domain_source_form_submit in Domain Access 8

Redirect form submissions to other domains.

1 string reference to 'domain_source_form_submit'
domain_source_form_alter in domain_source/domain_source.module
Implements hook_form_alter().

File

domain_source/domain_source.module, line 185
Domain-based path rewrites for content.

Code

function domain_source_form_submit(&$form, FormStateInterface $form_state) {

  // Ensure that we have saved an entity.
  if ($object = $form_state
    ->getFormObject()) {
    $urlObject = $object
      ->getEntity()
      ->toUrl();
  }

  // Validate that the URL will be considered "external" by Drupal, which means
  // that a scheme value will be present.
  if (!empty($urlObject)) {
    $url = $urlObject
      ->toString();
    $uri_parts = parse_url($url);

    // If necessary and secure, issue a TrustedRedirectResponse to the new URL.
    if (!empty($uri_parts['host'])) {

      // Pass a redirect if necessary.
      if (DomainRedirectResponse::checkTrustedHost($uri_parts['host'])) {
        $response = new TrustedRedirectResponse($url);
        $form_state
          ->setResponse($response);
      }
    }
  }
}