public function PictureMappingFormController::validate

Overrides Drupal\Core\Entity\EntityFormController::validate().

Overrides EntityFormController::validate

File

drupal/core/modules/picture/lib/Drupal/picture/PictureMappingFormController.php, line 106
Contains Drupal\picture\PictureFormController.

Class

PictureMappingFormController
Form controller for the picture edit/add forms.

Namespace

Drupal\picture

Code

public function validate(array $form, array &$form_state) {
  $picture_mapping = $this
    ->getEntity($form_state);

  // Only validate on edit.
  if (isset($form_state['values']['mappings'])) {
    $picture_mapping->mappings = $form_state['values']['mappings'];

    // Check if another breakpoint group is selected.
    if ($form_state['values']['breakpointGroup'] != $form_state['complete_form']['breakpointGroup']['#default_value']) {

      // Remove the mappings.
      unset($form_state['values']['mappings']);
    }
    elseif (!$picture_mapping
      ->isNew() && !$picture_mapping
      ->hasMappings()) {
      form_set_error('mappings', t('Please select at least one mapping.'));
    }
  }
}