Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Remove deprecated code #41318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Form/ButtonBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function getFormConfig()
*
* @throws BadMethodCallException
*/
public function setIsEmptyCallback(?callable $isEmptyCallback)
public function setIsEmptyCallback(?callable $isEmptyCallback): static
{
throw new BadMethodCallException('Buttons do not support "is empty" callback.');
}
Expand Down
14 changes: 14 additions & 0 deletions 14 src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
CHANGELOG
=========

6.0
---

* Remove `PropertyPathMaper`
* Remove `Symfony\Component\Form\Extension\Validator\Util\ServiceParams`
* Remove `FormPass` configuration
* Add `FormConfigInterface::getIsEmptyCallback()` and `FormConfigBuilderInterface::setIsEmptyCallback()`
* Change `$forms` parameter type of the `DataMapper::mapDataToForms()` method from `iterable` to `\Traversable`
* Change `$forms` parameter type of the `DataMapper::mapFormsToData()` method from `iterable` to `\Traversable`
* Change `$checkboxes` parameter type of the `CheckboxListMapper::mapDataToForms()` method from `iterable` to `\Traversable`
* Change `$checkboxes` parameter type of the `CheckboxListMapper::mapFormsToData()` method from `iterable` to `\Traversable`
* Change `$radios` parameter type of the `RadioListMapper::mapDataToForms()` method from `iterable` to `\Traversable`
* Change `$radios` parameter type of the `RadioListMapper::mapFormsToData()` method from `iterable` to `\Traversable`

5.3
---

Expand Down
43 changes: 12 additions & 31 deletions 43 src/Symfony/Component/Form/DependencyInjection/FormPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,13 @@ class FormPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

private $formExtensionService;
private $formTypeTag;
private $formTypeExtensionTag;
private $formTypeGuesserTag;
private $formDebugCommandService;

