I have an entity with a JSON field, and I do some complicated processing when the entity is saved.
Right now, I do this processing in hook_ENTITY_presave_alter()
, which calls a service I have created in a custom module.
However, since Drupal 9.3, we can create bundle classes to extend entities cleanly.
So I made one for my entity, and I wrote some new getters and setters so I can do $entity->getMyValue()
instead of $entity->field_abc->value
.
Now, I want to take the next step and inject my service into the entity and move the processing directly into the entity on save. How can I do that?