You are here

public function InvoiceTypeForm::validateForm in Commerce Invoice 8.2

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

src/Form/InvoiceTypeForm.php, line 196

Class

InvoiceTypeForm
Provides an invoice type form.

Namespace

Drupal\commerce_invoice\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $this
    ->validateTraitForm($form, $form_state);

  /** @var \Drupal\commerce_invoice\Entity\InvoiceTypeInterface $invoice_type */
  $invoice_type = $this->entity;
  $logo_file = $form_state
    ->getValue([
    'logo_file',
    '0',
  ]);

  /** @var \Drupal\file\Entity\File $file */
  if (!empty($logo_file) && ($file = $this->entityTypeManager
    ->getStorage('file')
    ->load($logo_file))) {
    $file
      ->setPermanent();
    $file
      ->save();
    $invoice_type
      ->setLogo($file
      ->uuid());
  }
  else {
    $invoice_type
      ->setLogo(NULL);
  }
}