You are here

function readonlymode_settings_form_submit in Read only mode 2.0.x

Same name and namespace in other branches
  1. 8 readonlymode.module \readonlymode_settings_form_submit()

Settings form submission handler.

See readonlymode_form_system_site_maintenance_mode_alter().

1 string reference to 'readonlymode_settings_form_submit'
readonlymode_form_system_site_maintenance_mode_alter in ./readonlymode.module
Implements hook_form_FORM_ID_alter().

File

./readonlymode.module, line 85
The readonlymode module file.

Code

function readonlymode_settings_form_submit(array &$form, FormStateInterface $form_state) {

  // Save the activation state.
  \Drupal::service('readonlymode.manager')
    ->setReadonly($form_state
    ->getValue('enable_readonly', FALSE));

  // Update the config with the messages if necessary.
  $config = \Drupal::configFactory()
    ->getEditable('readonlymode.settings');
  $updated = FALSE;
  $settings = [
    'messages.default' => 'default_message',
    'messages.not_saved' => 'not_saved_message',
  ];
  foreach ($settings as $key => $element) {
    if ($config
      ->get($key) != $form_state
      ->getValue($element)) {
      $config
        ->set($key, $form_state
        ->getValue($element));
      $updated = TRUE;
    }
  }
  if ($updated) {
    $config
      ->save();
  }
}