Skip to content

Navigation Menu

Sign in
Appearance settings

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

[FrameworkBundle] Fixed form type extensions priority ordering #20993

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

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Expand All @@ -24,8 +23,6 @@
*/
class FormPass implements CompilerPassInterface
{
use PriorityTaggedServiceTrait;

public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('form.extension')) {
Expand All @@ -49,23 +46,34 @@ public function process(ContainerBuilder $container)

$definition->replaceArgument(1, $types);

$typeExtensions = array();
$typeExtensionsToSort = array();

foreach ($this->findAndSortTaggedServices('form.type_extension', $container) as $reference) {
$serviceId = (string) $reference;
foreach ($container->findTaggedServiceIds('form.type_extension') as $serviceId => $tag) {
$serviceDefinition = $container->getDefinition($serviceId);
if (!$serviceDefinition->isPublic()) {
throw new InvalidArgumentException(sprintf('The service "%s" must be public as form type extensions are lazy-loaded.', $serviceId));
}

$tag = $serviceDefinition->getTag('form.type_extension');
if (isset($tag[0]['extended_type'])) {
$extendedType = $tag[0]['extended_type'];
} else {
throw new InvalidArgumentException(sprintf('Tagged form type extension must have the extended type configured using the extended_type/extended-type attribute, none was configured for the "%s" service.', $serviceId));
}

$typeExtensions[$extendedType][] = $serviceId;
$typeExtensionsToSort[isset($tag[0]['priority']) ? $tag[0]['priority'] : 0][] = array(
'service_id' => $serviceId,
'extended_type' => $extendedType,
);
}

$typeExtensions = array();
if ($typeExtensionsToSort) {
krsort($typeExtensionsToSort);
$typeExtensionsSorted = call_user_func_array('array_merge', $typeExtensionsToSort);

foreach ($typeExtensionsSorted as $typeExtension) {
$typeExtensions[$typeExtension['extended_type']][] = $typeExtension['service_id'];
}
}

$definition->replaceArgument(2, $typeExtensions);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.