function FileExampleSubmitHandlerHelper::handleDirectoryExists

Submit handler to test directory existence.

This actually just checks to see if the directory is writable.

Parameters

array $form: FormAPI form.

\Drupal\Core\Form\FormStateInterface $form_state: FormAPI form state.

File

modules/file_example/src/FileExampleSubmitHandlerHelper.php, line 442

Class

FileExampleSubmitHandlerHelper
A submit handler helper class for the file_example module.

Namespace

Drupal\file_example

Code

public function handleDirectoryExists(array &$form, FormStateInterface $form_state) {
    $form_values = $form_state->getValues();
    $directory = $form_values['directory_name'];
    $result = is_dir($directory);
    if (!$result) {
        $this->messenger
            ->addMessage($this->t('Directory %directory does not exist.', [
            '%directory' => $directory,
        ]));
    }
    else {
        $this->messenger
            ->addMessage($this->t('Directory %directory exists.', [
            '%directory' => $directory,
        ]));
    }
}