Skip to content

Commit cafa8a1

Browse files
committed
Drop support for sonata-project/form-extensions v1
1 parent ede291e commit cafa8a1

7 files changed

Lines changed: 24 additions & 319 deletions

File tree

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
"sonata-project/block-bundle": "^5.0",
3535
"sonata-project/doctrine-extensions": "^2.0",
3636
"sonata-project/exporter": "^3.1.1",
37-
"sonata-project/form-extensions": "^1.15 || ^2.0",
37+
"sonata-project/form-extensions": "^2.0",
3838
"sonata-project/twig-extensions": "^2.0",
3939
"symfony/asset": "^6.4 || ^7.1",
4040
"symfony/config": "^6.4 || ^7.1",
4141
"symfony/console": "^6.4 || ^7.1",
4242
"symfony/dependency-injection": "^6.4 || ^7.1",
43+
"symfony/deprecation-contracts": "^3.6",
4344
"symfony/doctrine-bridge": "^6.4 || ^7.1",
4445
"symfony/event-dispatcher": "^6.4 || ^7.1",
4546
"symfony/event-dispatcher-contracts": "^2.0 || ^3.0",

src/Resources/config/twig.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@
153153
->tag('twig.runtime')
154154
->args([
155155
service('request_stack'),
156-
// TODO: Remove this argument when dropping support for `sonata-project/form-extensions` 1.x.
157-
service('sonata.form.twig.canonicalize_runtime')->nullOnInvalid(),
158156
])
159157

160158
// NEXT_MAJOR: Remove the `args()` call.

src/Resources/views/standard_layout.html.twig

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,6 @@ file that was distributed with this source code.
6464
{% endfor %}
6565
{% endblock %}
6666

