Problem/Motivation
The cookies_addons_fields module completely removes field content when cookies are not accepted, showing
empty areas instead of informative placeholder messages with "Accept Cookies" buttons. This creates poor
user experience and is inconsistent with other cookie services like cookies_video.
Steps to reproduce
1. Enable cookies_addons_fields module
2. Configure a field (e.g., embedcode) to require video cookie consent
3. Visit page with blocked content without accepting cookies
4. Observe empty/blank area where content should be
5. No placeholder text or accept button is shown
Proposed resolution
Modify cookies_addons_fields_preprocess_field() in cookies_addons_fields.module to keep field content and
let the JavaScript overlay system handle display, similar to how cookies_video works.
Current approach removes content:
$variables['items'] = [];
Proposed approach: Keep content and mark as blocked:
$variables['attributes']['class'][] = 'cookies-addons-fields-blocked';
Provide proper placeholder which is replaced on cookies consent
This allows the cookiesOverlay system to show proper placeholder text and accept buttons.
Remaining tasks
- [ ] Add proper placeholder instead of just removing content
- [ ] Ensure JavaScript properly handles blocked content display
- [ ] Test placeholder text and accept buttons appear correctly
- [ ] Verify content shows after accepting cookies
User interface changes
- Blocked fields will now show placeholder text instead of empty areas
- "Accept Cookies" buttons will be visible for blocked content
- Consistent experience with other cookie services
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | cookies_addons-fix-issue-with-missing-placeholder-3542052-5.patch | 738 bytes | _shy |
Issue fork cookies_addons-3542052
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
guido_sContent can't be kept as this what needs to be blocked.
It must be done somewhat like in cookies_addons_views.
Thought I had seen something like this in the code when I checked @_shy s code. But as mentioned didn't have the time to check the rendered output myself.
@_shy said it would be working fine. If not that needs to be fixed. Everything needs a proper placeholder div which is replaced after cookie consent for the specific category.
Comment #5
_shyCreated a PR and attached a patch with the changes for easy testing.
Comment #6
guido_sI just tested in Drupal 11.2.3 and can confirm there is a placeholder now on both nodes and blocks, but I also noticed the content of the field isn't blocked now. The placeholder just covers the content of the field.
So this needs more work.
Comment #7
_shyI reworked the PR. Instead of hiding content with a placeholder, I loop through all field items and clear content inside of each.
This will block content and keep the correct structure to render the placeholder correctly.
Please, take a look.
Comment #8
guido_sThanks, I tested it again and now the content is properly removed and loaded on consent.
Comment #9
igor mashevskyi commentedI tested this MR and it works well for me.
Comment #10
guido_sThanks for also testing this. I rebase the branch and added it to the merge train.
Thanks everybody!