public function __construct(string $formExtensionService = 'form.extension', string $formTypeTag = 'form.type', string $formTypeExtensionTag = 'form.type_extension', string $formTypeGuesserTag = 'form.type_guesser', string $formDebugCommandService = 'console.command.form_debug')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->formExtensionService = $formExtensionService;
$this->formTypeTag = $formTypeTag;
$this->formTypeExtensionTag = $formTypeExtensionTag;
$this->formTypeGuesserTag = $formTypeGuesserTag;
$this->formDebugCommandService = $formDebugCommandService;
}

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition($this->formExtensionService)) {
if (!$container->hasDefinition('form.extension')) {
return;
}

$definition = $container->getDefinition($this->formExtensionService);
$definition = $container->getDefinition('form.extension');
$definition->replaceArgument(0, $this->processFormTypes($container));
$definition->replaceArgument(1, $this->processFormTypeExtensions($container));
$definition->replaceArgument(2, $this->processFormTypeGuessers($container));
Expand All @@ -68,15 +49,15 @@ private function processFormTypes(ContainerBuilder $container): Reference
$namespaces = ['Symfony\Component\Form\Extension\Core\Type' => true];

// Builds an array with fully-qualified type class names as keys and service IDs as values
foreach ($container->findTaggedServiceIds($this->formTypeTag, true) as $serviceId => $tag) {
foreach ($container->findTaggedServiceIds('form.type', true) as $serviceId => $tag) {
// Add form type service to the service locator
$serviceDefinition = $container->getDefinition($serviceId);
$servicesMap[$formType = $serviceDefinition->getClass()] = new Reference($serviceId);
$namespaces[substr($formType, 0, strrpos($formType, '\\'))] = true;
}

if ($container->hasDefinition($this->formDebugCommandService)) {
$commandDefinition = $container->getDefinition($this->formDebugCommandService);
if ($container->hasDefinition('console.command.form_debug')) {
$commandDefinition = $container->getDefinition('console.command.form_debug');
$commandDefinition->setArgument(1, array_keys($namespaces));
$commandDefinition->setArgument(2, array_keys($servicesMap));
}
Expand All @@ -88,11 +69,11 @@ private function processFormTypeExtensions(ContainerBuilder $container): array
{
$typeExtensions = [];
$typeExtensionsClasses = [];
foreach ($this->findAndSortTaggedServices($this->formTypeExtensionTag, $container) as $reference) {
foreach ($this->findAndSortTaggedServices('form.type_extension', $container) as $reference) {
$serviceId = (string) $reference;
$serviceDefinition = $container->getDefinition($serviceId);

$tag = $serviceDefinition->getTag($this->formTypeExtensionTag);
$tag = $serviceDefinition->getTag('form.type_extension');
$typeExtensionClass = $container->getParameterBag()->resolveValue($serviceDefinition->getClass());

if (isset($tag[0]['extended_type'])) {
Expand All @@ -117,8 +98,8 @@ private function processFormTypeExtensions(ContainerBuilder $container): array
$typeExtensions[$extendedType] = new IteratorArgument($extensions);
}

if ($container->hasDefinition($this->formDebugCommandService)) {
$commandDefinition = $container->getDefinition($this->formDebugCommandService);
if ($container->hasDefinition('console.command.form_debug')) {
$commandDefinition = $container->getDefinition('console.command.form_debug');
$commandDefinition->setArgument(3, $typeExtensionsClasses);
}

Expand All @@ -129,15 +110,15 @@ private function processFormTypeGuessers(ContainerBuilder $container): ArgumentI
{
$guessers = [];
$guessersClasses = [];
foreach ($container->findTaggedServiceIds($this->formTypeGuesserTag, true) as $serviceId => $tags) {
foreach ($container->findTaggedServiceIds('form.type_guesser', true) as $serviceId => $tags) {
$guessers[] = new Reference($serviceId);

$serviceDefinition = $container->getDefinition($serviceId);
$guessersClasses[] = $serviceDefinition->getClass();
}

if ($container->hasDefinition($this->formDebugCommandService)) {
$commandDefinition = $container->getDefinition($this->formDebugCommandService);
if ($container->hasDefinition('console.command.form_debug')) {
$commandDefinition = $container->getDefinition('console.command.form_debug');
$commandDefinition->setArgument(4, $guessersClasses);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ class CheckboxListMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapDataToForms($choices, iterable $checkboxes)
public function mapDataToForms($choices, \Traversable $checkboxes)
{
if (\is_array($checkboxes)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (null === $choices) {
$choices = [];
}
Expand All @@ -51,12 +47,8 @@ public function mapDataToForms($choices, iterable $checkboxes)
/**
* {@inheritdoc}
*/
public function mapFormsToData(iterable $checkboxes, &$choices)
public function mapFormsToData(\Traversable $checkboxes, &$choices)
{
if (\is_array($checkboxes)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (!\is_array($choices)) {
throw new UnexpectedTypeException($choices, 'array');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ public function __construct(DataAccessorInterface $dataAccessor = null)
/**
* {@inheritdoc}
*/
public function mapDataToForms($data, iterable $forms): void
public function mapDataToForms($data, \Traversable $forms): void
{
if (\is_array($forms)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

$empty = null === $data || [] === $data;

if (!$empty && !\is_array($data) && !\is_object($data)) {
Expand All @@ -64,12 +60,8 @@ public function mapDataToForms($data, iterable $forms): void
/**
* {@inheritdoc}
*/
public function mapFormsToData(iterable $forms, &$data): void
public function mapFormsToData(\Traversable $forms, &$data): void
{
if (\is_array($forms)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (null === $data) {
return;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RadioListMapper implements DataMapperInterface
/**
* {@inheritdoc}
*/
public function mapDataToForms($choice, iterable $radios)
public function mapDataToForms($choice, \Traversable $radios)
{
if (\is_array($radios)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the second argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
Expand All @@ -47,12 +47,8 @@ public function mapDataToForms($choice, iterable $radios)
/**
* {@inheritdoc}
*/
public function mapFormsToData(iterable $radios, &$choice)
public function mapFormsToData(\Traversable $radios, &$choice)
{
if (\is_array($radios)) {
trigger_deprecation('symfony/form', '5.3', 'Passing an array as the first argument of the "%s()" method is deprecated, pass "\Traversable" instead.', __METHOD__);
}

if (null !== $choice && !\is_string($choice)) {
throw new UnexpectedTypeException($choice, 'null or string');
}
Expand Down
7 changes: 0 additions & 7 deletions 7 src/Symfony/Component/Form/Extension/Core/Type/FormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
use Symfony\Component\Form\Extension\Core\EventListener\TrimListener;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormConfigBuilderInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\Options;
Expand Down Expand Up @@ -66,12 +65,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->addEventSubscriber(new TrimListener());
}

if (!method_exists($builder, 'setIsEmptyCallback')) {
trigger_deprecation('symfony/form', '5.1', 'Not implementing the "%s::setIsEmptyCallback()" method in "%s" is deprecated.', FormConfigBuilderInterface::class, get_debug_type($builder));

return;
}

$builder->setIsEmptyCallback($options['is_empty_callback']);
}

Expand Down

This file was deleted.

10 changes: 1 addition & 9 deletions 10 src/Symfony/Component/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,7 @@ public function isEmpty()
}
}

if (!method_exists($this->config, 'getIsEmptyCallback')) {
trigger_deprecation('symfony/form', '5.1', 'Not implementing the "%s::getIsEmptyCallback()" method in "%s" is deprecated.', FormConfigInterface::class, \get_class($this->config));

$isEmptyCallback = null;
} else {
$isEmptyCallback = $this->config->getIsEmptyCallback();
}

if (null !== $isEmptyCallback) {
if (null !== $isEmptyCallback = $this->config->getIsEmptyCallback()) {
return $isEmptyCallback($this->modelData);
}

Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Form/FormConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ public function getFormConfig()
/**
* {@inheritdoc}
*/
public function setIsEmptyCallback(?callable $isEmptyCallback)
public function setIsEmptyCallback(?callable $isEmptyCallback): static
{
$this->isEmptyCallback = $isEmptyCallback;

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.