diff --git a/.gitignore b/.gitignore index 8f81d29..7529196 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,4 @@ # Static utilities .php_cs.cache -/.php-cs-fixer.cache +.php-cs-fixer.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c0f18c..590e34b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Version 0.1.1 + +- Remove `modal.related_companies_count` +- Add `services.x.related_companies_count`. The total count will be the sum of this new configuration for enabled service. + ## Version 0.1.0 - Initial commit diff --git a/README.adoc b/README.adoc index dc02dcd..590be3c 100644 --- a/README.adoc +++ b/README.adoc @@ -11,10 +11,10 @@ ifndef::env-github[] image:.github/logo.svg[Logo, align=center] endif::[] -image:https://img.shields.io/packagist/v/rich-id/cookies-regulation-bundle-bundle[link="https://packagist.org/packages/rich-id/cookies-regulation-bundle-bundle",window="_blank"] +image:https://img.shields.io/packagist/v/rich-id/cookies-regulation-bundle[link="https://packagist.org/packages/rich-id/cookies-regulation-bundle",window="_blank"] image:https://github.com/rich-id/cookies-regulation-bundle/workflows/Tests/badge.svg[link="https://github.com/rich-id/cookies-regulation-bundle/actions",window="_blank"] image:https://coveralls.io/repos/github/rich-id/cookies-regulation-bundle/badge.svg?branch=master[link="https://coveralls.io/github/rich-id/cookies-regulation-bundle?branch=master",window="_blank"] -image:https://api.codeclimate.com/v1/badges/cookies-regulation-bundle/maintainability[link="https://codeclimate.com/github/rich-id/cookies-regulation-bundle/maintainability",window="_blank"] +image:https://api.codeclimate.com/v1/badges/829921eccb14db0b0948/maintainability[link="https://codeclimate.com/github/rich-id/cookies-regulation-bundle/maintainability",window="_blank"] image:https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat[link="https://github.com/richcongress/test-suite/issues",window="_blank"] image:https://img.shields.io/badge/license-MIT-blue.svg[link="LICENSE",window="_blank"] image:https://img.shields.io/badge/PHP-7.3%2B-yellow[] @@ -53,7 +53,7 @@ composer require rich-id/cookies-regulation-bundle == 3. Versioning -cookies-regulation-bundle-bundle follows link:https://semver.org/[semantic versioning^]. In short the scheme is MAJOR.MINOR.PATCH where +cookies-regulation-bundle follows link:https://semver.org/[semantic versioning^]. In short the scheme is MAJOR.MINOR.PATCH where 1. MAJOR is bumped when there is a breaking change, 2. MINOR is bumped when a new feature is added in a backward-compatible way, 3. PATCH is bumped when a bug is fixed in a backward-compatible way. diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 47b2a42..51e2a09 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -28,7 +28,6 @@ protected function buildConfig(NodeBuilder $nodeBuilder): void $modalNode = $nodeBuilder->arrayNode('modal')->children(); $modalNode->scalarNode('header')->isRequired(); - $modalNode->integerNode('related_companies_count')->isRequired(); $relatedCompaniesPrivacyPolicyUrlNode = $modalNode->arrayNode('related_companies_privacy_policy_url'); self::addUrlOrRouteConfig($relatedCompaniesPrivacyPolicyUrlNode); @@ -40,6 +39,7 @@ protected function buildConfig(NodeBuilder $nodeBuilder): void $servicesNode->booleanNode('mandatory')->defaultFalse(); $servicesNode->scalarNode('conservation')->isRequired(); $servicesNode->arrayNode('cookies_identifiers')->scalarPrototype(); + $servicesNode->integerNode('related_companies_count')->defaultValue(1); $servicesNode->scalarNode('initialization_callback'); $predefinedServiceNode = $servicesNode->arrayNode('predefined')->children(); diff --git a/src/Resources/views/partials/_modal.html.twig b/src/Resources/views/partials/_modal.html.twig index 43c5613..874ed7c 100644 --- a/src/Resources/views/partials/_modal.html.twig +++ b/src/Resources/views/partials/_modal.html.twig @@ -2,6 +2,6 @@ { header: '{{ config.header|trans|e('js') }}', - relatedCompaniesCount: {{ config.related_companies_count }}, + relatedCompaniesCount: {{ getCookiesRegulationRelatedCompaniesCount() }}, relatedCompaniesPrivacyPolicyUrl: '{{ urlMacro.parse(config.related_companies_privacy_policy_url)|trim }}', } diff --git a/src/TwigExtension/CookiesRegulationTwigExtension.php b/src/TwigExtension/CookiesRegulationTwigExtension.php index 1a25966..3b460ce 100644 --- a/src/TwigExtension/CookiesRegulationTwigExtension.php +++ b/src/TwigExtension/CookiesRegulationTwigExtension.php @@ -24,6 +24,7 @@ public function getFunctions(): array { return [ new TwigFunction('getCookiesRegulationConfig', [$this, 'getCookiesRegulationConfig']), + new TwigFunction('getCookiesRegulationRelatedCompaniesCount', [$this, 'getCookiesRegulationRelatedCompaniesCount']), ]; } @@ -35,4 +36,17 @@ public function getCookiesRegulationConfig(): array return $config; } + + public function getCookiesRegulationRelatedCompaniesCount(): int + { + $services = Configuration::get('services', $this->parameterBag); + $counts = \array_map( + static function (array $services): int { + return $services['enable'] ? $services['related_companies_count'] : 0; + }, + $services + ); + + return \array_sum($counts); + } } diff --git a/tests/DependencyConfiguration/ConfigurationTest.php b/tests/DependencyConfiguration/ConfigurationTest.php index c364304..833ad8b 100644 --- a/tests/DependencyConfiguration/ConfigurationTest.php +++ b/tests/DependencyConfiguration/ConfigurationTest.php @@ -44,20 +44,20 @@ public function testInstantiationContainer(): void ], 'modal' => [ 'header' => 'Modal header', - 'related_companies_count' => 2, 'related_companies_privacy_policy_url' => [ 'absolute' => 'http://related_companies_privacy_policy', ], ], 'services' => [ 'google_tag_manager' => [ - 'enable' => true, - 'name' => 'Google Tag Manager', - 'description' => 'Tag management system', - 'mandatory' => true, - 'conservation' => '6 months', - 'cookies_identifiers' => [], - 'predefined' => [ + 'enable' => true, + 'name' => 'Google Tag Manager', + 'description' => 'Tag management system', + 'mandatory' => true, + 'conservation' => '6 months', + 'related_companies_count' => 1, + 'cookies_identifiers' => [], + 'predefined' => [ 'name' => 'googleTagManager', 'options' => ['id' => 'GTM-TEST'], ], @@ -69,6 +69,7 @@ public function testInstantiationContainer(): void 'mandatory' => false, 'conservation' => '1 year', 'cookies_identifiers' => [], + 'related_companies_count' => 2, 'initialization_callback' => 'init_callback()', ], ], diff --git a/tests/Resources/Kernel/config/packages/rich_id_cookies_regulation.yaml b/tests/Resources/Kernel/config/packages/rich_id_cookies_regulation.yaml index cd26aa5..201983e 100644 --- a/tests/Resources/Kernel/config/packages/rich_id_cookies_regulation.yaml +++ b/tests/Resources/Kernel/config/packages/rich_id_cookies_regulation.yaml @@ -5,7 +5,6 @@ rich_id_cookies_regulation: url: 'http://privacy_policy' modal: header: 'Modal header' - related_companies_count: 2 related_companies_privacy_policy_url: 'http://related_companies_privacy_policy' services: google_tag_manager: @@ -21,5 +20,6 @@ rich_id_cookies_regulation: name: 'Another Service' description: 'Description of the another service' conservation: '1 year' + related_companies_count: 2 initialization_callback: 'init_callback()' diff --git a/tests/TwigExtension/CookiesRegulationTwigExtensionTest.php b/tests/TwigExtension/CookiesRegulationTwigExtensionTest.php index c1c9740..65f7ae3 100644 --- a/tests/TwigExtension/CookiesRegulationTwigExtensionTest.php +++ b/tests/TwigExtension/CookiesRegulationTwigExtensionTest.php @@ -43,20 +43,20 @@ public function testGetConfig(): void ], 'modal' => [ 'header' => 'Modal header', - 'related_companies_count' => 2, 'related_companies_privacy_policy_url' => [ 'absolute' => 'http://related_companies_privacy_policy', ], ], 'services' => [ 'google_tag_manager' => [ - 'enable' => true, - 'name' => 'Google Tag Manager', - 'description' => 'Tag management system', - 'mandatory' => true, - 'conservation' => '6 months', - 'cookies_identifiers' => [], - 'predefined' => [ + 'enable' => true, + 'name' => 'Google Tag Manager', + 'description' => 'Tag management system', + 'mandatory' => true, + 'conservation' => '6 months', + 'related_companies_count' => 1, + 'cookies_identifiers' => [], + 'predefined' => [ 'name' => 'googleTagManager', 'options' => ['id' => 'GTM-TEST'], ], @@ -67,6 +67,7 @@ public function testGetConfig(): void 'description' => 'Description of the another service', 'mandatory' => false, 'conservation' => '1 year', + 'related_companies_count' => 2, 'cookies_identifiers' => [], 'initialization_callback' => 'init_callback()', ], @@ -75,4 +76,13 @@ public function testGetConfig(): void $config ); } + + public function testGetRelatedCompaniesCount(): void + { + /** @var CookiesRegulationTwigExtension $extension */ + $extension = $this->getService(CookiesRegulationTwigExtension::class); + $result = $extension->getCookiesRegulationRelatedCompaniesCount(); + + self::assertSame(1, $result); + } }