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

Command icon 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

scontzen created an issue. See original summary.

guido_s’s picture

Issue summary: View changes

Content 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.

_shy made their first commit to this issue’s fork.

_shy’s picture

Version: 1.3.0 » 1.0.x-dev
Status: Active » Needs review
StatusFileSize
new738 bytes

Created a PR and attached a patch with the changes for easy testing.

guido_s’s picture

Status: Needs review » Needs work

I 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.

<div id="block-olivero-testblockfortestingfieldblockinginblocks" class="block block-block-content block-block-contentbfd273df-2330-489e-be5d-183a295bc5e6">
  
      <h2 class="block__title">Test Block for testing field blocking in blocks</h2>
    
      <div class="block__content">
      
            <div class="cookies-fallback--fields--wrap cookies-fallback--wrap disabled"><div class="cookies-addons-fields-placeholder text-content clearfix field field--name-body field--type-text-with-summary field--label-hidden field__item cookies-fallback--element" data-cookies-service="fields" data-service-name="Fields" data-field-id="block_content-1-body" data-view-mode="full" id="block_content-1-body-content">Test body of blocked field</div><div class="cookies-fallback cookies-fallback--fields cookies-fallback--fields--overlay"><div class="cookies-fallback--text">This content is blocked because field cookies have not been accepted.</div><button class="cookies-fallback--fields--btn cookies-fallback--btn">Accept field cookies</button><a href="#cookiesjsrAccept" class="cookies-fallback--link">Accept All Cookies</a></div></div>
      
    </div>
  </div>
_shy’s picture

Status: Needs work » Needs review

I 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.

guido_s’s picture

Thanks, I tested it again and now the content is properly removed and loaded on consent.

igor mashevskyi’s picture

Status: Needs review » Reviewed & tested by the community

I tested this MR and it works well for me.

guido_s’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for also testing this. I rebase the branch and added it to the merge train.
Thanks everybody!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • guido_s committed d71b31a1 on 1.0.x authored by _shy
    [#3542052] feat: Missing placeholder display for blocked content
    
    By:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.