diff --git a/composer.json b/composer.json index 28c38666..aefecf50 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "source": "https://git.drupalcode.org/project/rules" }, "require": { - "drupal/core": "^9 || ^10", + "drupal/core": "^9.1 || ^10", "drupal/typed_data": "^1.0" }, "minimum-stability": "dev", diff --git a/rules.info.yml b/rules.info.yml index 10bd719c..f9fb2372 100644 --- a/rules.info.yml +++ b/rules.info.yml @@ -2,7 +2,7 @@ name: Rules type: module description: 'React on events and conditionally evaluate actions.' package: Rules -core_version_requirement: ^9 || ^10 +core_version_requirement: ^9.1 || ^10 dependencies: - drupal:config - typed_data:typed_data diff --git a/src/Core/RulesConfigurableEventHandlerInterface.php b/src/Core/RulesConfigurableEventHandlerInterface.php index c2e1d2ab..2158a569 100644 --- a/src/Core/RulesConfigurableEventHandlerInterface.php +++ b/src/Core/RulesConfigurableEventHandlerInterface.php @@ -4,7 +4,6 @@ namespace Drupal\rules\Core; use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Core\Form\FormStateInterface; -use Symfony\Component\EventDispatcher\Event; /** * Interface for handling configurable rules events. @@ -29,8 +28,13 @@ interface RulesConfigurableEventHandlerInterface extends RulesEventHandlerInterf /** * Determines the qualified event names for the dispatched event. * - * @param \Symfony\Component\EventDispatcher\Event $event + * @todo The 'object' type hint should be replaced with the appropriate + * class once Symfony 4 is no longer supported. + * + * @param object $event * The event data of the event being dispatched. + * In Drupal 9 this will be a \Symfony\Component\EventDispatcher\Event, + * In Drupal 10 this will be a \Symfony\Contracts\EventDispatcher\Event. * @param string $event_name * The event base name. * @param array $event_definition @@ -42,7 +46,7 @@ interface RulesConfigurableEventHandlerInterface extends RulesEventHandlerInterf * the fully-qualified event "rules_entity_view:node--article" should be * triggered in addition to base event "rules_entity_view:node". */ - public static function determineQualifiedEvents(Event $event, $event_name, array &$event_definition); + public static function determineQualifiedEvents(object $event, $event_name, array &$event_definition); /** * Provides a human readable summary of the event's configuration. diff --git a/src/EventHandler/ConfigurableEventHandlerEntityBundle.php b/src/EventHandler/ConfigurableEventHandlerEntityBundle.php index 0174f168..fd93a58d 100644 --- a/src/EventHandler/ConfigurableEventHandlerEntityBundle.php +++ b/src/EventHandler/ConfigurableEventHandlerEntityBundle.php @@ -4,7 +4,6 @@ namespace Drupal\rules\EventHandler; use Drupal\Core\Form\FormStateInterface; use Drupal\rules\Event\EntityEvent; -use Symfony\Component\EventDispatcher\Event; /** * Exposes the bundle of an entity as event setting. @@ -14,7 +13,9 @@ class ConfigurableEventHandlerEntityBundle extends ConfigurableEventHandlerBase /** * {@inheritdoc} */ - public static function determineQualifiedEvents(Event $event, $event_name, array &$event_definition) { + public static function determineQualifiedEvents(object $event, $event_name, array &$event_definition) { + // @todo The 'object' type hint should be replaced with the appropriate + // class once Symfony 4 is no longer supported. $events_suffixes = []; if ($event instanceof EntityEvent) { $events_suffixes[] = $event->getSubject()->bundle(); diff --git a/src/EventSubscriber/GenericEventSubscriber.php b/src/EventSubscriber/GenericEventSubscriber.php index 9b67687b..e30026dd 100644 --- a/src/EventSubscriber/GenericEventSubscriber.php +++ b/src/EventSubscriber/GenericEventSubscriber.php @@ -8,9 +8,10 @@ use Drupal\rules\Context\ExecutionState; use Drupal\rules\Core\RulesConfigurableEventHandlerInterface; use Drupal\rules\Core\RulesEventManager; use Drupal\rules\Engine\RulesComponentRepositoryInterface; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\GenericEvent; +use Symfony\Component\EventDispatcher\Event as SymfonyComponentEvent; +use Symfony\Contracts\EventDispatcher\Event as SymfonyContractsEvent; /** * Subscribes to Symfony events and maps them to Rules events. @@ -97,12 +98,22 @@ class GenericEventSubscriber implements EventSubscriberInterface { /** * Reacts on the given event and invokes configured reaction rules. * - * @param \Symfony\Component\EventDispatcher\Event $event + * @param object $event * The event object containing context for the event. + * In Drupal 9 this will be a \Symfony\Component\EventDispatcher\Event, + * In Drupal 10 this will be a \Symfony\Contracts\EventDispatcher\Event. * @param string $event_name * The event name. */ - public function onRulesEvent(Event $event, $event_name) { + public function onRulesEvent(object $event, $event_name) { + // @todo The 'object' type hint should be replaced with the appropriate + // class once Symfony 4 is no longer supported, and the assert() should be + // removed. + assert( + $event instanceof SymfonyComponentEvent || + $event instanceof SymfonyContractsEvent + ); + // Get event metadata and the to-be-triggered events. $event_definition = $this->eventManager->getDefinition($event_name); $handler_class = $event_definition['class'];