Auto-configure event subscribers

References #347
This commit is contained in:
Oliver Davies 2021-01-13 23:49:03 +00:00
parent 53ab326415
commit 43455d5ae1
4 changed files with 8 additions and 16 deletions

View file

@ -11,15 +11,5 @@ services:
Drupal\Core\Queue\QueueFactory:
alias: queue
Drupal\opdavies_blog\EventSubscriber\PushPostToSocialMediaOnceItIsPublished:
autowire: true
tags:
- { name: event_subscriber }
Drupal\opdavies_blog\EventSubscriber\SortTagsAlphabeticallyWhenPostIsSaved:
autowire: true
tags:
- { name: event_subscriber }
GuzzleHttp\ClientInterface:
alias: http_client

View file

@ -12,7 +12,7 @@ use Symfony\Component\Finder\Finder;
final class OpdaviesBlogServiceProvider implements ServiceProviderInterface {
public function register(ContainerBuilder $container): void {
foreach (['Repository', 'Service'] as $directory) {
foreach (['EventSubscriber', 'Repository', 'Service'] as $directory) {
$files = Finder::create()
->in(__DIR__ . '/' . $directory)
->files()
@ -28,6 +28,9 @@ final class OpdaviesBlogServiceProvider implements ServiceProviderInterface {
$definition = new Definition($class);
$definition->setAutowired(TRUE);
if ($directory == 'EventSubscriber') {
$definition->addTag('event_subscriber');
}
$container->setDefinition($class, $definition);
}
}

View file

@ -4,7 +4,3 @@ services:
Drupal\Core\Entity\EntityTypeManagerInterface:
alias: entity_type.manager
Drupal\opdavies_talks\EventSubscriber\UpdateTalkNodeBeforeSave:
tags:
- { name: event_subscriber }

View file

@ -12,7 +12,7 @@ use Symfony\Component\Finder\Finder;
final class OpdaviesTalksServiceProvider implements ServiceProviderInterface {
public function register(ContainerBuilder $container): void {
foreach (['Repository', 'Service'] as $directory) {
foreach (['EventSubscriber', 'Repository', 'Service'] as $directory) {
$files = Finder::create()
->in(__DIR__ . '/' . $directory)
->files()
@ -28,6 +28,9 @@ final class OpdaviesTalksServiceProvider implements ServiceProviderInterface {
$definition = new Definition($class);
$definition->setAutowired(TRUE);
if ($directory == 'EventSubscriber') {
$definition->addTag('event_subscriber');
}
$container->setDefinition($class, $definition);
}
}