67-
{# TODO: Drop locale for moment calls when dropping support for `sonata-project/form-extensions` 1.x #}
68-
{# localize moment #}
69-
{% set localeForMoment = canonicalize_locale_for_moment() %}
70-
{% if localeForMoment %}
71-
<script src="{{ asset('bundles/sonataform/moment-locale/' ~ localeForMoment ~ '.js', 'sonata_admin') }}"></script>
72-
{% endif %}
73-
7467
{# localize select2 #}
7568
{% if sonata_config.getOption('use_select2') %}
7669
{% set localeForSelect2 = canonicalize_locale_for_select2() %}

src/Twig/CanonicalizeRuntime.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,35 @@
1313

1414
namespace Sonata\AdminBundle\Twig;
1515

16-
use Sonata\Form\Twig\CanonicalizeRuntime as SonataFormCanonicalizeRuntime;
1716
use Symfony\Component\HttpFoundation\RequestStack;
1817
use Twig\Extension\RuntimeExtensionInterface;
1918

20-
/** @psalm-suppress UndefinedClass */
2119
final class CanonicalizeRuntime implements RuntimeExtensionInterface
2220
{
2321
/**
24-
* TODO: Remove second argument when dropping support for `sonata-project/form-extensions` 1.x.
25-
*
2622
* @internal This class should only be used through Twig
2723
*/
28-
public function __construct(
29-
private RequestStack $requestStack,
30-
private ?SonataFormCanonicalizeRuntime $canonicalizeRuntime = null, // @phpstan-ignore-line
31-
) {
24+
public function __construct(private RequestStack $requestStack)
25+
{
3226
}
3327

3428
/**
3529
* NEXT_MAJOR: Remove this method.
3630
*
37-
* Returns a canonicalized locale for "Moment.js" NPM library,
38-
* or `null` if the locale's language is "en", which doesn't require localization.
31+
* @deprecated since sonata-project/admin-bundle 4.40.0
32+
*
33+
* @phpstan-ignore return.unusedType
3934
*/
4035
public function getCanonicalizedLocaleForMoment(): ?string
4136
{
42-
if (null === $this->canonicalizeRuntime) {
43-
return null;
44-
}
37+
trigger_deprecation(
38+
'sonata-project/admin-bundle',
39+
'4.40.0',
40+
'Method "%s" is deprecated and no-op. It always returns null.',
41+
__METHOD__,
42+
);
4543

46-
// @phpstan-ignore-next-line
47-
return $this->canonicalizeRuntime->getCanonicalizedLocaleForMoment();
44+
return null;
4845
}
4946

5047
/**

src/Twig/Extension/CanonicalizeExtension.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,20 @@ public function getFunctions(): array
4343
/**
4444
* NEXT_MAJOR: Remove this method.
4545
*
46-
* @deprecated since sonata-project/admin-bundle version 4.7 use CanonicalizeRuntime::getCanonicalizedLocaleForMoment() instead
46+
* @deprecated since sonata-project/admin-bundle version 4.7
4747
*
48-
* Returns a canonicalized locale for "moment" NPM library,
49-
* or `null` if the locale's language is "en", which doesn't require localization.
48+
* @phpstan-ignore return.unusedType
5049
*/
5150
public function getCanonicalizedLocaleForMoment(): ?string
5251
{
53-
@trigger_error(\sprintf(
54-
'The method "%s()" is deprecated since sonata-project/admin-bundle 4.7 and will be removed in 5.0.'
55-
.' Use "%s::%s()" instead.',
52+
trigger_deprecation(
53+
'sonata-project/admin-bundle',
54+
'4.7.0',
55+
'Method "%s" is deprecated and no-op. It always returns null.',
5656
__METHOD__,
57-
CanonicalizeRuntime::class,
58-
__FUNCTION__
59-
), \E_USER_DEPRECATED);
57+
);
6058

61-
return $this->canonicalizeRuntime->getCanonicalizedLocaleForMoment();
59+
return null;
6260
}
6361

6462
/**

tests/Twig/CanonicalizeRuntimeTest.php

Lines changed: 1 addition & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
namespace Sonata\AdminBundle\Tests\Twig;
1515

1616
use PHPUnit\Framework\Attributes\DataProvider;
17-
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
1817
use PHPUnit\Framework\TestCase;
1918
use Sonata\AdminBundle\Twig\CanonicalizeRuntime;
20-
use Sonata\Form\Twig\CanonicalizeRuntime as SonataFormCanonicalizeRuntime;
2119
use Symfony\Component\HttpFoundation\Request;
2220
use Symfony\Component\HttpFoundation\RequestStack;
2321

@@ -32,24 +30,7 @@ protected function setUp(): void
3230
$this->request = new Request();
3331
$requestStack = new RequestStack();
3432
$requestStack->push($this->request);
35-
$this->canonicalizeRuntime = new CanonicalizeRuntime(
36-
$requestStack,
37-
class_exists(SonataFormCanonicalizeRuntime::class) ? new SonataFormCanonicalizeRuntime($requestStack) : null,
38-
);
39-
}
40-
41-
/**
42-
* NEXT_MAJOR: Remove this test.
43-
*/
44-
#[DataProvider('provideCanonicalizedLocaleForMomentCases')]
45-
#[IgnoreDeprecations]
46-
public function testCanonicalizedLocaleForMoment(?string $expected, string $original): void
47-
{
48-
$this->changeLocale($original);
49-
50-
$expected = class_exists(SonataFormCanonicalizeRuntime::class) ? $expected : null;
51-
52-
static::assertSame($expected, $this->canonicalizeRuntime->getCanonicalizedLocaleForMoment());
33+
$this->canonicalizeRuntime = new CanonicalizeRuntime($requestStack);
5334
}
5435

5536
#[DataProvider('provideCanonicalizedLocaleForSelect2Cases')]
@@ -59,130 +40,6 @@ public function testCanonicalizedLocaleForSelect2(?string $expected, string $ori
5940
static::assertSame($expected, $this->canonicalizeRuntime->getCanonicalizedLocaleForSelect2());
6041
}
6142

62-
/**
63-
* NEXT_MAJOR: Remove this function.
64-
*
65-
* @return iterable<array{string|null, string}>
66-
*/
67-
public static function provideCanonicalizedLocaleForMomentCases(): iterable
68-
{
69-
yield ['af', 'af'];
70-
yield ['ar-dz', 'ar-dz'];
71-
yield ['ar', 'ar'];
72-
yield ['ar-ly', 'ar-ly'];
73-
yield ['ar-ma', 'ar-ma'];
74-
yield ['ar-sa', 'ar-sa'];
75-
yield ['ar-tn', 'ar-tn'];
76-
yield ['az', 'az'];
77-
yield ['be', 'be'];
78-
yield ['bg', 'bg'];
79-
yield ['bn', 'bn'];
80-
yield ['bo', 'bo'];
81-
yield ['br', 'br'];
82-
yield ['bs', 'bs'];
83-
yield ['ca', 'ca'];
84-
yield ['cs', 'cs'];
85-
yield ['cv', 'cv'];
86-
yield ['cy', 'cy'];
87-
yield ['da', 'da'];
88-
yield ['de-at', 'de-at'];
89-
yield ['de', 'de'];
90-
yield ['de', 'de-de'];
91-
yield ['dv', 'dv'];
92-
yield ['el', 'el'];
93-
yield [null, 'en'];
94-
yield [null, 'en-us'];
95-
yield ['en-au', 'en-au'];
96-
yield ['en-ca', 'en-ca'];
97-
yield ['en-gb', 'en-gb'];
98-
yield ['en-ie', 'en-ie'];
99-
yield ['en-nz', 'en-nz'];
100-
yield ['eo', 'eo'];
101-
yield ['es-do', 'es-do'];
102-
yield ['es', 'es-ar'];
103-
yield ['es', 'es-mx'];
104-
yield ['es', 'es'];
105-
yield ['et', 'et'];
106-
yield ['eu', 'eu'];
107-
yield ['fa', 'fa'];
108-
yield ['fi', 'fi'];
109-
yield ['fo', 'fo'];
110-
yield ['fr-ca', 'fr-ca'];
111-
yield ['fr-ch', 'fr-ch'];
112-
yield ['fr', 'fr-fr'];
113-
yield ['fr', 'fr'];
114-
yield ['fy', 'fy'];
115-
yield ['gd', 'gd'];
116-
yield ['gl', 'gl'];
117-
yield ['he', 'he'];
118-
yield ['hi', 'hi'];
119-
yield ['hr', 'hr'];
120-
yield ['hu', 'hu'];
121-
yield ['hy-am', 'hy-am'];
122-
yield ['id', 'id'];
123-
yield ['is', 'is'];
124-
yield ['it', 'it'];
125-
yield ['ja', 'ja'];
126-
yield ['jv', 'jv'];
127-
yield ['ka', 'ka'];
128-
yield ['kk', 'kk'];
129-
yield ['km', 'km'];
130-
yield ['ko', 'ko'];
131-
yield ['ky', 'ky'];
132-
yield ['lb', 'lb'];
133-
yield ['lo', 'lo'];
134-
yield ['lt', 'lt'];
135-
yield ['lv', 'lv'];
136-
yield ['me', 'me'];
137-
yield ['mi', 'mi'];
138-
yield ['mk', 'mk'];
139-
yield ['ml', 'ml'];
140-
yield ['mr', 'mr'];
141-
yield ['ms', 'ms'];
142-
yield ['ms-my', 'ms-my'];
143-
yield ['my', 'my'];
144-
yield ['nb', 'nb'];
145-
yield ['ne', 'ne'];
146-
yield ['nl-be', 'nl-be'];
147-
yield ['nl', 'nl'];
148-
yield ['nl', 'nl-nl'];
149-
yield ['nn', 'nn'];
150-
yield ['pa-in', 'pa-in'];
151-
yield ['pl', 'pl'];
152-
yield ['pt-br', 'pt-br'];
153-
yield ['pt', 'pt'];
154-
yield ['ro', 'ro'];
155-
yield ['ru', 'ru'];
156-
yield ['se', 'se'];
157-
yield ['si', 'si'];
158-
yield ['sk', 'sk'];
159-
yield ['sl', 'sl'];
160-
yield ['sq', 'sq'];
161-
yield ['sr-cyrl', 'sr-cyrl'];
162-
yield ['sr', 'sr'];
163-
yield ['ss', 'ss'];
164-
yield ['sv', 'sv'];
165-
yield ['sw', 'sw'];
166-
yield ['ta', 'ta'];
167-
yield ['te', 'te'];
168-
yield ['tet', 'tet'];
169-
yield ['th', 'th'];
170-
yield ['tlh', 'tlh'];
171-
yield ['tl-ph', 'tl-ph'];
172-
yield ['tr', 'tr'];
173-
yield ['tzl', 'tzl'];
174-
yield ['tzm', 'tzm'];
175-
yield ['tzm-latn', 'tzm-latn'];
176-
yield ['uk', 'uk'];
177-
yield ['uz', 'uz'];
178-
yield ['vi', 'vi'];
179-
yield ['x-pseudo', 'x-pseudo'];
180-
yield ['yo', 'yo'];
181-
yield ['zh-cn', 'zh-cn'];
182-
yield ['zh-hk', 'zh-hk'];
183-
yield ['zh-tw', 'zh-tw'];
184-
}
185-
18643
/**
18744
* @return iterable<array{string|null, string}>
18845
*/

0 commit comments

Comments
 (0)