You are here

public function FastlySettingsForm::uploadMaintenance in Fastly 8.3

Uploads maintenance page and saves configuration.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

\Drupal\Core\Ajax\AjaxResponse AjaxResponse.

File

src/Form/FastlySettingsForm.php, line 417

Class

FastlySettingsForm
Class FastlySettingsForm Defines a form to configure module settings.

Namespace

Drupal\fastly\Form

Code

public function uploadMaintenance(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  if ($this
    ->config("error_maintenance") != $form_state
    ->getValue('error_maintenance')) {
    $upload = $this->vclHandler
      ->uploadMaintenancePage($form_state
      ->getValue('error_maintenance'));
  }
  if (!$upload) {
    $message = $this
      ->t("Maintenance page upload failed.");
  }
  else {
    $message = $this
      ->t("Maintenance page uploaded successfuly.");
    $this->webhook
      ->sendWebHook($this
      ->t("Fastly Error / Maintenance page updated on %base_url", [
      '%base_url' => $this->baseUrl,
    ]), "config_save");
    $this
      ->submitForm($form, $form_state);
  }
  $response
    ->addCommand(new HtmlCommand('.error-maintenance-message', $message));
  return $response;
}