Move event registration from services.yml to events.yml

Created on 19 June 2013, over 11 years ago
Updated 15 July 2023, over 1 year ago

Updated: Comment #N

Problem/Motivation

To register event subscribers currently, you have to add a service with the "event_subscriber" tag.

Considering that we don't use tagged services for discovery consistently in core, this is exposing an unnecessary implementation detail.

I think we can improve DX by adding a dedicated events.yml with a simple schema for registering events and subscribers.

Something like this:


namespace Drupal\rdf;

final class RdfMappingEvents {
  const MAP_TYPES_FROM_INPUT = 'rdf.map_types_from_input';
}

namespace Drupal\rdf\EventSubscriber;

use Drupal\rdf\RdfMappingEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class MappingSubscriber implements EventSubscriberInterface {

  static function getSubscribedEvents() {
    $events[RdfMappingEvents::MAP_TYPES_FROM_INPUT] = 'mapTypesFromInput';
    return $events;
  }
}
services:
  rdf.mapping:
    class: Drupal\rdf\EventSubscriber\MappingSubscriber
    tags:
      - { name: event_subscriber }

Proposed resolution

Could be something like this:

events:
- rdf.map_types_from_input
subscribers: 
  rdf.map_types_from_input: Drupal\rdf\EventSubscriber\MappingSubscriber::mapTypesFromInput

Or generically speaking:

subscribers:
  config.importer.import:
    - callback: config_snapshot_subscriber:onConfigImporterImport
      priority: 40
  config.importer.validate:
    - callback: Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate
      priority: 40
  config.save:
    - callback: config.factory:onConfigSave
      priority: 255

For dependency injection we can use the ContainerInjectionInterface

Remaining tasks

User interface changes

API changes

Beta phase evaluation

<!--Uncomment the relevant rows for the issue. -->
πŸ“Œ Task
Status

Closed: outdated

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States msonnabaum

Live updates comments and jobs are added and updated live.
  • API addition

    Enhances an existing API or introduces a new subsystem. Depending on the size and impact, possibly backportable to earlier major versions.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024