Commit 78de53aa authored by Luis Carvalho's avatar Luis Carvalho Committed by Paulo Henrique Cota Starling
Browse files

Issue #3267943 by luiscarvalho, mpaulo, sophiavs: Add option to customize "do...

Issue #3267943 by luiscarvalho, mpaulo, sophiavs: Add option to customize "do not show again" cookie expiration
parent 04f92a9c
Loading
Loading
Loading
Loading
+2 −0
Changes for config/install/modal_page.modal.thank_you_for_installing_modal_page.yml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ enable_right_button: true
ok_label_button: OK
enable_dont_show_again_option: true
dont_show_again_label: 'Don''t show again'
enable_custom_cookie_expiration: false
custom_cookie_expiration_time: 10000
modal_size: modal-md
close_modal_esc_key: true
close_modal_clicking_outside: true
+1 −0
Changes for config/install/modal_page.settings.yml: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,3 +2,4 @@ verify_load_bootstrap_automatically: true
load_bootstrap: false
allowed_tags: 'h1,h2,a,b,big,code,del,em,i,ins,pre,q,small,span,strong,sub,sup,tt,ol,ul,li,p,br,img'
clear_caches_on_modal_save: false
default_cookie_expiration: 10000
+9 −0
Changes for config/schema/modal.schema.yml: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -60,6 +60,12 @@ modal_page.modal.*:
    delay_display:
      type: string
      label: 'Delay to display'
    enable_custom_cookie_expiration:
      type: boolean
      label: 'Cookie expiration'
    custom_cookie_expiration_time:
      type: integer
      label: 'Cookie expiration time'
    enable_show_on_height:
      type: boolean
      label: 'Enable show on height'
@@ -153,3 +159,6 @@ modal_page.settings:
    clear_caches_on_modal_save:
      type: boolean
      label: 'Clear caches on modal save'
    default_cookie_expiration:
      type: integer
      label: 'Default cookie expiration time'
+12 −3
Changes for js/modal-page.js: 12 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -168,9 +168,18 @@
        ok_button.on('click', function () {

          if (checkbox_please_do_not_show_again.is(':checked')) {

            $.cookie('please_do_not_show_again_modal_id_' + id_modal, true, {expires: 365 * 20, path: '/'});

            var cookieTime = $(modal).find('#cookie_expiration').val();
            var cookieSettings = { path: '/'};
            // If not set at all, uses an arbitraty time (never show up again)
            if (!cookieTime) {
              cookieSettings.expires = 10000;
            } else {
              // If it's 0, don't add expire date. Expire at end of session.
              if (cookieTime > 0) {
                cookieSettings.expires = parseInt(cookieTime);
              }
            }
            $.cookie('please_do_not_show_again_modal_id_' + id_modal, true, cookieSettings);
          }

          var modalElement = $('.js-modal-page-ok-button').parents('#js-modal-page-show-modal');
+6 −1
Changes for modal_page.module: 6 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ function modal_page_theme() {
    'modal_page_modal' => [
      'variables' => [
        'do_not_show_again' => NULL,
        'cookie_expiration_time' => NULL,
        'title' => NULL,
        'display_title' => NULL,
        'text' => NULL,
@@ -129,9 +130,12 @@ function modal_page_preprocess_html(&$variables) {
    }
  }

  $modalHelper = \Drupal::service('modal_page.helper');

  foreach ($modals as $modal) {

    $modalOptions = \Drupal::service('modal_page.helper')->getModalOptions($modal);
    $modalOptions = $modalHelper->getModalOptions($modal);
    $cookieExpiration = $modalHelper->getCookieExpirationTime($modal);

    $dontShowAgain = $modal->getDontShowAgainLabel();

@@ -142,6 +146,7 @@ function modal_page_preprocess_html(&$variables) {
    $variables['page_top']['slidedown_templates'][] = [
      '#theme' => 'modal_page_modal',
      '#do_not_show_again'            => $dontShowAgain,
      '#cookie_expiration_time'       => $cookieExpiration,
      '#title'                        => $modal->label(),
      '#display_title'                => $modal->getDisplayTitle(),
      '#text'                         => $modal->getBody(),
Loading