You are here

public function PhotosAdminSettingsForm::submitForm in Album Photos 8.5

Same name and namespace in other branches
  1. 8.4 src/Form/PhotosAdminSettingsForm.php \Drupal\photos\Form\PhotosAdminSettingsForm::submitForm()
  2. 6.0.x src/Form/PhotosAdminSettingsForm.php \Drupal\photos\Form\PhotosAdminSettingsForm::submitForm()

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ConfigFormBase::submitForm

File

src/Form/PhotosAdminSettingsForm.php, line 667

Class

PhotosAdminSettingsForm
Defines a form to configure maintenance settings for this site.

Namespace

Drupal\photos\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  parent::submitForm($form, $form_state);

  // Build $photos_size array.
  $size = [];
  for ($i = 0; $i < $form_state
    ->getValue('photos_thumb_count'); $i++) {
    if ($form_state
      ->getValue('photos_size_' . $i)) {
      $size[$form_state
        ->getValue('photos_size_' . $i)] = $form_state
        ->getValue('photos_name_' . $i);
    }
  }
  $photos_size = $size;

  // Set number of albums per role.
  $num = $form_state
    ->getValue('num');
  foreach ($num as $rnum => $rcount) {
    $this
      ->config('photos.settings')
      ->set($rnum, $rcount);
  }

  // Check current legacy setting and clear cache if changed.
  $currentLegacySetting = $this
    ->config('photos.settings')
    ->get('photos_legacy_view_mode');

  // Check current album photos image list view.
  $currentImageListView = $this
    ->config('photos.settings')
    ->get('node_field_album_photos_list_view');
  $this
    ->config('photos.settings')
    ->set('album_link_override', $form_state
    ->getValue('album_link_override'))
    ->set('multi_upload_default_field', $form_state
    ->getValue('multi_upload_default_field'))
    ->set('node_field_album_photos_list_view', $form_state
    ->getValue('node_field_album_photos_list_view'))
    ->set('photos_additional_sizes', $form_state
    ->getValue('photos_additional_sizes'))
    ->set('photos_album_column_count', $form_state
    ->getValue('photos_album_column_count'))
    ->set('photos_album_display_type', $form_state
    ->getValue('photos_album_display_type'))
    ->set('photos_cover_imagesize', $form_state
    ->getValue('photos_cover_imagesize'))
    ->set('photos_display_colorbox_max_height', $form_state
    ->getValue('photos_display_colorbox_max_height'))
    ->set('photos_display_colorbox_max_width', $form_state
    ->getValue('photos_display_colorbox_max_width'))
    ->set('photos_display_full_imagesize', $form_state
    ->getValue('photos_display_full_imagesize'))
    ->set('photos_display_full_viewnum', $form_state
    ->getValue('photos_display_full_viewnum'))
    ->set('photos_display_imageorder', $form_state
    ->getValue('photos_display_imageorder'))
    ->set('photos_display_list_imagesize', $form_state
    ->getValue('photos_display_list_imagesize'))
    ->set('photos_display_page_display', $form_state
    ->getValue('photos_display_page_display'))
    ->set('photos_display_page_user', $form_state
    ->getValue('photos_display_page_user'))
    ->set('photos_display_teaser_display', $form_state
    ->getValue('photos_display_teaser_display'))
    ->set('photos_display_teaser_imagesize', $form_state
    ->getValue('photos_display_teaser_imagesize'))
    ->set('photos_display_teaser_user', $form_state
    ->getValue('photos_display_teaser_user'))
    ->set('photos_display_teaser_viewnum', $form_state
    ->getValue('photos_display_teaser_viewnum'))
    ->set('photos_display_user', $form_state
    ->getValue('photos_display_user'))
    ->set('photos_display_view_imagesize', $form_state
    ->getValue('photos_display_view_imagesize'))
    ->set('photos_display_viewpager', $form_state
    ->getValue('photos_display_viewpager'))
    ->set('photos_image_count', $form_state
    ->getValue('photos_image_count'))
    ->set('photos_legacy_view_mode', $form_state
    ->getValue('photos_legacy_view_mode'))
    ->set('photos_num', $form_state
    ->getValue('photos_num'))
    ->set('photos_pager_imagesize', $form_state
    ->getValue('photos_pager_imagesize'))
    ->set('photos_plupload_status', $form_state
    ->getValue('photos_plupload_status'))
    ->set('photos_size', $photos_size)
    ->set('photos_size_max', $form_state
    ->getValue('photos_size_max'))
    ->set('photos_clean_title', $form_state
    ->getValue('photos_clean_title'))
    ->set('photos_upzip', $form_state
    ->getValue('photos_upzip'))
    ->set('photos_user_count_cron', $form_state
    ->getValue('photos_user_count_cron'))
    ->set('user_albums_link_override', $form_state
    ->getValue('user_albums_link_override'))
    ->set('user_images_link_override', $form_state
    ->getValue('user_images_link_override'))
    ->save();
  if ($currentLegacySetting != $form_state
    ->getValue('photos_legacy_view_mode')) {
    $this->messenger
      ->addMessage($this
      ->t('Cache cleared.'));
    drupal_flush_all_caches();
  }
  if ($currentImageListView != $form_state
    ->getValue('node_field_album_photos_list_view')) {
    $this->messenger
      ->addMessage($this
      ->t('Views node_list and photos_image_list cache cleared.'));

    // Clear views cache.
    Cache::invalidateTags([
      'node_list',
      'photos_image_list',
    ]);
  }
}