Commit 765055a5 authored by Tilen Gombac's avatar Tilen Gombac Committed by Jakob P
Browse files

Issue #3219414: Module should have enable and disable checkbox on setting page

parent 9476a032
Loading
Loading
Loading
Loading
+10 −2
Changes for autologout.post_update.php: 10 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -6,8 +6,16 @@
 */

/**
 * Clear Caches to reload services container, issue #3101732.
 * Post update hook for all changes between 8.x-1.3 and 8.x-1.4.
 */
function autologout_post_update_fix_login_redirection_path() {
function autologout_post_update_8014() {

  // Issue #3219414: Add a disable checkbox for autologout
  $config_factory = \Drupal::configFactory();
  $config = $config_factory->getEditable('autologout.settings');
  $config->set('enabled', TRUE);
  $config->save(TRUE);

  // Issue #3101732: Flush caches due to service signature changes.
  drupal_flush_all_caches();
}
+1 −0
Changes for config/install/autologout.settings.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
enabled: true
timeout: 1800
max_timeout: 172800
padding: 20
+3 −0
Changes for config/schema/autologout.schema.yml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
autologout.settings:
  type: config_object
  mapping:
    enabled:
      type: boolean
      label: 'Enable autologout'
    timeout:
      type: integer
      label: 'Timeout value'
+5 −0
Changes for src/AutologoutManager.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -153,6 +153,11 @@ class AutologoutManager implements AutologoutManagerInterface {
   * {@inheritdoc}
   */
  public function preventJs() {
    if ($this->autoLogoutSettings->get('enabled') === FALSE) {
      // Autologout is disabled globally.
      return TRUE;
    }

    foreach ($this->moduleHandler->invokeAll('autologout_prevent') as $prevent) {
      if (!empty($prevent)) {
        return TRUE;
+12 −1
Changes for src/Form/AutologoutSettingsForm.php: 12 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -79,6 +79,15 @@ class AutologoutSettingsForm extends ConfigFormBase {
    if (!$default_dialog_title) {
      $default_dialog_title = $this->config('system.site')->get('name') . ' Alert';
    }

    $form['enabled'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable autologout'),
      '#default_value' => $config->get('enabled'),
      '#weight' => -20,
      '#description' => $this->t("Enable autologout on this site."),
    ];

    $form['timeout'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Timeout value in seconds'),
@@ -409,7 +418,9 @@ class AutologoutSettingsForm extends ConfigFormBase {
    $old_no_individual_logout_threshold = $autologout_settings->get('no_individual_logout_threshold');
    $new_no_individual_logout_threshold = (bool) $values['no_individual_logout_threshold'];

    $autologout_settings->set('timeout', $values['timeout'])
    $autologout_settings
      ->set('enabled', $values['enabled'])
      ->set('timeout', $values['timeout'])
      ->set('max_timeout', $values['max_timeout'])
      ->set('padding', $values['padding'])
      ->set('no_individual_logout_threshold', $values['no_individual_logout_threshold'])
Loading