You are here

public function ActionForm::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/ActionForm.php, line 200

Class

ActionForm
Performs file action (upload, delete, hooked in actions).

Namespace

Drupal\uc_file\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  switch ($form_state
    ->getValue('action')) {
    case 'uc_file_upload':

      // Upload the file and get its object.
      if ($temp_file = file_save_upload('upload', [
        'file_validate_extensions' => [],
      ])) {

        // Check if any hook_uc_file_action('upload_validate', $args)
        // are implemented.
        foreach ($this->moduleHandler
          ->getImplementations('uc_file_action') as $module) {
          $name = $module . '_uc_file_action';
          $name('upload_validate', [
            'file_object' => $temp_file,
            'form_id' => $form_id,
            'form_state' => $form_state,
          ]);
        }

        // Save the uploaded file for later processing.
        $form_state
          ->set('temp_file', $temp_file);
      }
      else {
        $form_state
          ->setErrorByName('', $this
          ->t('An error occurred while uploading the file'));
      }
      break;
    default:

      // This action isn't handled by us, so check if any
      // hook_uc_file_action('validate', $args) are implemented.
      foreach ($this->moduleHandler
        ->getImplementations('uc_file_action') as $module) {
        $name = $module . '_uc_file_action';
        $name('validate', [
          'form_id' => $form_id,
          'form_state' => $form_state,
        ]);
      }
      break;
  }
}