You are here

public function PhotosUploadForm::validateForm in Album Photos 6.0.x

Same name and namespace in other branches
  1. 8.5 src/Form/PhotosUploadForm.php \Drupal\photos\Form\PhotosUploadForm::validateForm()
  2. 8.4 src/Form/PhotosUploadForm.php \Drupal\photos\Form\PhotosUploadForm::validateForm()

Form validation 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 FormBase::validateForm

File

src/Form/PhotosUploadForm.php, line 282

Class

PhotosUploadForm
Defines a form to upload photos to this site.

Namespace

Drupal\photos\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $config = $this
    ->config('photos.settings');
  $album_id = $form_state
    ->getValue('album_id');
  $album_photo_limit = $config
    ->get('album_photo_limit');
  $photo_count = $this->connection
    ->query("SELECT count FROM {photos_album} WHERE album_id = :album_id", [
    ':album_id' => $album_id,
  ])
    ->fetchField();
  if ($album_photo_limit && $photo_count >= $album_photo_limit) {
    $form_state
      ->setErrorByName('new', $this
      ->t('Maximum number of photos reached for this album.'));
  }
}