Last active
October 4, 2017 05:40
-
-
Save fede-green/fc7cddffca6c3debf97743ec388af222 to your computer and use it in GitHub Desktop.
How to create a service that does stuff for you.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\my_module; | |
/** | |
* Service to doi Stuff. | |
*/ | |
class DoStuff extends XYZ { | |
/** | |
* Returns stuff. | |
* | |
* @return string | |
* Stuff returned. | |
*/ | |
public function doStuff() { | |
return "Stuff"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services: | |
mymodule.do_stuff: | |
class: Drupal\my_module\DoStuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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