public function CacheControlForm::submitForm in Akamai 8.3
Same name and namespace in other branches
- 8 lib/Drupal/akamai/Form/CacheControlForm.php \Drupal\akamai\Form\CacheControlForm::submitForm()
- 8.2 src/Form/CacheControlForm.php \Drupal\akamai\Form\CacheControlForm::submitForm()
Form submission 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 FormInterface::submitForm
File
- src/
Form/ CacheControlForm.php, line 198
Class
- CacheControlForm
- A simple form for testing the Akamai integration, or doing manual clears.
Namespace
Drupal\akamai\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$action = $form_state
->getValue('action');
$method = $form_state
->getValue('method');
$objects = explode(PHP_EOL, $form_state
->getValue('paths'));
$urls_to_clear = [];
if ($method == 'url') {
foreach ($objects as $path) {
$urls_to_clear[] = trim('/' . $path);
}
}
else {
$urls_to_clear = $objects;
$this->akamaiClient
->setType('cpcode');
}
$this->akamaiClient
->setAction($action);
$this->akamaiClient
->setDomain($form_state
->getValue('domain_override'));
if ($method == 'url') {
$response = $this->akamaiClient
->purgeUrls($urls_to_clear);
}
else {
$response = $this->akamaiClient
->purgeCpCodes($urls_to_clear);
}
if ($response) {
$this->messenger
->addMessage($this
->t('Requested :action of the following objects: :objects', [
':action' => $action,
':objects' => implode(', ', $urls_to_clear),
]));
}
else {
$this->messenger
->addError($this
->t('There was an error clearing the cache. Check logs for further detail.'));
}
}