You are here

public function SettingsForm::validateForm in Imagecache External 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/SettingsForm.php, line 160

Class

SettingsForm
Defines a form that configures uploadcare settings.

Namespace

Drupal\imagecache_external\Form

Code

public function validateForm(array &$form, FormStateInterface $form_state) {
  $scheme = $this->configFactory
    ->get('system.file')
    ->get('default_scheme');
  $directory = $scheme . '://' . $form_state
    ->getValue('imagecache_directory');
  if (!$this->fileSystem
    ->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY)) {
    $error = $this
      ->t('The directory %directory does not exist or is not writable.', [
      '%directory' => $directory,
    ]);
    $form_state
      ->setErrorByName('imagecache_directory', $error);
    $this
      ->logger('imagecache_external')
      ->error($error);
  }
}