You are here

public function AuditFilesMergeFileReferences::validateForm in Audit Files 8

Same name and namespace in other branches
  1. 8.3 src/Form/AuditFilesMergeFileReferences.php \Drupal\auditfiles\Form\AuditFilesMergeFileReferences::validateForm()
  2. 8.2 src/Form/AuditFilesMergeFileReferences.php \Drupal\auditfiles\Form\AuditFilesMergeFileReferences::validateForm()
  3. 4.x src/Form/AuditFilesMergeFileReferences.php \Drupal\auditfiles\Form\AuditFilesMergeFileReferences::validateForm()

Form validation.

Overrides FormBase::validateForm

File

src/Form/AuditFilesMergeFileReferences.php, line 282

Class

AuditFilesMergeFileReferences

Namespace

Drupal\auditfiles\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $storage = $form_state
    ->getStorage();
  if (isset($storage['confirm'])) {
    if ($storage['stage'] == 'preconfirm') {
      $counter = 0;
      foreach ($form_state
        ->getValue('files_being_merged') as $file) {
        if (!empty($file)) {
          $counter++;
        }
      }
      if ($counter < 2) {
        $form_state
          ->setErrorByName('files_being_merged', $this
          ->t('At least two file IDs must be selected in order to merge them.'));
      }
    }
  }
}