public function FastlySettingsForm::validateForm in Fastly 8.3
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- src/
Form/ FastlySettingsForm.php, line 301
Class
- FastlySettingsForm
- Class FastlySettingsForm Defines a form to configure module settings.
Namespace
Drupal\fastly\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
// Get and use the API token value from this form for validation.
$apiKey = $form_state
->getValue('api_key');
if (empty($apiKey) && !$this->api
->validatePurgeCredentials()) {
$form_state
->setErrorByName('api_key', $this
->t('Please enter an API token.'));
}
if (!empty($apiKey)) {
$this->api
->setApiKey($apiKey);
}
// Verify API token has adequate scope to use this form.
if (!$this->api
->validatePurgeToken()) {
$form_state
->setErrorByName('api_key', $this
->t('Invalid API token. Make sure the token you are trying has at least <em>global:read</em>, <em>purge_all</em>, and <em>purge_all</em> scopes.'));
}
}