whitecube / laravel-cookie-consent

Register, configure and ask for cookies consent in a EU-compliant way
MIT License
312 stars 37 forks source link

Blade directive for cookie information injection inside a legal information page #49

Closed toonvandenbos closed 2 months ago

toonvandenbos commented 2 months ago

Most privacy policy/cookie policy or other legal pages covering cookies need to list durations and descriptions for each used cookie. Since we already have this list and information from the configured cookies, a new @cookieconsentinfo directive linked to a new publishable view used to automatically display a table inside these legal pages would be a great addition to the package.

The idea is to create a new Blade Directive that would simply inject the cookie descriptions at the correct location:

<p>{{-- legal blablabla --}}</p>

@cookieconsentinfo

<p>{{-- legal blablabla --}}</p>

... would render the contents from a publishable blade view, containing typical "WYSIWYG" markup (paragraphs and tables).

In order to enable content administrators to insert this information wherever they want inside their WYSIWYG editor, we should also add a facade method to Whitecube\LaravelCookieConsent\Facades\Cookies that could be used to inject said view at the location of the @cookieconsentinfo tag inside the WYSIWYG content that will be echo'ed in the page. Somenthing like this:

<div id="legal-content">
{!! Cookies::replaceInfoTag($wysiwyg) !!}
</div>

Since most WYSIWYG mechanisms will inject HTML, we'll have to check for the following occurrences in case the tag is automatically wrapped inside an HTML tag:

  1. \<(\w)[^\>]+\>\@cookieconsentinfo\<\/\1\>
  2. @cookieconsentinfo