You are here

public function FileActionForm::validateForm in Ubercart 8.4

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

uc_file/src/Form/FileActionForm.php, line 120

Class

FileActionForm
Form builder for file products admin.

Namespace

Drupal\uc_file\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  switch ($form_state
    ->getValue('action')) {
    case 'uc_file_delete':
      $file_ids = [];
      if (is_array($form_state
        ->getValue('file_select'))) {
        foreach ($form_state
          ->getValue('file_select') as $fid => $value) {
          if ($value) {
            $file_ids[] = $fid;
          }
        }
      }
      if (count($file_ids) == 0) {
        $form_state
          ->setErrorByName('', $this
          ->t('You must select at least one file to delete.'));
      }
      break;
    case 'uc_file_upload':

      // Nothing to do in this case.
      break;
    default:

      // @todo Deal with validating hook-provided actions.
      break;
  }
}