From ff8864bdf299760ace6fe746506ba7633e3098f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 11:36:21 +0200 Subject: [PATCH 01/23] Make ancestorClass option consistency to underscore --- doc/01-Basic-Menus.md | 2 +- doc/examples/01_apply_active_class_to_whole_tree.md | 4 ++-- src/Knp/Menu/Renderer/ListRenderer.php | 4 ++-- src/Knp/Menu/Renderer/RendererInterface.php | 2 +- src/Knp/Menu/Renderer/TwigRenderer.php | 2 +- src/Knp/Menu/Resources/views/knp_menu.html.twig | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/01-Basic-Menus.md b/doc/01-Basic-Menus.md index 2714e366..dbd9a932 100644 --- a/doc/01-Basic-Menus.md +++ b/doc/01-Basic-Menus.md @@ -238,7 +238,7 @@ the second argument to the `render()` method: is an ancestor of the current item. * `currentAsLink` (default: `true`): Whether to render the "current" menu item as link or as span. * `currentClass` (default: `current`) -* `ancestorClass` (default: `current_ancestor`) +* `ancestor_class` (default: `current_ancestor`) * `firstClass` (default: `first`) * `lastClass` (default: `last`) * `compressed` (default: `false`) diff --git a/doc/examples/01_apply_active_class_to_whole_tree.md b/doc/examples/01_apply_active_class_to_whole_tree.md index 15071685..598b4858 100644 --- a/doc/examples/01_apply_active_class_to_whole_tree.md +++ b/doc/examples/01_apply_active_class_to_whole_tree.md @@ -7,12 +7,12 @@ render method of your used renderer: ```php render($item, ['currentClass' => 'active', 'ancestorClass' => 'active']); +$renderer->render($item, ['currentClass' => 'active', 'ancestor_class' => 'active']); ``` or pass it as argument to the constructor of the used renderer: ```php 'active', 'ancestorClass' => 'active']); +$renderer = new Renderer($matcher, ['currentClass' => 'active', 'ancestor_class' => 'active']); ``` diff --git a/src/Knp/Menu/Renderer/ListRenderer.php b/src/Knp/Menu/Renderer/ListRenderer.php index 6b1e7837..3f372481 100644 --- a/src/Knp/Menu/Renderer/ListRenderer.php +++ b/src/Knp/Menu/Renderer/ListRenderer.php @@ -31,7 +31,7 @@ public function __construct(MatcherInterface $matcher, array $defaultOptions = [ 'matchingDepth' => null, 'currentAsLink' => true, 'currentClass' => 'current', - 'ancestorClass' => 'current_ancestor', + 'ancestor_class' => 'current_ancestor', 'firstClass' => 'first', 'lastClass' => 'last', 'compressed' => false, @@ -130,7 +130,7 @@ protected function renderItem(ItemInterface $item, array $options): string if ($this->matcher->isCurrent($item)) { $class[] = $options['currentClass']; } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) { - $class[] = $options['ancestorClass']; + $class[] = $options['ancestor_class']; } if ($item->actsLikeFirst()) { diff --git a/src/Knp/Menu/Renderer/RendererInterface.php b/src/Knp/Menu/Renderer/RendererInterface.php index 1855c463..91a1a590 100644 --- a/src/Knp/Menu/Renderer/RendererInterface.php +++ b/src/Knp/Menu/Renderer/RendererInterface.php @@ -16,7 +16,7 @@ interface RendererInterface * 1: only direct children * - currentAsLink: whether the current item should be a link * - currentClass: class added to the current item - * - ancestorClass: class added to the ancestors of the current item + * - ancestor_class: class added to the ancestors of the current item * - firstClass: class added to the first child * - lastClass: class added to the last child * diff --git a/src/Knp/Menu/Renderer/TwigRenderer.php b/src/Knp/Menu/Renderer/TwigRenderer.php index 9c9f88bf..40e8b3d6 100644 --- a/src/Knp/Menu/Renderer/TwigRenderer.php +++ b/src/Knp/Menu/Renderer/TwigRenderer.php @@ -39,7 +39,7 @@ public function __construct( 'matchingDepth' => null, 'currentAsLink' => true, 'currentClass' => 'current', - 'ancestorClass' => 'current_ancestor', + 'ancestor_class' => 'current_ancestor', 'firstClass' => 'first', 'lastClass' => 'last', 'template' => $template, diff --git a/src/Knp/Menu/Resources/views/knp_menu.html.twig b/src/Knp/Menu/Resources/views/knp_menu.html.twig index 0ac53f64..0d37856c 100644 --- a/src/Knp/Menu/Resources/views/knp_menu.html.twig +++ b/src/Knp/Menu/Resources/views/knp_menu.html.twig @@ -55,7 +55,7 @@ {%- if matcher.isCurrent(item) %} {%- set classes = classes|merge([options.currentClass]) %} {%- elseif matcher.isAncestor(item, options.matchingDepth) %} - {%- set classes = classes|merge([options.ancestorClass]) %} + {%- set classes = classes|merge([options.ancestor_class]) %} {%- endif %} {%- if item.actsLikeFirst %} {%- set classes = classes|merge([options.firstClass]) %} From 4fc676d5147fabaa80707c6886ce6c481afec877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 14:28:31 +0200 Subject: [PATCH 02/23] Require symfony/deprecation-contracts for trigger warnings --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7cb59e79..4e2b03d3 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ } ], "require": { - "php": "^7.2 || ^8.0" + "php": "^7.2 || ^8.0", + "symfony/deprecation-contracts": "^2.4" }, "conflict": { "twig/twig": "<1.40 || >=2,<2.9" From df8563795990e6d809a588418fd44fb8cea491a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 14:33:05 +0200 Subject: [PATCH 03/23] Add deprecation contracts and allow both ways for support BC --- doc/01-Basic-Menus.md | 2 +- .../01_apply_active_class_to_whole_tree.md | 14 ++++++++++++++ src/Knp/Menu/Renderer/ListRenderer.php | 5 +++++ src/Knp/Menu/Renderer/RendererInterface.php | 2 +- src/Knp/Menu/Renderer/TwigRenderer.php | 1 + src/Knp/Menu/Resources/views/knp_menu.html.twig | 3 ++- 6 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/01-Basic-Menus.md b/doc/01-Basic-Menus.md index dbd9a932..7aee7e8d 100644 --- a/doc/01-Basic-Menus.md +++ b/doc/01-Basic-Menus.md @@ -238,7 +238,7 @@ the second argument to the `render()` method: is an ancestor of the current item. * `currentAsLink` (default: `true`): Whether to render the "current" menu item as link or as span. * `currentClass` (default: `current`) -* `ancestor_class` (default: `current_ancestor`) +* `ancestor_class` (default: `current_ancestor`) (alias: ancestorClass, currently deprecated) * `firstClass` (default: `first`) * `lastClass` (default: `last`) * `compressed` (default: `false`) diff --git a/doc/examples/01_apply_active_class_to_whole_tree.md b/doc/examples/01_apply_active_class_to_whole_tree.md index 598b4858..aad4067d 100644 --- a/doc/examples/01_apply_active_class_to_whole_tree.md +++ b/doc/examples/01_apply_active_class_to_whole_tree.md @@ -10,9 +10,23 @@ render method of your used renderer: $renderer->render($item, ['currentClass' => 'active', 'ancestor_class' => 'active']); ``` +Old deprecated way: + +```php +render($item, ['currentClass' => 'active', 'ancestorClass' => 'active']); +``` + or pass it as argument to the constructor of the used renderer: ```php 'active', 'ancestor_class' => 'active']); ``` + +Old deprecated way: + +```php + 'active', 'ancestorClass' => 'active']) +``` diff --git a/src/Knp/Menu/Renderer/ListRenderer.php b/src/Knp/Menu/Renderer/ListRenderer.php index 3f372481..a7253364 100644 --- a/src/Knp/Menu/Renderer/ListRenderer.php +++ b/src/Knp/Menu/Renderer/ListRenderer.php @@ -32,6 +32,7 @@ public function __construct(MatcherInterface $matcher, array $defaultOptions = [ 'currentAsLink' => true, 'currentClass' => 'current', 'ancestor_class' => 'current_ancestor', + 'ancestorClass' => 'current_ancestor', // Deprecated in future 'firstClass' => 'first', 'lastClass' => 'last', 'compressed' => false, @@ -130,6 +131,10 @@ protected function renderItem(ItemInterface $item, array $options): string if ($this->matcher->isCurrent($item)) { $class[] = $options['currentClass']; } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) { + if(isset($options['ancestorClass']) { // Deprecated: it will be removed in future (@see: ancestor_class) + trigger_deprecation('knplabs/knp-menu', '3.2', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); + $options['ancestor_class'] = $options['ancestorClass']; + } $class[] = $options['ancestor_class']; } diff --git a/src/Knp/Menu/Renderer/RendererInterface.php b/src/Knp/Menu/Renderer/RendererInterface.php index 91a1a590..70ee352d 100644 --- a/src/Knp/Menu/Renderer/RendererInterface.php +++ b/src/Knp/Menu/Renderer/RendererInterface.php @@ -16,7 +16,7 @@ interface RendererInterface * 1: only direct children * - currentAsLink: whether the current item should be a link * - currentClass: class added to the current item - * - ancestor_class: class added to the ancestors of the current item + * - ancestor_class: class added to the ancestors of the current item (alias: ancestorClass, deprecated in a future) * - firstClass: class added to the first child * - lastClass: class added to the last child * diff --git a/src/Knp/Menu/Renderer/TwigRenderer.php b/src/Knp/Menu/Renderer/TwigRenderer.php index 40e8b3d6..e8f8b931 100644 --- a/src/Knp/Menu/Renderer/TwigRenderer.php +++ b/src/Knp/Menu/Renderer/TwigRenderer.php @@ -40,6 +40,7 @@ public function __construct( 'currentAsLink' => true, 'currentClass' => 'current', 'ancestor_class' => 'current_ancestor', + 'ancestorClass' => 'current_ancestor', 'firstClass' => 'first', 'lastClass' => 'last', 'template' => $template, diff --git a/src/Knp/Menu/Resources/views/knp_menu.html.twig b/src/Knp/Menu/Resources/views/knp_menu.html.twig index 0d37856c..4f79b806 100644 --- a/src/Knp/Menu/Resources/views/knp_menu.html.twig +++ b/src/Knp/Menu/Resources/views/knp_menu.html.twig @@ -55,7 +55,8 @@ {%- if matcher.isCurrent(item) %} {%- set classes = classes|merge([options.currentClass]) %} {%- elseif matcher.isAncestor(item, options.matchingDepth) %} - {%- set classes = classes|merge([options.ancestor_class]) %} + {# ancestorClass will be deprecated in future, use ancestor_class #} + {%- set classes = classes|merge([options.ancestor_class])|merge([options.ancestorClass]) %} {%- endif %} {%- if item.actsLikeFirst %} {%- set classes = classes|merge([options.firstClass]) %} From d2b325b7d33a185bde3afa918bd1403ce6aab0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 14:44:03 +0200 Subject: [PATCH 04/23] Fix if spaced as per review suggested --- src/Knp/Menu/Renderer/ListRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Knp/Menu/Renderer/ListRenderer.php b/src/Knp/Menu/Renderer/ListRenderer.php index a7253364..f912d76f 100644 --- a/src/Knp/Menu/Renderer/ListRenderer.php +++ b/src/Knp/Menu/Renderer/ListRenderer.php @@ -131,7 +131,7 @@ protected function renderItem(ItemInterface $item, array $options): string if ($this->matcher->isCurrent($item)) { $class[] = $options['currentClass']; } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) { - if(isset($options['ancestorClass']) { // Deprecated: it will be removed in future (@see: ancestor_class) + if (isset($options['ancestorClass']) { // Deprecated: it will be removed in future (@see: ancestor_class) trigger_deprecation('knplabs/knp-menu', '3.2', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); $options['ancestor_class'] = $options['ancestorClass']; } From d7a33998c36319d45c2c52605c16145a2baeff13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 14:44:55 +0200 Subject: [PATCH 05/23] Revert changes in doc for deprecated way as per review suggested --- .../01_apply_active_class_to_whole_tree.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/doc/examples/01_apply_active_class_to_whole_tree.md b/doc/examples/01_apply_active_class_to_whole_tree.md index aad4067d..598b4858 100644 --- a/doc/examples/01_apply_active_class_to_whole_tree.md +++ b/doc/examples/01_apply_active_class_to_whole_tree.md @@ -10,23 +10,9 @@ render method of your used renderer: $renderer->render($item, ['currentClass' => 'active', 'ancestor_class' => 'active']); ``` -Old deprecated way: - -```php -render($item, ['currentClass' => 'active', 'ancestorClass' => 'active']); -``` - or pass it as argument to the constructor of the used renderer: ```php 'active', 'ancestor_class' => 'active']); ``` - -Old deprecated way: - -```php - 'active', 'ancestorClass' => 'active']) -``` From 3aeb6874dbdb0fc156a4af600d35245c51907ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 15:04:33 +0200 Subject: [PATCH 06/23] Update version number for deprecation --- src/Knp/Menu/Renderer/ListRenderer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Knp/Menu/Renderer/ListRenderer.php b/src/Knp/Menu/Renderer/ListRenderer.php index f912d76f..51376b45 100644 --- a/src/Knp/Menu/Renderer/ListRenderer.php +++ b/src/Knp/Menu/Renderer/ListRenderer.php @@ -132,7 +132,7 @@ protected function renderItem(ItemInterface $item, array $options): string $class[] = $options['currentClass']; } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) { if (isset($options['ancestorClass']) { // Deprecated: it will be removed in future (@see: ancestor_class) - trigger_deprecation('knplabs/knp-menu', '3.2', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); + trigger_deprecation('knplabs/knp-menu', '3.3', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); $options['ancestor_class'] = $options['ancestorClass']; } $class[] = $options['ancestor_class']; From 24fa9c2819d62945add341b3b5fdfc3cc7e72678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 15:09:22 +0200 Subject: [PATCH 07/23] Improve warning message for twig deprecation as per review suggested --- src/Knp/Menu/Resources/views/knp_menu.html.twig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Knp/Menu/Resources/views/knp_menu.html.twig b/src/Knp/Menu/Resources/views/knp_menu.html.twig index 4f79b806..7697b9c0 100644 --- a/src/Knp/Menu/Resources/views/knp_menu.html.twig +++ b/src/Knp/Menu/Resources/views/knp_menu.html.twig @@ -55,8 +55,11 @@ {%- if matcher.isCurrent(item) %} {%- set classes = classes|merge([options.currentClass]) %} {%- elseif matcher.isAncestor(item, options.matchingDepth) %} - {# ancestorClass will be deprecated in future, use ancestor_class #} - {%- set classes = classes|merge([options.ancestor_class])|merge([options.ancestorClass]) %} + {%- set classes = classes|merge([options.ancestor_class]) %} + {%- if options.ancestorClass is not empty %} + {% deprecated 'knplabs/knp-menu 3.3: Using "ancestorClass" option is deprecated, use "ancestor_class" instead.' %} + {%- set classes = classes|merge([options.ancestorClass]) %} + {%- endif %} {%- endif %} {%- if item.actsLikeFirst %} {%- set classes = classes|merge([options.firstClass]) %} From 05e3231df52b1554bae30a37ca8ba6cf6ba0b46f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 15:32:54 +0200 Subject: [PATCH 08/23] Update test for show as legacy deprecation warnings --- tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php b/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php index f936d627..0e1e6dbf 100644 --- a/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php +++ b/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php @@ -202,7 +202,7 @@ public function testRenderWithClassAndTitle(): void $this->assertEquals($rendered, $this->renderer->render($this->menu)); } - public function testRenderWithCurrentItem(): void + public function testLegacyRenderWithCurrentItem(): void { $this->ch2->setCurrent(true); $rendered = '
  • Parent 1
  • Parent 2
'; @@ -326,7 +326,7 @@ public function testMatchingDepth1(): void $this->assertEquals($rendered, $this->renderer->render($this->menu, ['depth' => 1, 'matchingDepth' => 2])); } - public function testMatchingDepth2(): void + public function testLegacyMatchingDepth2(): void { $this->menu['Parent 1']['Child 1']->setCurrent(true); $rendered = '
  • Parent 1
  • Parent 2
'; From 5bf59b99a281f4cd83622770d84151ecb848ea3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 15:33:20 +0200 Subject: [PATCH 09/23] Avoid duplication of configs and show deprecations warnings too --- src/Knp/Menu/Renderer/ListRenderer.php | 10 ++++++++-- src/Knp/Menu/Renderer/TwigRenderer.php | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Knp/Menu/Renderer/ListRenderer.php b/src/Knp/Menu/Renderer/ListRenderer.php index 365c1218..c02a9086 100644 --- a/src/Knp/Menu/Renderer/ListRenderer.php +++ b/src/Knp/Menu/Renderer/ListRenderer.php @@ -32,7 +32,6 @@ public function __construct(MatcherInterface $matcher, array $defaultOptions = [ 'currentAsLink' => true, 'currentClass' => 'current', 'ancestor_class' => 'current_ancestor', - 'ancestorClass' => 'current_ancestor', // Deprecated in future 'firstClass' => 'first', 'lastClass' => 'last', 'compressed' => false, @@ -49,6 +48,13 @@ public function render(ItemInterface $item, array $options = []): string { $options = \array_merge($this->defaultOptions, $options); + // Avoid duplication of current_ancestor class. Overwrite value in old config to new one + if (isset($options['ancestorClass'])) { + $options['ancestor_class'] = $options['ancestorClass']; + unset($options['ancestorClass']); + trigger_deprecation('knplabs/knp-menu', '3.3', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); + } + $html = $this->renderList($item, $item->getChildrenAttributes(), $options); if ($options['clear_matcher']) { @@ -131,7 +137,7 @@ protected function renderItem(ItemInterface $item, array $options): string if ($this->matcher->isCurrent($item)) { $class[] = $options['currentClass']; } elseif ($this->matcher->isAncestor($item, $options['matchingDepth'])) { - if (isset($options['ancestorClass']) { // Deprecated: it will be removed in future (@see: ancestor_class) + if (isset($options['ancestorClass'])) { // Deprecated: it will be removed in future (@see: ancestor_class) trigger_deprecation('knplabs/knp-menu', '3.3', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); $options['ancestor_class'] = $options['ancestorClass']; } diff --git a/src/Knp/Menu/Renderer/TwigRenderer.php b/src/Knp/Menu/Renderer/TwigRenderer.php index e8f8b931..ed00254d 100644 --- a/src/Knp/Menu/Renderer/TwigRenderer.php +++ b/src/Knp/Menu/Renderer/TwigRenderer.php @@ -40,7 +40,6 @@ public function __construct( 'currentAsLink' => true, 'currentClass' => 'current', 'ancestor_class' => 'current_ancestor', - 'ancestorClass' => 'current_ancestor', 'firstClass' => 'first', 'lastClass' => 'last', 'template' => $template, @@ -56,6 +55,13 @@ public function render(ItemInterface $item, array $options = []): string { $options = \array_merge($this->defaultOptions, $options); + // Avoid duplication of current_ancestor class. Overwrite value in old config to new one + if (isset($options['ancestorClass'])) { + $options['ancestor_class'] = $options['ancestorClass']; + unset($options['ancestorClass']); + trigger_deprecation('knplabs/knp-menu', '3.3', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); + } + $html = $this->environment->render($options['template'], ['item' => $item, 'options' => $options, 'matcher' => $this->matcher]); if ($options['clear_matcher']) { From 5ae265b7ad9105ece977c6a32c0439c4285e49d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 15:53:22 +0200 Subject: [PATCH 10/23] Update php version in composer --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5e14fc28..696e1b7f 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^7.3 || ^8.0", "symfony/deprecation-contracts": "^2.4" }, "conflict": { From 10569aa7cf379d4d28e86d96a75dd1a0abb04d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 15:59:16 +0200 Subject: [PATCH 11/23] Try to avoid replacements by deprecation contracts in github build --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f6ad9b3b..fba26acf 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} - run: | - sed -ri 's/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; + sed -ri 's/"symfony\/(.+)/symfony\/deprecation-contracts/d;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; if: matrix.symfony - run: composer config minimum-stability dev && composer config prefer-stable true if: matrix.dev From abdeda84032b13dd5ccefdb562e1ad0b6a524d03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 16:05:17 +0200 Subject: [PATCH 12/23] Try another sed vudu way --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fba26acf..121d553e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} - run: | - sed -ri 's/"symfony\/(.+)/symfony\/deprecation-contracts/d;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; + sed -ri 's/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; if: matrix.symfony - run: composer config minimum-stability dev && composer config prefer-stable true if: matrix.dev From ae50e5772e79467953db9b99141b42f0b5d5fe21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 16:53:00 +0200 Subject: [PATCH 13/23] Add exclusion pattern /pattern/!s/pattern/ --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 121d553e..51b24a5c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} - run: | - sed -ri 's/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; + sed -ri '/symfony\/deprecation-contracts/!s/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; if: matrix.symfony - run: composer config minimum-stability dev && composer config prefer-stable true if: matrix.dev From 98046aa941c2f4b83cfa00cbde98ad92d0726286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 17:22:57 +0200 Subject: [PATCH 14/23] Update the sed vudu charm --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 51b24a5c..4e40c426 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} - run: | - sed -ri '/symfony\/deprecation-contracts/!s/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; + sed -ri '/symfony\/deprecation-contracts/!s/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; if: matrix.symfony - run: composer config minimum-stability dev && composer config prefer-stable true if: matrix.dev From 4ef0026a686620f07f92c5f92867cadfb797733f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 17:26:58 +0200 Subject: [PATCH 15/23] Vudu sed require a space --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4e40c426..37829636 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} - run: | - sed -ri '/symfony\/deprecation-contracts/!s/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; + sed -ri '/symfony\/deprecation-contracts/! s/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; if: matrix.symfony - run: composer config minimum-stability dev && composer config prefer-stable true if: matrix.dev From d82c70ff29cfdcf6c248e83fab131ad4e66adeeb Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Tue, 31 Aug 2021 17:33:43 +0200 Subject: [PATCH 16/23] Update build.yaml --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 37829636..e2f35917 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -62,7 +62,7 @@ jobs: with: php-version: ${{ matrix.php }} - run: | - sed -ri '/symfony\/deprecation-contracts/! s/"symfony\/(.+)\symfony\/deprecation-contracts/;": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; + sed -ri '/symfony\/deprecation-contracts/! s/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json; if: matrix.symfony - run: composer config minimum-stability dev && composer config prefer-stable true if: matrix.dev From 4abbba4cdf00b07454f5d01acbb9b7d7cf565a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 18:08:18 +0100 Subject: [PATCH 17/23] Add support deprecation for knp_menu_render and knp_menu_get with ancestor_class deprecation --- src/Knp/Menu/Twig/MenuExtension.php | 14 ++++++++++++++ tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Knp/Menu/Twig/MenuExtension.php b/src/Knp/Menu/Twig/MenuExtension.php index b5e749bf..b0b022ed 100644 --- a/src/Knp/Menu/Twig/MenuExtension.php +++ b/src/Knp/Menu/Twig/MenuExtension.php @@ -77,6 +77,13 @@ public function getTests(): array */ public function get($menu, array $path = [], array $options = []): ItemInterface { + // Avoid duplication of current_ancestor class. Overwrite value in old config to new one + if (isset($options['ancestorClass'])) { + $options['ancestor_class'] = $options['ancestorClass']; + unset($options['ancestorClass']); + trigger_deprecation('knplabs/knp-menu', '3.3', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); + } + return $this->helper->get($menu, $path, $options); } @@ -88,6 +95,13 @@ public function get($menu, array $path = [], array $options = []): ItemInterface */ public function render($menu, array $options = [], ?string $renderer = null): string { + // Avoid duplication of current_ancestor class. Overwrite value in old config to new one + if (isset($options['ancestorClass'])) { + $options['ancestor_class'] = $options['ancestorClass']; + unset($options['ancestorClass']); + trigger_deprecation('knplabs/knp-menu', '3.3', 'Using "%s" option is deprecated, use "%s" instead.', 'ancestorClass', 'ancestor_class'); + } + return $this->helper->render($menu, $options, $renderer); } diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index d0433851..734f4759 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -39,6 +39,20 @@ public function testRenderMenuWithOptions(): void $this->assertEquals('

foobar

', $this->getTemplate('{{ knp_menu_render(menu, {"firstClass": "test"}) }}', $helper)->render(['menu' => $menu])); } + + public function testRenderMenuWithDeprecatedAncestorClass(): void + { + $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); + $helper = $this->getHelperMock(['render']); + $helper->expects($this->once()) + ->method('render') + ->with($menu, ['ancestor_class' => 'test'], null) + ; + + $this->getTemplate('{{ knp_menu_render(menu, {"ancestorClass": "test"}) }}', $helper)->render(['menu' => $menu, 'ancestorClass' => 'test']); + + $this->expectDeprecationMessage('Since knplabs/knp-menu 3.3: Using "ancestorClass" option is deprecated, use "ancestor_class" instead.'); + } public function testRenderMenuWithRenderer(): void { From 9c5797cdce5f5612638d696bdd521886893ca4f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 20:47:57 +0100 Subject: [PATCH 18/23] Use ExpectDeprecationTrait for deprecation message --- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index 734f4759..e079522f 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -11,9 +11,12 @@ use Twig\Environment; use Twig\Loader\ArrayLoader; use Twig\TemplateWrapper; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; final class MenuExtensionTest extends TestCase { + use ExpectDeprecationTrait; + public function testRenderMenu(): void { $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); @@ -51,7 +54,7 @@ public function testRenderMenuWithDeprecatedAncestorClass(): void $this->getTemplate('{{ knp_menu_render(menu, {"ancestorClass": "test"}) }}', $helper)->render(['menu' => $menu, 'ancestorClass' => 'test']); - $this->expectDeprecationMessage('Since knplabs/knp-menu 3.3: Using "ancestorClass" option is deprecated, use "ancestor_class" instead.'); + $this->expectDeprecation('Since knplabs/knp-menu 3.3: Using "ancestorClass" option is deprecated, use "ancestor_class" instead.'); } public function testRenderMenuWithRenderer(): void From 78608e36a3ac15e1190468173ee8f74a491676a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 20:56:27 +0100 Subject: [PATCH 19/23] Add @group Legacy or Legacy in name for allow pass test in CI --- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index e079522f..ed7bd250 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -43,7 +43,7 @@ public function testRenderMenuWithOptions(): void $this->assertEquals('

foobar

', $this->getTemplate('{{ knp_menu_render(menu, {"firstClass": "test"}) }}', $helper)->render(['menu' => $menu])); } - public function testRenderMenuWithDeprecatedAncestorClass(): void + public function testRenderMenuWithDeprecatedAncestorClassLegacy(): void { $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $helper = $this->getHelperMock(['render']); From 742aacc39951bdb6fabf9520f325452c39c94a97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 20:58:57 +0100 Subject: [PATCH 20/23] Mistake preprend at beginning legacy --- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index ed7bd250..1c65ab96 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -42,8 +42,8 @@ public function testRenderMenuWithOptions(): void $this->assertEquals('

foobar

', $this->getTemplate('{{ knp_menu_render(menu, {"firstClass": "test"}) }}', $helper)->render(['menu' => $menu])); } - - public function testRenderMenuWithDeprecatedAncestorClassLegacy(): void + + public function testLegacyRenderMenuWithDeprecatedAncestorClass(): void { $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); $helper = $this->getHelperMock(['render']); From 9de5229e454402a3e217cf9f7e786e2a6368e8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 21:00:17 +0100 Subject: [PATCH 21/23] Add as annotation since CI don't recognize --- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index 1c65ab96..b7fbcb6f 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -43,6 +43,9 @@ public function testRenderMenuWithOptions(): void $this->assertEquals('

foobar

', $this->getTemplate('{{ knp_menu_render(menu, {"firstClass": "test"}) }}', $helper)->render(['menu' => $menu])); } + /** + * @group legacy + */ public function testLegacyRenderMenuWithDeprecatedAncestorClass(): void { $menu = $this->getMockBuilder(ItemInterface::class)->getMock(); From c42343b33c1f27f14ef0a73bb905416b0b9ac0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 21:02:09 +0100 Subject: [PATCH 22/23] Remove message since expects empty message for trait --- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index b7fbcb6f..80e14663 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -57,7 +57,7 @@ public function testLegacyRenderMenuWithDeprecatedAncestorClass(): void $this->getTemplate('{{ knp_menu_render(menu, {"ancestorClass": "test"}) }}', $helper)->render(['menu' => $menu, 'ancestorClass' => 'test']); - $this->expectDeprecation('Since knplabs/knp-menu 3.3: Using "ancestorClass" option is deprecated, use "ancestor_class" instead.'); + $this->expectDeprecation(); } public function testRenderMenuWithRenderer(): void From a4bc394b5147b77c89c840b7e8dd500b59666109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 26 Jan 2022 21:04:06 +0100 Subject: [PATCH 23/23] Add empty string message for deprecation instead null --- tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php index 80e14663..05cfe560 100644 --- a/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php +++ b/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php @@ -57,7 +57,7 @@ public function testLegacyRenderMenuWithDeprecatedAncestorClass(): void $this->getTemplate('{{ knp_menu_render(menu, {"ancestorClass": "test"}) }}', $helper)->render(['menu' => $menu, 'ancestorClass' => 'test']); - $this->expectDeprecation(); + $this->expectDeprecation(''); } public function testRenderMenuWithRenderer(): void