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.
Problem/Motivation
If your node template doesn't print {{ content }}
or explicitly {{ content.statistics_content_counter }}
, then statistics.js is not added.
Proposed resolution
Add the library to $build['#attached'], then it apparently works if at least one {{ content.something }}
exists. I don't know why it works, other than @WimLeers said so ;)
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#10 | statistics-library-2458601-10.patch | 4.13 KB | thenchev |
#10 | interdiff.txt | 5.05 KB | thenchev |
Comments
Comment #1
BerdirPatch was created on an older core version, let's see if this still applies.
Comment #2
timmillwoodComment #3
BerdirCompletely forgot about this one, thanks for the RTBC :)
Note: Adding a test for this would require a test theme with a node template that doesn't contain {{ content }}, that quite some effort.
Comment #4
timmillwoodRight, because there's no proper tests I'll look out for bug reports.
Comment #5
alexpottRe #3 this this like pretty important functionality for the statistics module and probably something that should be tested. #2385243: Make core user fields available for twig templates added a test theme for a similar reason - didn't seem like too much work.
Comment #6
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedWorking on it.
Comment #7
timmillwoodGreat start @Denchev thanks for the work on this!
Comment #8
thenchev CreditAttribution: thenchev at MD Systems GmbH commentedComment #9
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedFew cosmetic comments:
s/block_test_theme/statistics_test_attached
Copy-paste kind of thing I assume.
Is there a way to avoid using the global here?
Maybe asserting just statistics.js? Something like:
I think we don't need this entire comment block in a template that is used for testing purposes only.
Comment #10
thenchev CreditAttribution: thenchev at MD Systems GmbH commented9.2) Yup, missed that somehow
Also this should fix everything else.
Comment #11
BerdirLooks good now I think.
Comment #12
alexpottThis is a normal bug fix that is not disruptive and therefore permitted during beta. Committed bfdc741 and pushed to 8.0.x. Thanks!