Skip to content
Snippets Groups Projects
Commit 7e8697b0 authored by jurgenhaas's avatar jurgenhaas
Browse files

Update core patch

parent ad1f378a
No related branches found
No related tags found
1 merge request!202Merging develop into main
Pipeline #1224853 passed with warnings
......@@ -87,7 +87,7 @@
"#3298701 Local patch to prevent BC issue in 10.3": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/3298701.diff",
"#3159113 Local patch to prevent BC issue in 10.3": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/3159113.diff",
"#3392903 Local patch to work around %formatter in custom_field": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/3392903-follow-up.diff",
"#2909185 Local patch to undo this core change until config_auto_export got adjusted": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/2909185.diff",
"#2909185 Local patch to undo this core change until config_auto_export got adjusted": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/2909185-2.diff",
"#3438893 Views entity reverse": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/d10/3438893.diff",
"#944582 File System Permissions": "https://www.drupal.org/files/issues/2024-01-16/944582-10.2.x-192.patch"
},
......
diff --git a/core/core.services.yml b/core/core.services.yml
index da5011df77..106db6a337 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -895,7 +895,8 @@ services:
arguments: ['@request_stack']
Drupal\Core\Routing\RouteMatchInterface: '@current_route_match'
event_dispatcher:
- class: Symfony\Component\EventDispatcher\EventDispatcher
+ class: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
+ arguments: ['@service_container']
Psr\EventDispatcher\EventDispatcherInterface: '@event_dispatcher'
Symfony\Contracts\EventDispatcher\EventDispatcherInterface: '@event_dispatcher'
controller_resolver:
diff --git a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
index fd99e0335e..41afec903e 100644
--- a/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
+++ b/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
@@ -2,8 +2,6 @@
namespace Drupal\Component\EventDispatcher;
-@trigger_error('The ' . __NAMESPACE__ . '\ContainerAwareEventDispatcher is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use Symfony\Component\EventDispatcher\EventDispatcher instead. See https://www.drupal.org/node/3376090', E_USER_DEPRECATED);
-
use Psr\EventDispatcher\StoppableEventInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -32,11 +30,6 @@
* runtime is not affected by this change though.
* </dd>
* </dl>
- *
- * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
- * \Symfony\Component\EventDispatcher\EventDispatcher instead.
- *
- * @see https://www.drupal.org/node/3376090
*/
class ContainerAwareEventDispatcher implements EventDispatcherInterface {
diff --git a/core/lib/Drupal/Core/CoreServiceProvider.php b/core/lib/Drupal/Core/CoreServiceProvider.php
index 20fd28594a..368692ba7b 100644
--- a/core/lib/Drupal/Core/CoreServiceProvider.php
+++ b/core/lib/Drupal/Core/CoreServiceProvider.php
@@ -30,7 +30,6 @@
use Psr\Log\LoggerAwareInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Reference;
-use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
@@ -86,7 +85,7 @@ public function register(ContainerBuilder $container) {
$container->addCompilerPass(new TwigExtensionPass());
// Add a compiler pass for registering event subscribers.
- $container->addCompilerPass(new RegisterEventSubscribersPass(new RegisterListenersPass()), PassConfig::TYPE_AFTER_REMOVING);
+ $container->addCompilerPass(new RegisterEventSubscribersPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new LoggerAwarePass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new RegisterAccessChecksPass());
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php
index 82d1f1614d..5fed449612 100644
--- a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php
@@ -4,10 +4,10 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
-use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
- * Wraps the Symfony event subscriber pass to use different tag names.
+ * Registers all event subscribers to the event dispatcher.
*/
class RegisterEventSubscribersPass implements CompilerPassInterface {
@@ -25,29 +25,48 @@ public function __construct(
* {@inheritdoc}
*/
public function process(ContainerBuilder $container) {
- $this->renameTag($container, 'event_subscriber', 'kernel.event_subscriber');
- $this->pass->process($container);
- $this->renameTag($container, 'kernel.event_subscriber', 'event_subscriber');
- }
+ if (!$container->hasDefinition('event_dispatcher')) {
+ return;
+ }
- /**
- * Renames tags in the container.
- *
- * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
- * The container.
- * @param string $source_tag
- * The tag to be renamed.
- * @param string $target_tag
- * The tag to rename with.
- */
- protected function renameTag(ContainerBuilder $container, string $source_tag, string $target_tag): void {
- foreach ($container->getDefinitions() as $definition) {
- if ($definition->hasTag($source_tag)) {
- $attributes = $definition->getTag($source_tag)[0];
- $definition->addTag($target_tag, $attributes);
- $definition->clearTag($source_tag);
+ $definition = $container->getDefinition('event_dispatcher');
+
+ $event_subscriber_info = [];
+ foreach ($container->findTaggedServiceIds('event_subscriber') as $id => $attributes) {
+
+ // We must assume that the class value has been correctly filled, even if
+ // the service is created by a factory.
+ $class = $container->getDefinition($id)->getClass();
+
+ $interface = EventSubscriberInterface::class;
+ if (!is_subclass_of($class, $interface)) {
+ throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
+ }
+
+ // Get all subscribed events.
+ foreach ($class::getSubscribedEvents() as $event_name => $params) {
+ if (is_string($params)) {
+ $priority = 0;
+ $event_subscriber_info[$event_name][$priority][] = ['service' => [$id, $params]];
+ }
+ elseif (is_string($params[0])) {
+ $priority = $params[1] ?? 0;
+ $event_subscriber_info[$event_name][$priority][] = ['service' => [$id, $params[0]]];
+ }
+ else {
+ foreach ($params as $listener) {
+ $priority = $listener[1] ?? 0;
+ $event_subscriber_info[$event_name][$priority][] = ['service' => [$id, $listener[0]]];
+ }
+ }
}
}
+
+ foreach (array_keys($event_subscriber_info) as $event_name) {
+ krsort($event_subscriber_info[$event_name]);
+ }
+
+ $definition->addArgument($event_subscriber_info);
}
}
diff --git a/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php b/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php
index 63c52f408c..de8ecb220f 100644
--- a/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php
+++ b/core/modules/layout_builder/tests/src/Unit/SectionRenderTest.php
@@ -4,6 +4,7 @@
namespace Drupal\Tests\layout_builder\Unit;
+use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Block\BlockManagerInterface;
@@ -23,7 +24,6 @@
use Drupal\layout_builder\SectionComponent;
use Drupal\Tests\UnitTestCase;
use Prophecy\Argument;
-use Symfony\Component\EventDispatcher\EventDispatcher;
/**
* @coversDefaultClass \Drupal\layout_builder\Section
@@ -62,7 +62,7 @@ class SectionRenderTest extends UnitTestCase {
/**
* The event dispatcher.
*
- * @var \Symfony\Component\EventDispatcher\EventDispatcher
+ * @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
*/
protected $eventDispatcher;
@@ -77,7 +77,7 @@ protected function setUp(): void {
$this->contextHandler = $this->prophesize(ContextHandlerInterface::class);
$this->contextRepository = $this->prophesize(ContextRepositoryInterface::class);
// @todo Refactor this into some better tests in https://www.drupal.org/node/2942605.
- $this->eventDispatcher = (new \ReflectionClass(EventDispatcher::class))->newInstanceWithoutConstructor();
+ $this->eventDispatcher = (new \ReflectionClass(ContainerAwareEventDispatcher::class))->newInstanceWithoutConstructor();
$this->account = $this->prophesize(AccountInterface::class);
$subscriber = new BlockComponentRenderArray($this->account->reveal());
diff --git a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
index 9ee42e3f70..a8fd9e87d6 100644
--- a/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
+++ b/core/tests/Drupal/Tests/Component/EventDispatcher/ContainerAwareEventDispatcherTest.php
@@ -25,7 +25,6 @@
* synchronizations.
*
* @group EventDispatcher
- * @group legacy
*/
class ContainerAwareEventDispatcherTest extends TestCase {
diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
index c567bc0398..94ced461bc 100644
--- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php
@@ -4,13 +4,13 @@
namespace Drupal\Tests\Core\EventSubscriber;
+use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher as EventDispatcher;
use Drupal\Core\EventSubscriber\RedirectResponseSubscriber;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Utility\UnroutedUrlAssemblerInterface;
use Drupal\Tests\UnitTestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Container;
-use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
@@ -87,7 +87,7 @@ protected function setUp(): void {
* @dataProvider providerTestDestinationRedirect
*/
public function testDestinationRedirect(Request $request, $expected) {
- $dispatcher = new EventDispatcher();
+ $dispatcher = new EventDispatcher(\Drupal::getContainer());
$kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new RedirectResponse('http://example.com/drupal');
$request->headers->set('HOST', 'example.com');
@@ -128,7 +128,7 @@ public static function providerTestDestinationRedirect() {
* @dataProvider providerTestDestinationRedirectToExternalUrl
*/
public function testDestinationRedirectToExternalUrl($request, $expected) {
- $dispatcher = new EventDispatcher();
+ $dispatcher = new EventDispatcher(\Drupal::getContainer());
$kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new RedirectResponse('http://other-example.com');
@@ -143,7 +143,7 @@ public function testDestinationRedirectToExternalUrl($request, $expected) {
* @covers ::checkRedirectUrl
*/
public function testRedirectWithOptInExternalUrl() {
- $dispatcher = new EventDispatcher();
+ $dispatcher = new EventDispatcher(\Drupal::getContainer());
$kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new TrustedRedirectResponse('http://external-url.com');
$request = Request::create('');
@@ -176,7 +176,7 @@ public static function providerTestDestinationRedirectToExternalUrl() {
* @dataProvider providerTestDestinationRedirectWithInvalidUrl
*/
public function testDestinationRedirectWithInvalidUrl(Request $request) {
- $dispatcher = new EventDispatcher();
+ $dispatcher = new EventDispatcher(\Drupal::getContainer());
$kernel = $this->createMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$response = new RedirectResponse('http://example.com/drupal');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment