You are here

function amp_node_form_submit in Accelerated Mobile Pages (AMP) 8

Same name and namespace in other branches
  1. 8.3 amp.module \amp_node_form_submit()
  2. 8.2 amp.module \amp_node_form_submit()
  3. 7 amp.module \amp_node_form_submit()

Submit handler for viewing the AMP page.

1 string reference to 'amp_node_form_submit'
amp_form_node_form_alter in ./amp.module
Implements hook_form_BASE_FORM_ID_alter().

File

./amp.module, line 363

Code

function amp_node_form_submit(&$form, FormStateInterface $form_state) {
  $path = $form_state
    ->getValue('path');

  // Redirect to the alias if it exists, otherwise use the node URL.
  $url = !empty($path[0]['alias']) ? $path[0]['alias'] : $path[0]['source'];
  if (isset($url)) {
    $amp_url = \Drupal::service('amp.query_parameters')
      ->add($url);
    $response = new RedirectResponse($amp_url);
    $response
      ->send();
  }
}