March 2019
Intermediate to advanced
580 pages
15h 3m
English
Now that we have a general idea as to what a service is, let's create one to see all this in practice.
As I mentioned earlier, I want my greetings to be more dynamic, that is, I want the salutation to depend on the time of day. So, we will create a (HelloWorldSalutation) class that is responsible for doing that and place it in the /src folder (our module's namespace root in a file naturally called HelloWorldSalutation.php):
namespace Drupal\hello_world;use Drupal\Core\StringTranslation\StringTranslationTrait;/** * Prepares the salutation to the world. */class HelloWorldSalutation { use StringTranslationTrait; /** * Returns the salutation */ public function getSalutation() { $time = new \DateTime(); if ((int) ...
Read now
Unlock full access