function CredentialForm::validatePaths

Same name in other branches
  1. 8.9.x 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 345

Class

CredentialForm
Migrate Upgrade database credential form.

Namespace

Drupal\migrate_drupal_ui\Form

Code

public function validatePaths($element, FormStateInterface $form_state) {
    $version = $form_state->getValue('version');
    // Only validate the paths relevant to the legacy Drupal version.
    if ($version !== '7' && ($element['#name'] == 'source_base_path' || $element['#name'] == 'source_private_file_path')) {
        return;
    }
    if ($version !== '6' && $element['#name'] == 'd6_source_base_path') {
        return;
    }
    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.