public function ImageOptimizerForm::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/ ImageOptimizerForm.php, line 235
Class
- ImageOptimizerForm
- Class ImageOptimizerForm.
Namespace
Drupal\fastly\FormCode
public function validateForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('fastly.settings');
if (empty($config
->get('api_key'))) {
$element = [];
$form_state
->setError($element, $this
->t('You must set an API token <a href=":url">here</a> first', [
':url' => Url::fromRoute('fastly.settings')
->toString(),
]));
}
if ($form_state
->getValue('image_optimization') == 1) {
if (!$this->api
->ioEnabled($config
->get('service_id'))) {
$form_state
->setErrorByName('image_optimization', $this
->t('You cannot enable Fastly image optimization in configuration until you have it available on service!'));
}
}
if ($form_state
->getValue('image_optimization') && !$form_state
->getValue('optimize')) {
$form_state
->setErrorByName('optimize', $this
->t('You need to set default optimization of images to low, medium or high.'));
}
}