You are here

function amp_view_modes_submit in Accelerated Mobile Pages (AMP) 7

Same name and namespace in other branches
  1. 8.3 amp.module \amp_view_modes_submit()
  2. 8 amp.module \amp_view_modes_submit()
  3. 8.2 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 570

Code

function amp_view_modes_submit(&$form, $form_state) {
  $new_values = array();
  $old_values = array();
  if (isset($form_state['values']['view_modes_custom'])) {
    $new_values = array_filter($form_state['values']['view_modes_custom']);
  }
  if (isset($form_state['complete form']['modes']['view_modes_custom']['#default_value'])) {
    $old_values = $form_state['complete form']['modes']['view_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)) {

    // If the AMP view was removed, clear cache of AMP-enabled content.
    cache_clear_all('amp_enabled_types', 'cache');
  }
  if (is_array($added) && in_array('amp', $added)) {

    // If the AMP view was added, clear cache of AMP-enabled content.
    cache_clear_all('amp_enabled_types', 'cache');
  }
}