You are here

public function GoogleQRCodeAdminForm::validateForm in Google QR Code Generator 8

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/GoogleQRCodeAdminForm.php, line 86

Class

GoogleQRCodeAdminForm

Namespace

Drupal\google_qr_code\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {

  // Check that entered values are numeric.
  if (!is_numeric($form_state
    ->getValue('google_qr_code_height')) || !is_numeric($form_state
    ->getValue('google_qr_code_width'))) {
    $error_text = $this
      ->t('Values entered for height and width must be numeric!');
    $form_state
      ->setErrorByName('google_qr_code_image_settings', $error_text);
  }

  // Check entered pixels VS maximum amount of pixels.
  $total_pixels = $form_state
    ->getValue('google_qr_code_height') * $form_state
    ->getValue('google_qr_code_width');
  if ($total_pixels > 300000) {
    $error_text = $this
      ->t('Total dimensions cannot exceed 300,000px. Currently at @total px', array(
      '@total' => $total_pixels,
    ));
    $form_state
      ->setErrorByName('google_qr_code_image_settings', $error_text);
  }
  parent::validateForm($form, $form_state);

  // TODO: Change the autogenerated stub
}