mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
[Core] Remove LocaleTypeExtension
This commit is contained in:
parent
f45e02a51a
commit
37d3c84a0d
3 changed files with 0 additions and 94 deletions
|
|
@ -3620,11 +3620,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/Sylius/Bundle/CoreBundle/Form/EventSubscriber/CustomerRegistrationFormSubscriber.php
|
||||
|
||||
-
|
||||
message: "#^Method Sylius\\\\Bundle\\\\CoreBundle\\\\Form\\\\Extension\\\\LocaleTypeExtension\\:\\:__construct\\(\\) has parameter \\$localeRepository with generic interface Sylius\\\\Component\\\\Resource\\\\Repository\\\\RepositoryInterface but does not specify its types\\: T$#"
|
||||
count: 1
|
||||
path: src/Sylius/Bundle/CoreBundle/Form/Extension/LocaleTypeExtension.php
|
||||
|
||||
-
|
||||
message: "#^Method Sylius\\\\Bundle\\\\CoreBundle\\\\Form\\\\Type\\\\CatalogPromotionScope\\\\ForProductsScopeConfigurationType\\:\\:__construct\\(\\) has parameter \\$productsToCodesTransformer with generic interface Symfony\\\\Component\\\\Form\\\\DataTransformerInterface but does not specify its types\\: T, R$#"
|
||||
count: 1
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\CoreBundle\Form\Extension;
|
||||
|
||||
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleType;
|
||||
use Sylius\Component\Locale\Model\LocaleInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Intl\Locales;
|
||||
|
||||
trigger_deprecation(
|
||||
'sylius/core-bundle',
|
||||
'1.14',
|
||||
'The "%s" class is deprecated and will be removed in Sylius 2.0.',
|
||||
LocaleTypeExtension::class,
|
||||
);
|
||||
|
||||
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
|
||||
final class LocaleTypeExtension extends AbstractTypeExtension
|
||||
{
|
||||
public function __construct(private RepositoryInterface $localeRepository)
|
||||
{
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
|
||||
$options = [
|
||||
'label' => 'sylius.form.locale.name',
|
||||
'choice_loader' => null,
|
||||
];
|
||||
|
||||
$locale = $event->getData();
|
||||
if ($locale instanceof LocaleInterface && null !== $locale->getCode()) {
|
||||
$options['disabled'] = true;
|
||||
|
||||
$options['choices'] = [$this->getLocaleName($locale->getCode()) => $locale->getCode()];
|
||||
} else {
|
||||
$options['choices'] = array_flip($this->getAvailableLocales());
|
||||
}
|
||||
|
||||
$form = $event->getForm();
|
||||
$form->add('code', \Symfony\Component\Form\Extension\Core\Type\LocaleType::class, $options);
|
||||
});
|
||||
}
|
||||
|
||||
public static function getExtendedTypes(): iterable
|
||||
{
|
||||
return [LocaleType::class];
|
||||
}
|
||||
|
||||
private function getLocaleName(string $code): string
|
||||
{
|
||||
return Locales::getName($code);
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private function getAvailableLocales(): array
|
||||
{
|
||||
$availableLocales = Locales::getNames();
|
||||
|
||||
/** @var LocaleInterface[] $definedLocales */
|
||||
$definedLocales = $this->localeRepository->findAll();
|
||||
|
||||
foreach ($definedLocales as $locale) {
|
||||
unset($availableLocales[$locale->getCode()]);
|
||||
}
|
||||
|
||||
return $availableLocales;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,10 +70,6 @@
|
|||
<service id="sylius.form.extension.type.channel" class="Sylius\Bundle\CoreBundle\Form\Extension\ChannelTypeExtension">
|
||||
<tag name="form.type_extension" extended-type="Sylius\Bundle\ChannelBundle\Form\Type\ChannelType" priority="100" />
|
||||
</service>
|
||||
<service id="sylius.form.extension.type.locale" class="Sylius\Bundle\CoreBundle\Form\Extension\LocaleTypeExtension">
|
||||
<argument type="service" id="sylius.repository.locale" />
|
||||
<tag name="form.type_extension" extended-type="Sylius\Bundle\LocaleBundle\Form\Type\LocaleType" priority="100" />
|
||||
</service>
|
||||
<service id="sylius.form.extension.type.order" class="Sylius\Bundle\CoreBundle\Form\Extension\OrderTypeExtension">
|
||||
<tag name="form.type_extension" extended-type="Sylius\Bundle\OrderBundle\Form\Type\OrderType" priority="100" />
|
||||
</service>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue