Add a way to send data to the server when requesting the cookie data

Created on 6 January 2022, over 3 years ago
Updated 30 January 2023, about 2 years ago

Problem/Motivation

When calling the callback for the cookie data, it would be nice to also be able to send custom data.
An example would be to send the browser timezone, which could then be saved in hook_cacheable_cookie_handling_set_cookies().

Steps to reproduce

This is a new feature.

Proposed resolution

Collect the data from other modules before marking the Ajax request.

Remaining tasks

Write the code.

User interface changes

Nothing.

API changes

There will be a way to add the data to send.

Data model changes

None.

📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇮🇹Italy marco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇹Italy FrancescoQ

    I found some issues with the first provided approach:

    • - only one provider could be set, as the last one overrides the previous ones.
    • - there could be some issues in case of different js loading times, when the provider js file was loaded before the library.

    with the attached patch I changed the way we provide/collect the cacheable cookie handling providers, by treating more in a similar way Drupal core use the behaviours:

    • - They are now stored in "their own" Drupal property cacheableCookieHandlingProviders so there's no risk that cacheableCookieHandling in not initialised if the JS are loaded in different order.
    • - When cacheableCookieHandling init we search/loop that property and if we found some providers we use the provided data
    • - Before this change the last provider set in the cacheableCookieHandling object was the only one that could provide data since it overrides the old ones (we don't have a case of multiple providers yet, but this could happens), now all the providers are manteined.

    I also provided an updated example with this new logic implemented.

Production build 0.71.5 2024