diff --git a/src/TwigComponent/config/debug.php b/src/TwigComponent/config/debug.php index 6afabb82245..9e7712d4136 100644 --- a/src/TwigComponent/config/debug.php +++ b/src/TwigComponent/config/debug.php @@ -15,6 +15,7 @@ use Symfony\UX\TwigComponent\DataCollector\TwigComponentDataCollector; use Symfony\UX\TwigComponent\EventListener\TwigComponentLoggerListener; +use function Symfony\Component\DependencyInjection\Loader\Configurator\param; use function Symfony\Component\DependencyInjection\Loader\Configurator\service; return static function (ContainerConfigurator $container) { @@ -27,6 +28,7 @@ ->args([ service('ux.twig_component.component_logger_listener'), service('twig'), + param('ux.twig_component.profiler_dump_components'), ]) ->tag('data_collector', [ 'template' => '@TwigComponent/Collector/twig_component.html.twig', diff --git a/src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php b/src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php index 1ee94c71bdb..e3317f8802f 100644 --- a/src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php +++ b/src/TwigComponent/src/DataCollector/TwigComponentDataCollector.php @@ -35,6 +35,7 @@ final class TwigComponentDataCollector extends AbstractDataCollector implements public function __construct( private readonly TwigComponentLoggerListener $logger, private readonly Environment $twig, + private readonly bool $dumpComponents = true, ) { $this->hasStub = class_exists(ClassStub::class); } @@ -130,12 +131,15 @@ private function collectDataFromLogger(): void 'input_props' => $mountedComponent->getInputProps(), 'attributes' => $mountedComponent->getAttributes()->all(), 'template_index' => $event->getTemplateIndex(), - 'component' => $mountedComponent->getComponent(), 'depth' => \count($ongoingRenders), 'children' => [], 'render_start' => $profile[0], ]; + if ($this->dumpComponents) { + $renders[$renderId]['component'] = $mountedComponent->getComponent(); + } + if ($parentId = end($ongoingRenders)) { $renders[$parentId]['children'][] = $renderId; } diff --git a/src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php b/src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php index dc71c610931..b5f248c2f1d 100644 --- a/src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php +++ b/src/TwigComponent/src/DependencyInjection/TwigComponentExtension.php @@ -69,6 +69,7 @@ public function load(array $configs, ContainerBuilder $container): void $defaults = []; } $container->setParameter('ux.twig_component.component_defaults', $defaults); + $container->setParameter('ux.twig_component.profiler_dump_components', $config['profiler_dump_components']); $container->register('ux.twig_component.component_template_finder', ComponentTemplateFinder::class) ->setArguments([ @@ -219,6 +220,10 @@ public function getConfigTreeBuilder(): TreeBuilder ->info('Enables the profiler for Twig Component (in debug mode)') ->defaultValue('%kernel.debug%') ->end() + ->booleanNode('profiler_dump_components') + ->info('Enables the dump components for Twig Component (in debug mode)') + ->defaultValue('%kernel.debug%') + ->end() ->scalarNode('controllers_json') ->setDeprecated('symfony/ux-twig-component', '2.18', 'The "twig_component.controllers_json" config option is deprecated, and will be removed in 3.0.') ->defaultNull() diff --git a/src/TwigComponent/templates/Collector/twig_component.html.twig b/src/TwigComponent/templates/Collector/twig_component.html.twig index c2098156f22..7bd88387fbc 100644 --- a/src/TwigComponent/templates/Collector/twig_component.html.twig +++ b/src/TwigComponent/templates/Collector/twig_component.html.twig @@ -293,10 +293,12 @@ Attributes {{ profiler_dump(render.attributes) }} + {% if render.component is defined %} Component {{ profiler_dump(render.component) }} + {% endif %} {% endfor %}