Clicking on 'OK' button in modal does not write any cookie(s).

Created on 13 July 2023, 12 months ago
Updated 15 August 2023, 11 months ago

Problem/Motivation

No cookies are ever written when a user clicks "OK" or in this case re-labelled to "I Accept".

I also see no way to control the cookie name for each modal, which is important on managed hosting like Acquia or Pantheon where cookie names must meet specific naming patterns to pass through to the application from the client request.

How are you supposed to control modal visibility via cookies if modals are not writing or reading any?

The only time I see it writing a cookie is:

if (checkbox_please_do_not_show_again.is(':checked')) {
            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);
              }
            }

            cookies.set('please_do_not_show_again_modal_id_' + id_modal, true, cookieSettings);

          }

But I do not want to use a 'checkbox_please_do_not_show_again' checkbox. That is the purpose of "I Accept" button.

✨ Feature request
Status

Active

Version

5.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kevinquillen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kevinquillen
  • πŸ‡§πŸ‡·Brazil RenatoG Campinas

    Thanks for your feedback @kevinquillen

    No cookies are ever written when a user clicks "OK" or in this case re-labelled to "I Accept"

    The project wasn't designed to create cookies on "OK" button, so isn't a "bug", but I definitely is a great suggestion so I'm converting to Feature Request

    Workaround

    For now as a temporary you can use HOOK_modal_ID_alter() and when the user clicks on "I accept" we can store the cookie programmatically

    Example:

    /**
     * Implements hook_modal_ID_alter().
     */
    function HOOK_modal_ID_alter(&$modal, $modal_id) {
    
      // Set cookie to don't show again
      $cookieName = 'please_do_not_show_again_modal_id_' + $modal_id';
    
      // TODO: logic to insert the cookie.
    }
    

    Other possibility:

    1. Edit this Modal(s)
    2. Put a class on "OK button" E.g. i-accept-modal
    3. Hide the checkbox please don't show again for the end-users with display:none
    4. Create a custom JS to mark this checkbox when the user clicks on "I Accept" class

    I also see no way to control the cookie name for each modal

    We also don't have this option, I created a ticket to implement that ✨ Create a way to customize the cookie name for "don't show Modal" Active

    Question: If we have one config inside "Global Settings" to customize the cookie is enough, or do you think is necessary to customize cookie name from Modal to Modal?

Production build 0.69.0 2024