generated from locomotivemtl/charcoal-contrib-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cookie-consent): fix cookie-consent error when consent is disabled
changes: - add active check - deactivated consent settings no longer throws an error - add a template trait to help with front-end formatting
- Loading branch information
1 parent
5046b55
commit fc55492
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace Charcoal\CookieConsent; | ||
|
||
use Pimple\Container; | ||
|
||
/** | ||
* Provides templating tools for cookie consent integration | ||
*/ | ||
trait HasCookieConsentTrait | ||
{ | ||
protected CookieConsentManager $cookieConsent; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function cookieConsentConfigAsJson() : string | ||
{ | ||
return $this->cookieConsent->getPluginOptionsAsJson(); | ||
} | ||
|
||
public function hasCookieConsent(): bool | ||
{ | ||
return $this->cookieConsent->isCookieConsentActive(); | ||
} | ||
|
||
public function cookieConsentScriptTag(): string | ||
{ | ||
if (!$this->hasCookieConsent()) { | ||
return 'type=text/javascript'; | ||
} | ||
|
||
return 'type=text/plain'; | ||
} | ||
|
||
/** | ||
* twig syntax | ||
* | ||
* @return string | ||
*/ | ||
public function getCookieConsentConfigAsJson(): string | ||
{ | ||
return $this->cookieConsentConfigAsJson(); | ||
} | ||
|
||
/** | ||
* twig syntax | ||
* | ||
* @return string | ||
*/ | ||
public function getCookieConsentScriptTag(): string | ||
{ | ||
return $this->cookieConsentScriptTag(); | ||
} | ||
|
||
/** | ||
* twig syntax | ||
* | ||
* @return string | ||
*/ | ||
public function getHasCookieConsent(): bool | ||
{ | ||
return $this->hasCookieConsent(); | ||
} | ||
|
||
/** | ||
* @param Container|CookieConsentManager $cookieConsent | ||
* @return void | ||
*/ | ||
public function setCookieConsent($cookieConsent) | ||
{ | ||
$this->cookieConsent = $cookieConsent instanceof Container ? $cookieConsent['cookie-consent'] : $cookieConsent; | ||
} | ||
} |