Run prettier on all *.md files

```
prettier '{app,source}/**/**.md' --write
```
This commit is contained in:
Oliver Davies 2020-03-08 17:52:59 +00:00
parent a3ceeaf0f3
commit 85a10c545b
170 changed files with 5127 additions and 2282 deletions

View file

@ -1,26 +1,39 @@
---
title: Experimenting with events in Drupal 8
date: 2018-08-21
excerpt: Trying a different way of structuring Drupal modules, using event subscribers and autowiring.
excerpt:
Trying a different way of structuring Drupal modules, using event subscribers
and autowiring.
tags:
- drupal
- drupal-8
- drupal-planet
- php
- symfony
- drupal
- drupal-8
- drupal-planet
- php
- symfony
promoted: true
---
Ive been experimenting with moving some code to Drupal 8, and Im quite intrigued by a different way that Ive tried to structure it - using event subscribers, building on some of the takeaways from Drupal Dev Days.
Ive been experimenting with moving some code to Drupal 8, and Im quite
intrigued by a different way that Ive tried to structure it - using event
subscribers, building on some of the takeaways from Drupal Dev Days.
Here is how this module is currently structured:
![](/images/blog/events-drupal-8/1.png){.border .p-1}
Note that there is no `opdavies_blog.module` file, and rather than calling actions from within a hook like `opdavies_blog_entity_update()`, each action becomes its own event subscriber class.
Note that there is no `opdavies_blog.module` file, and rather than calling
actions from within a hook like `opdavies_blog_entity_update()`, each action
becomes its own event subscriber class.
This means that there are no long `hook_entity_update` functions, and instead there are descriptive, readable event subscriber class names, simpler action code that is responsibile only for performing one task, and youre able to inject and autowire dependencies into the event subscriber classes as services - making it easier and cleaner to use dependency injection, and simpler write tests to mock dependencies when needed.
This means that there are no long `hook_entity_update` functions, and instead
there are descriptive, readable event subscriber class names, simpler action
code that is responsibile only for performing one task, and youre able to
inject and autowire dependencies into the event subscriber classes as services -
making it easier and cleaner to use dependency injection, and simpler write
tests to mock dependencies when needed.
The additional events are provided by the [Hook Event Dispatcher module](https://www.drupal.org/project/hook_event_dispatcher).
The additional events are provided by the
[Hook Event Dispatcher module](https://www.drupal.org/project/hook_event_dispatcher).
## Code