Skip to content

Instantly share code, notes, and snippets.

@fede-green
Last active October 4, 2017 05:40
Show Gist options
  • Save fede-green/fc7cddffca6c3debf97743ec388af222 to your computer and use it in GitHub Desktop.
Save fede-green/fc7cddffca6c3debf97743ec388af222 to your computer and use it in GitHub Desktop.
How to create a service that does stuff for you.
<?php
namespace Drupal\my_module;
/**
* Service to doi Stuff.
*/
class DoStuff extends XYZ {
/**
* Returns stuff.
*
* @return string
* Stuff returned.
*/
public function doStuff() {
return "Stuff";
}
}
services:
mymodule.do_stuff:
class: Drupal\my_module\DoStuff
<?php
$stuffdoer = \Drupal::service('my_module.do_stuff');
$theStuff = $stuffdoer->doStuff();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment