Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
@Myself: TODO: Write better issue summary!
Context:
EUCC JavaScript functions
Problem:
The current JavaScript code of this wonderful module is very much UI based. It's hard to fire events or listen for them from external APIs. Examples can be found in the related issues.
Good examples are to show / hide the popup through a JavaScript call from a custom button, change consent, ...
Proposed solution:
Instead the current implementation should use calls to a more generic JS API which is also usable from global.
Next Steps:
- Write down requirements and API calls + events
- D8 & D7 Implementation
- Documentation
- Inform other issues about new API calls
Comment | File | Size | Author |
---|---|---|---|
#23 | D7.3130015.public-js-api.23.patch | 26.43 KB | Grayle |
#18 | D8.3130015.public-js-api.18.patch | 27.12 KB | Grayle |
Comments
Comment #2
AnybodyComment #3
reszlithe attached patch could be a starting point for this issue:
done it for both D7 and D8
D8 sample:
example usage (sending category data to Google Tag Manager) for both D7 and D8 can be found in my sandbox module:
https://www.drupal.org/sandbox/reszli/3138494
Comment #4
Grayle CreditAttribution: Grayle at Dropsolid commentedTested the last patch, and with it I'm getting a console error.
handlers has no length. My guess is filterQueue's if statement isn't met so it returns nothing. Moving the "var handlers = []" and "return handlers" outside the if statement should fix it.
Comment #5
reszlithanks Grayle! indeed, when there are no handlers attached the code would fail
attached patch fixes this by always returning at least an empty array when filtering the queue
NOTE: the patches here apply only if you also have the latest patch from #3068670: Improve the UX for cookie categories
Comment #6
svenryen CreditAttribution: svenryen at Ramsalt Lab commented@reszli: Do you have any steps or sample code that can be used to review this issue?
Comment #7
reszli@svenryen example usage (sending category data to Google Tag Manager) for both D7 and D8 can be found in my sandbox module
https://www.drupal.org/sandbox/reszli/3138494
Comment #8
AnybodyHi reszli,
great work, thanks a lot! What we can see is, that this concept can even make the code simpler or better readable in some areas and we should definitely use this chance for a refactoring of the JS code.
Some critical questions, not to criticise you or your solution, but to discuss for the best solution:
1)
Which would mean EUCC doesn't "block" scripts, instead it also "defers" their execution. So Google Analytics for example registers its codes for eventual execution instead of executing itself?
Can we think of cases where that would not work and perhaps make things even worse because of the "defer"? Another module would have to rely on this, correct?
For reference: EUCCX instead encapsulated scripts and defers their execution. Before we decide which way to go (or both), we should think about how to interact best with Drupal libraries, dynamic code and the possibility that a third-party module isn't changed by the maintainer but other modules can define plugins to defer their execution.
I'd like to discuss this now, before the "defer" logic gets in because once shipped this all will be hard to remove / change again!
And my bitter results from many problems with tracking snippets and cookie compliance is that priority /loading order is often a problem if you only have limited access to all parts of the code (e.g. comes from different contrib modules).
2) You decided to implement your own observers. That's fair, while still using jQuery in eu_cookie_compliance a trigger() / on() event could be a lot more "lightweight" (if jQuery is not removed here)?
I know that's a heretical debate... ;) I just want to point out, that we should be sure this is the best way to go. Quite a lot of boilerplate code is added for these observers.
Thank you very much again and as said above - this is for discussion, not because I don't like your patch :)
Comment #9
svenryen CreditAttribution: svenryen at Ramsalt Lab commented> we should definitely use this chance for a refactoring of the JS code.
I disagree with this. I think we should get these new features out the door in 1.x. Refactoring all the JS code (and removing jQuery) is probably a 2.x task.
Comment #10
Anybodyre: @svenryen: Ok that sounds fair and you are the maintainer. :)
2.x could then perhaps start with several concept & code cleanup steps plus test driven. What I just wanted to say with
> we should definitely use this chance for a refactoring of the JS code.
is, that these added functionalities lead to more and more complex code and eventually spaghetti, which justifies a refactoring as soon as we know how to proceed. But also it shows chances to better encapsulation and separation via API. I agree keeping 1.x stable is very important.
Comment #11
svenryen CreditAttribution: svenryen at Ramsalt Lab commentedI tried the EUCC GTM module the other day and it seems to work.
Is that sufficient testing, or do we need more testing of this patch?
Comment #12
Grayle CreditAttribution: Grayle at Dropsolid commentedWe've been using this patch successfully in several projects, so for us I think we can call that RTBC.
Comment #13
svenryen CreditAttribution: svenryen at Ramsalt Lab commentedI trust you on that (will still give it some scrutiny as well) so bumping the status.
Comment #14
AnybodyCould someone please help to create a follow-up for an 2.0.x issue with a clean issue summary (by issue template) to write down the requirements? That would help a lot!
I think a complete rewrite makes sense, but as @svenryen decided, this issue itself should go into 1.x.
Comment #15
svenryen CreditAttribution: svenryen at Ramsalt Lab commented@grayle, I tried the d8 and maybe I'm missing something, but it doesn't cleanly apply. We've added quite a bit to the module since June. Would you be able to do a re-roll of the patches?
Comment #16
Grayle CreditAttribution: Grayle at Dropsolid commentedSure thing
Comment #17
Grayle CreditAttribution: Grayle at Dropsolid commentedRerolled D8 patch against current head of dev (instead of against patched dev as old patch).
Comment #18
Grayle CreditAttribution: Grayle at Dropsolid commentedComment #21
svenryen CreditAttribution: svenryen at Ramsalt Lab commentedCommitted the D8 version just now.
Comment #22
svenryen CreditAttribution: svenryen at Ramsalt Lab commentedComment #23
Grayle CreditAttribution: Grayle at Dropsolid commentedComment #24
Grayle CreditAttribution: Grayle at Dropsolid commentedComment #26
Grayle CreditAttribution: Grayle at Dropsolid commentedComment #27
Grayle CreditAttribution: Grayle at Dropsolid commentedTalked with Sven on slack to review/commit this patch