Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By runeasgar on
Situation:
I've built a hello world module for fun, and I've created a service that does a little processing of the hello world text.
It's easy enough to inject this service into a CONTROLLER, but how do I inject it into a block plugin?
Basically, I have this HelloText::getText() function that I'm calling in HelloController::hello(), but how do I use it in HelloBlock::build() ?
ContainerInjectionInterface appears to be something usable only by blocks.. and I don't see an equivalent syntax for supplying services via hello.routing.yml (using arguments).