October 2017
Intermediate to advanced
566 pages
14h 31m
English
We have now closed the parenthesis on how services can be used. Let's take a look at how to inject our newly created service into our Controller.
We will need to add some code to our Controller (typically at the beginning of the class so that we can immediately identify the presence of this code when looking at it):
/** * @var \Drupal\hello_world\HelloWorldSalutation */ protected $salutation; /** * HelloWorldController constructor. * * @param \Drupal\hello_world\HelloWorldSalutation $salutation */ public function __construct(HelloWorldSalutation $salutation) { $this->salutation = $salutation; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { return new static( ...Read now
Unlock full access