You are here

public function SettingsController::updateApiKey in Popup Maker - All popup types 8

To ypdate the API key.

1 string reference to 'SettingsController::updateApiKey'
popup_maker.routing.yml in ./popup_maker.routing.yml
popup_maker.routing.yml

File

src/Controller/SettingsController.php, line 194

Class

SettingsController
Settings Controller to the popup maker module.

Namespace

Drupal\popup_maker\Controller

Code

public function updateApiKey() {
  if (!isset($_POST['sgpm-api-key-submit'])) {
    $this->messenger
      ->addError('Invalid request');
    return FALSE;
  }
  if (!$this->csrfToken
    ->validate($_POST['_csrf_token'], 'popup_maker_api_key')) {
    $this->messenger
      ->addError('Could not validate the security token');
    return FALSE;
  }
  if ($this
    ->refreshData($_POST['sgpm-api-key'])) {
    $this->configFactory
      ->getEditable('popup_maker.settings')
      ->set('api_key', $_POST['sgpm-api-key'])
      ->save();
    $this->messenger
      ->addStatus('New api key saved successfully');
  }
  return $this
    ->redirect('popup_maker.settings');
}