You are here

public function SettingsForm::validateForm in Forward 8

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::validateForm()
  2. 8.2 src/Form/SettingsForm.php \Drupal\forward\Form\SettingsForm::validateForm()

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/SettingsForm.php, line 412

Class

SettingsForm
Configure settings for this module.

Namespace

Drupal\forward\Form

Code

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

  // Validate link icon path if provided
  if ($form_state
    ->getValue('forward_link_icon')) {
    $image = File::create();
    $image
      ->setFileUri($form_state
      ->getValue('forward_link_icon'));
    $image
      ->setFilename($this->fileSystem
      ->basename($image
      ->getFileUri()));
    $errors = file_validate_is_image($image);
    if (count($errors)) {
      $form_state
        ->setErrorByName('forward_link_icon', $this
        ->t("The link icon path '@path' is invalid.", array(
        '@path' => $form_state
          ->getValue('forward_link_icon'),
      )));
    }
  }
  parent::validateForm($form, $form_state);
}