- Issue created by @niklan
- 🇷🇺Russia niklan Russia, Perm
Not sure what these conditions are meant for, but removing them fixes the problem. In that case, everything works as expected.
- 🇩🇪Germany jan kellermann
The 2nd markup is from Klaro JS.
The 1st markup is provided by Drupal module.So we cant fix the Klaro JS markup :(
The Klaro JS only shows close button on some situations. You may open an upstream issue on github.
- 🇩🇪Germany jan kellermann
> Not sure what these conditions are meant for, but removing them fixes the problem. In that case, everything works as expected.
The conditions control when the Drupal module has to add its own close button. Else the close button fom Klaro JS is used.
- 🇷🇺Russia niklan Russia, Perm
Shouldn't the Klaro module replace the Klaro JS markup in this case? Removing these conditions ensures the close button is consistent across all scenarios.
The conditions control when the Drupal module has to add its own close button. Else the close button fom Klaro JS is used.
In that case, shouldn't these conditions affect all cases, not just the consent modal in a specific state?
Drupal.behaviors.klaro.manager.confirmed
— as I understand it, this becomesTRUE
if consent information is present (in a cookie or localStorage), no matter what consent was chosen.Drupal.behaviors.klaro.config.mustConsent
— becomesTRUE
when a user must choose consent and confirm it. Basically, this is used for the "Consent dialog" that is opened by default.
if ((Drupal.behaviors.klaro.manager.confirmed) && (!Drupal.behaviors.klaro.config.mustConsent)) {
So, this condition can be explained as follows: if the user has already performed some actions with consent (accepted, customized, or declined) AND there is no force for the "Consent dialog", disable the close button and let Klaro JS handle it.
But the “Consent dialog” from the
rel="open-consent-manager"
trigger is exactly the same. So, it sounds like the conditions are useless or wrong? The one withconfirmed
doesn’t make any sense. If it is confirmed, why would you try to hide the close button, or if it’s notmustConsent
, again, why would you hide it?I see the logic for the close button, which disables all the consents on click. But shouldn’t it be that way only when
Drupal.behaviors.klaro.manager.confirmed
isFALSE
? So, if it is not yet confirmed, disable everything and close, but if it is confirmed, we should preserve the settings and just close the window?// Handle close button X. if (drupalSettings.klaro.show_close_button) { if (document.querySelector('#klaro-cookie-notice')) { var elem = document.querySelector('#klaro-cookie-notice'); } else if (document.querySelector('.cm-modal.cm-klaro')) { var elem = document.querySelector('.cm-modal.cm-klaro .cm-header'); } if (elem && !document.querySelector('.klaro-close')) { var close_label = Drupal.t("Close dialog and decline all", {},{context: 'klaro'}); if (Drupal.behaviors.klaro.manager.confirmed) { var close_label = Drupal.t("Close dialog and keep existing consents", {},{context: 'klaro'}); } var close_html = '<button title="' + close_label + '" type="button" class="cn-decline klaro-close" tabindex="0" aria-label="' + close_label + '"></button>'; elem.insertAdjacentHTML('beforeend', close_html);; document.querySelector('.klaro-close')?.addEventListener('click', (e) => { if (!Drupal.behaviors.klaro.manager.confirmed) { Drupal.behaviors.klaro.manager.changeAll(false); Drupal.behaviors.klaro.manager.saveAndApplyConsents(); } }, false); document.querySelector('.klaro').classList.add('klaro-close-enabled'); document.querySelector('.klaro .cookie-modal .cm-modal .hide')?.remove(); } }
Take a look at the
.klaro-close
event listener. It only changes all consents to a disabled state and applies the changes if the user has still not interacted with the consent dialogs in any way. However, if something has already been selected, it does nothing and simply closes the window.Another approach could be to remove the close button added by Klaro JS if it meets the current conditions, instead of setting
elem
tofalse
. In that case, the “Consent modal” will be without a close button, which is also acceptable I think. - 🇩🇪Germany jan kellermann
We discussed the close button for some weeks in https://www.drupal.org/project/klaro/issues/3485880 ✨ Make close button X as DeclineAll button for mustConsent: true (needed for Italy) Active
Please have a look. I cannot remember all the problems we discussed.The behavior to "discard all" is only needed, if no consents are saved (in notice dialog and in consent dialog). The consent dialog has its own close-button - except if option "must consent" is enabled, then Klaro hides its own close button. So we added a close button with "discard all" function for this both cases. In all other cases the close-button is like an "abort"-button.