public function PhotosImageAddForm::validateForm in Album Photos 6.0.x
Button-level validation handlers are highly discouraged for entity forms, as they will prevent entity validation from running. If the entity is going to be saved during the form submission, this method should be manually invoked from the button-level validation handler, otherwise an exception will be thrown.
Overrides ContentEntityForm::validateForm
File
- src/
Form/ PhotosImageAddForm.php, line 111
Class
- PhotosImageAddForm
- Defines a form to edit images.
Namespace
Drupal\photos\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
$album_photo_limit = $this
->config('photos.settings')
->get('album_photo_limit');
if ($album_photo_limit) {
$form_state_values = $form_state
->getValues();
$album_id = $form_state_values['album_id'][0]['target_id'];
$photo_count = $this->connection
->query("SELECT count FROM {photos_album} WHERE album_id = :album_id", [
':album_id' => $album_id,
])
->fetchField();
if ($photo_count >= $album_photo_limit) {
$form_state
->setErrorByName('album_id', $this
->t('Maximum number of photos reached for this album.'));
}
}
}