It would be great to have a possibility to block individual fields based on the user's cookie consent preferences.
Currently, the Cookies Addons module has submodules for blocking blocks (cookies_addons_blocks) and views (cookies_addons_views), but there's no way to block specific fields when users haven't consented to relevant cookie categories.
For example:
- Block video embed fields when user declined marketing cookies
- Hide social media fields when tracking cookies are not accepted
- Block map fields (Google Maps) when functional cookies are declined
- Hide any field that might load third-party content requiring consent
I propose creating a separate sub-module "cookies_addons_fields" that would work exactly like cookies_addons_blocks but for fields, using the same configuration pattern and placeholder replacement logic.
This would complete the cookie consent coverage by adding field-level control alongside the existing block and view level controls.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | cookies_addons-implement-field-blocking-function-3532613-4.patch | 11.98 KB | _shy |
Issue fork cookies_addons-3532613
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 #4
_shyAlso, added a patch with the changes.
Comment #6
guido_sComment #7
guido_sI added some validation for the route and some access checks to make sure users can only get fields and view modes they have access for to not leak any data. Didn't manage yet to do a test in a test site though. Feel free to check again. I will merge this after it has been properly tested in a real drupal environment.
Comment #8
_shyI tested the functionality with the latest changes on the Drupal website. After accepting the cookies, the field’s content was correctly displayed in place of the placeholder block.
The functionality was verified for both logged-in and anonymous users and tested with different field types.
Comment #10
guido_sThanks for testing it again!
I merged it now and we can create a new feature release and update the modules description.