Skip to content

Commit

Permalink
Merge branch '4.13' into 5.3
Browse files Browse the repository at this point in the history
# Conflicts:
#	core-bundle/src/Resources/config/migrations.yml
#	core-bundle/src/Resources/contao/library/Contao/InsertTags.php
  • Loading branch information
leofeyer committed May 7, 2024
2 parents 53a970e + d26e0ce commit feea078
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace Contao\CoreBundle\DependencyInjection\Compiler;

use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -52,6 +53,10 @@ private function getCallbacks(ContainerBuilder $container): array
$definition = $container->findDefinition($serviceId);
$definition->setPublic(true);

while (!$definition->getClass() && $definition instanceof ChildDefinition) {
$definition = $container->findDefinition($definition->getParent());
}

foreach ($tags as $attributes) {
$this->addCallback($callbacks, $serviceId, $definition->getClass(), $attributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Contao\CoreBundle\Fixtures\EventListener\TestListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;

Expand Down Expand Up @@ -55,6 +56,51 @@ public function testRegistersTheHookListeners(): void
);
}

public function testResolvesChildDefinitions(): void
{
$definition = new Definition(TestListener::class);
$definition->addTag('contao.callback', [
'table' => 'tl_module',
'target' => 'fields.imageSize.options',
'method' => 'onOptions',
]);

$childDefinition = new ChildDefinition('test.parent.listener');
$childDefinition->addTag('contao.callback', [
'table' => 'tl_module',
'target' => 'fields.otherField.options',
'method' => 'onOptions',
]);

$container = $this->getContainerBuilder();
$container->setDefinition('test.parent.listener', $definition);
$container->setDefinition('test.child.listener', $childDefinition);

$pass = new DataContainerCallbackPass();
$pass->process($container);

$this->assertSame(
[
'tl_module' => [
'fields.imageSize.options_callback' => [
[
['test.parent.listener', 'onOptions'],
],
],
'fields.otherField.options_callback' => [
[
['test.child.listener', 'onOptions'],
],
],
],
],
$this->getCallbacksFromDefinition($container)[0],
);

$this->assertTrue($container->findDefinition('test.parent.listener')->isPublic());
$this->assertTrue($container->findDefinition('test.child.listener')->isPublic());
}

public function testMakesHookListenersPublic(): void
{
$attributes = [
Expand Down
5 changes: 5 additions & 0 deletions core-bundle/tests/Fixtures/src/EventListener/TestListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public function onLoadFirst(): void
{
}

public function onOptions(): array
{
return [];
}

public function onLoadSecond(): void
{
}
Expand Down

0 comments on commit feea078

Please sign in to comment.