fede-green
9/11/2017 - 7:01 AM

How to create a service that does stuff for you.

How to create a service that does stuff for you.

services: 
  mymodule.do_stuff:
    class: Drupal\my_module\DoStuff
<?php
  $stuffdoer = \Drupal::service('my_module.do_stuff');
  $theStuff = $stuffdoer->doStuff();
  
<?php

namespace Drupal\my_module;


/**
 * Service to doi Stuff.
 */
class DoStuff extends XYZ {
  /**
   * Returns stuff.
   *
   * @return string
   *   Stuff returned.
   */
  public function doStuff() {
    return "Stuff";
  }
  
}