function CredentialForm::validatePaths

Same name in other branches
  1. 9 core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::validatePaths()
  2. 10 core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::validatePaths()
  3. 11.x core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::validatePaths()

The #element_validate handler for the source path elements.

Ensures that entered path can be read.

File

core/modules/migrate_drupal_ui/src/Form/CredentialForm.php, line 285

Class

CredentialForm
Migrate Upgrade database credential form.

Namespace

Drupal\migrate_drupal_ui\Form

Code

public function validatePaths($element, FormStateInterface $form_state) {
    if ($source = $element['#value']) {
        $msg = $this->t('Failed to read from @title.', [
            '@title' => $element['#title'],
        ]);
        if (UrlHelper::isExternal($source)) {
            try {
                $this->httpClient
                    ->head($source);
            } catch (TransferException $e) {
                $msg .= ' ' . $this->t('The server reports the following message: %error.', [
                    '%error' => $e->getMessage(),
                ]);
                $this->errors[$element['#name']] = $msg;
            }
        }
        elseif (!file_exists($source) || !is_dir($source) || !is_readable($source)) {
            $this->errors[$element['#name']] = $msg;
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.