You are here

function amp_form_node_form_alter in Accelerated Mobile Pages (AMP) 8.2

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

Implements hook_form_BASE_FORM_ID_alter().

File

./amp.module, line 306

Code

function amp_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Check if the content is AMP enabled.
  $amp_entity_type_service = \Drupal::service('amp.entity_type');
  $type = $form_state
    ->getFormObject()
    ->getEntity()
    ->bundle();
  if (!$amp_entity_type_service
    ->isAmpEnabledType($type)) {
    return;
  }

  // Add another option to go to the AMP page after saving.
  $form['actions']['save_view_amp'] = array(
    '#type' => 'submit',
    '#value' => t('Save and view AMP page'),
    '#submit' => array(
      '::submitForm',
      '::save',
    ),
    '#access' => TRUE,
    '#dropbutton' => "save",
  );

  // Add another option to go to the AMP page after saving.
  $form['actions']['save_view_amp_with_warn'] = array(
    '#type' => 'submit',
    '#value' => t('Save and view AMP page and see any AMP formatter related warnings'),
    '#submit' => array(
      '::submitForm',
      '::save',
    ),
    '#access' => TRUE,
    '#dropbutton' => "save",
  );

  // Add a submit handler to redirect to the AMP page.
  $form['actions']['save_view_amp']['#submit'][] = 'amp_node_form_submit';
  $form['actions']['save_view_amp_with_warn']['#submit'][] = 'amp_node_form_submit_with_warn';
}