You are here

public function Oauth2TokenSettingsForm::validateExistingFile in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.4 src/Entity/Form/Oauth2TokenSettingsForm.php \Drupal\simple_oauth\Entity\Form\Oauth2TokenSettingsForm::validateExistingFile()
  2. 8.2 src/Entity/Form/Oauth2TokenSettingsForm.php \Drupal\simple_oauth\Entity\Form\Oauth2TokenSettingsForm::validateExistingFile()
  3. 5.x src/Entity/Form/Oauth2TokenSettingsForm.php \Drupal\simple_oauth\Entity\Form\Oauth2TokenSettingsForm::validateExistingFile()

Validates if the file exists.

Parameters

array $element: The element being processed.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

array $complete_form: The complete form structure.

File

src/Entity/Form/Oauth2TokenSettingsForm.php, line 208

Class

Oauth2TokenSettingsForm
The settings form.

Namespace

Drupal\simple_oauth\Entity\Form

Code

public function validateExistingFile(array &$element, FormStateInterface $form_state, array &$complete_form) {
  if (!empty($element['#value'])) {
    $path = $element['#value'];

    // Does the file exist?
    if (!$this->fileSystemChecker
      ->fileExist($path)) {
      $form_state
        ->setError($element, $this
        ->t('The %field file does not exist.', [
        '%field' => $element['#title'],
      ]));
    }

    // Is the file readable?
    if (!$this->fileSystemChecker
      ->isReadable($path)) {
      $form_state
        ->setError($element, $this
        ->t('The %field file at the specified location is not readable.', [
        '%field' => $element['#title'],
      ]));
    }
  }
}