Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\UX\LiveComponent\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

final class AddControllerTagToLiveComponentPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
foreach ($container->findTaggedServiceIds('twig.component') as $id => $component) {
if (!($component[0]['live'] ?? false)) {
continue;
}

$definition = $container->getDefinition($id);

if (!$definition->hasTag('controller.service_arguments')) {
$definition->addTag('controller.service_arguments');
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public function load(array $configs, ContainerBuilder $container): void
function (ChildDefinition $definition, AsLiveComponent $attribute) {
$definition
->addTag('twig.component', array_filter($attribute->serviceConfig(), static fn ($v) => null !== $v && '' !== $v))
->addTag('controller.service_arguments')
;
}
);
Expand Down
2 changes: 2 additions & 0 deletions src/LiveComponent/src/LiveComponentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\UX\LiveComponent\DependencyInjection\Compiler\AddControllerTagToLiveComponentPass;
use Symfony\UX\LiveComponent\DependencyInjection\Compiler\ComponentDefaultActionPass;
use Symfony\UX\LiveComponent\DependencyInjection\Compiler\OptionalDependencyPass;

Expand All @@ -28,6 +29,7 @@ public function build(ContainerBuilder $container): void
{
// must run before Symfony\Component\Serializer\DependencyInjection\SerializerPass
$container->addCompilerPass(new OptionalDependencyPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 100);
$container->addCompilerPass(new AddControllerTagToLiveComponentPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 1);
$container->addCompilerPass(new ComponentDefaultActionPass());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public function attributesForRendering(MountedComponent $mounted, ComponentMetad
$attributesCollection = $this->attributeHelper->create();
$attributesCollection->setLiveController($mounted->getName());

$url = $this->urlGenerator->generate($metadata->get('route'), ['_live_component' => $mounted->getName()], $metadata->get('url_reference_type'));
$url = $this->urlGenerator->generate(
$metadata->get('route') ?? 'ux_live_component',
['_live_component' => $mounted->getName()],
$metadata->get('url_reference_type') ?? UrlGeneratorInterface::ABSOLUTE_PATH
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Author

@FabienSalles FabienSalles Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the question (since I explained why in the PR description).

If we manually declare the service in the YAML file, we have to provide this additional information.

These default internal values ​​are precisely designed to prevent this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i missclicked on the line apparently.. i was asking about the AbsolutePath as default

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I use the same defaults values as the attribute, visible here : https://github.com/symfony/ux/blob/2.x/src/LiveComponent/src/Attribute/AsLiveComponent.php#L51

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method:POST is also mandatory in some cases

);
$attributesCollection->setUrl($url);

$liveListeners = AsLiveComponent::liveListeners($mounted->getComponent());
Expand Down
Loading