We got a basic understanding of what a Drupal service is previously.
How to best store and retrieve a tree-style in a relational DB? This pattern is more common than we think. Examples would be hierarchical tags and threaded comments or discussions.
Drupal 8 has this concept of services, or reusable PHP objects. The distinguishing feature of services is that their initiation is configurable. In other words, we can configure what type of instance is created and when this instance is created in the code, mostly without changing the code at all.
Why is this a big deal?
Real world plugins have a lot more properties than the
label property mentioned in our breakfast plugin. To make our plugin more "real world", we introduce 2 properties, image and ingredients.
- Implementing a new plugin from existing plugin types.
- Implementing a new plugin type using the annotation based discovery mechanism.
As an exercise, let's first construct an imaginary scenario where the user of your Drupal site wants choose what they want for breakfast from a list of breakfast menu items.