elleracompany / craft-cookie-consent

GDPR-Compliant cookie consent banner for Craft CMS
Other
6 stars 6 forks source link

Override site specific slugs on multisite #15

Closed andersaloof closed 4 years ago

andersaloof commented 4 years ago

This is more of a feature request than an issue.

I'm currently developing a multisite with 7 sites, 6 countries and a splash site for selecting the desired country.

The splash site is shown on example.com, with each country having their own directory (example.com/uk, example.com/no, etc...).

I would like to let the given consent for each group to be global and not site specific, so my templates could do {% if craft.cookieConsent.getConsent('statistics') { // insert ga.js } %} instead of {% if craft.cookieConsent.getConsent('siteunitedkingdom-statistics') { // insert ga.js } %} and checking the slug for each site.

I was able to achieve this by enabling the slug field in https://github.com/elleracompany/craft-cookie-consent/blob/master/src/templates/settings/_includes/group.twig#L39 to be editable, and overriding the default generated site specific slug "siteunitedkingdom-statistics" to a generic "statistics" for relevant groups across all sites.

So the feature request is that the slug field is editable, at least on multisite installations,

kerns commented 4 years ago

What is the reason for slug fields not being editable? This feels like it would fix a lot of issues. @jellingsen Maybe if I understood on a technical level why it was this way I could better suggest a work around.

jellingsen commented 4 years ago

We made that not editable because we expect manually editing that would add a lot of possible issues. Consents will no longer match their cookie groups when the slug is edited after the consent is given, and we might have slug conflicts between sites in a multisite setup.

It is, as @andersaloof mentions, possible by editing the twig (or db directly), and that seems to work for them. Maybe the only change we need here is to do is to enable editing, but slap on a warning of the undesired effects it might cause.

andersaloof commented 4 years ago

We moved on to CookieBot to handle cookies and consents, as we also needed to handle consents on a WooCommerce webshop system hosted on a subdomain.

While still using the plugin, we did run into other issues trying to override the automatically generated slugs, so it's not a recommended solution...

jellingsen commented 4 years ago

It seems like this request is going to create more issues than it solves. For now this functionality will not be implemented, but I'm willing to revisit this on a later date should more people have the need.

dennisfrank commented 4 years ago

I fixed this with some custom Twig:

craft.cookieConsent.getConsent(currentSite.handle|lower ~ '-statistics')