You are here

function amp_view_modes_submit in Accelerated Mobile Pages (AMP) 8

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

Submit handler for enabling or disabling AMP view modes.

1 string reference to 'amp_view_modes_submit'
amp_form_alter in ./amp.module
Implements hook_form_alter().

File

./amp.module, line 401

Code

function amp_view_modes_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $new_values = array();
  $old_values = array();
  if (isset($form_state
    ->getValues()['display_modes_custom'])) {
    $new_values = array_filter($form_state
      ->getValues()['display_modes_custom']);
  }
  if (isset($form_state
    ->getCompleteForm()['modes']['display_modes_custom']['#default_value'])) {
    $old_values = $form_state
      ->getCompleteForm()['modes']['display_modes_custom']['#default_value'];
  }
  $removed = array_diff($old_values, $new_values);
  $added = array_diff($new_values, $old_values);
  if (is_array($removed) && in_array('amp', $removed) && ($type = $form['#bundle'])) {

    // If the AMP view was removed, clear cache of AMP-enabled content.
    \Drupal::cache()
      ->delete('amp_enabled_types');
    \Drupal::service('cache_tags.invalidator')
      ->invalidateTags([
      'amp_types',
    ]);
  }
  if (is_array($added) && in_array('amp', $added)) {

    // If the AMP view was added, clear cache of AMP-enabled content.
    \Drupal::cache()
      ->delete('amp_enabled_types');
    \Drupal::service('cache_tags.invalidator')
      ->invalidateTags([
      'amp_types',
    ]);
  }
}