Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Skullbock committed Jan 19, 2024
1 parent 094280f commit 60b8707
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
18 changes: 12 additions & 6 deletions config/cookiebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,35 @@
*/
'consent_groups' => [
'required' => [
'title' => 'cookiebar.consents.required.label',
'description' => 'cookiebar.consents.required.description',
'title' => 'cookiebar::cookiebar.consents.required.label',
'description' => 'cookiebar::cookiebar.consents.required.description',
'consents' => [
GTMConsent::SECURITY_STORAGE,
GTMConsent::FUNCTIONALITY_STORAGE,
],
'disabled' => true,
'default' => true,
],
'analytics' => [
'title' => 'cookiebar.consents.analytics.label',
'description' => 'cookiebar.consents.analytics.description',
'title' => 'cookiebar::cookiebar.consents.analytics.label',
'description' => 'cookiebar::cookiebar.consents.analytics.description',
'consents' => [
GTMConsent::ANALYTICS_STORAGE,
GTMConsent::FUNCTIONALITY_STORAGE,
],
'disabled' => false,
'default' => false,
],
'marketing' => [
'title' => 'cookiebar.consents.marketing.label',
'description' => 'cookiebar.consents.marketing.description',
'title' => 'cookiebar::cookiebar.consents.marketing.label',
'description' => 'cookiebar::cookiebar.consents.marketing.description',
'consents' => [
GTMConsent::AD_STORAGE,
GTMConsent::AD_PERSONALIZATION,
GTMConsent::AD_USER_DATA,
],
'disabled' => false,
'default' => false,
],
],
];
10 changes: 0 additions & 10 deletions src/GTMConsentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,4 @@ public function consentGroups(): Collection
{
return collect(config('cookiebar.consent_groups', []));
}

public function forcedConsentGroups(): Collection
{
return $this->consentGroups()->where('force', true);
}

public function isConsentGroupForced(string $consent): bool
{
return $this->forcedConsentGroups()->contains($consent);
}
}
13 changes: 7 additions & 6 deletions src/Livewire/HasCookieBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Filament\Actions\Action;
use Filament\Forms\Components\Toggle;
use Illuminate\Support\HtmlString;
use Weble\LaravelFilamentCookieBar\Enums\GTMConsent;
use Weble\LaravelFilamentCookieBar\Facades\GTMConsentManager;

Expand All @@ -23,17 +24,17 @@ public function showCookieModalAction(): Action
->form(
GTMConsentManager::consentGroups()
->map(fn(array $consentOptions, string $key): Toggle => Toggle::make($key)
->label(__($consentOptions['label'] ?? $key))
->label(__($consentOptions['title'] ?? $key))
->helperText(__($consentOptions['description'] ?? null))
->disabled(GTMConsentManager::isConsentGroupForced($key))
->accepted(GTMConsentManager::isConsentGroupForced($key))
->disabled($consentOptions['disabled'] ?? false)
->accepted($consentOptions['default'] ?? false)
)
->all()
)
->fillForm(
GTMConsentManager::forcedConsentGroups()
->mapWithKeys(fn(string $consent): array => [
$consent => 1
GTMConsentManager::consentGroups()
->mapWithKeys(fn(array $consentOptions, string $consent): array => [
$consent => $consentOptions['default'] ? 1 : 0
])
->all()
)
Expand Down

0 comments on commit 60b8707

Please sign in to comment.