public function CredentialForm::validatePaths in Drupal 10
Same name and namespace in other branches
- 8 core/modules/migrate_drupal_ui/src/Form/CredentialForm.php \Drupal\migrate_drupal_ui\Form\CredentialForm::validatePaths()
- 9 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\FormCode
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;
}
}
}