Created
January 16, 2019 16:48
Star
You must be signed in to star a gist
D8 - Services Example
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
D8 - Services | |
... | |
lightning-8/modules/custom/basic/basic.services.yml | |
services: | |
basic.basic_hero_articles: | |
class: Drupal\basic\BasicArticleService | |
... | |
lightning-8/modules/custom/basic/src/BasicArticleService.php | |
<?php | |
namespace Drupal\basic; | |
/** | |
* Our basic articles service | |
*/ | |
class BasicArticleService { | |
/** | |
* Methood for getting Articles, regarding heroes. | |
*/ | |
public function getHeroArticles() { | |
$articles = ["Article 1", "Article 2"]; | |
return $articles; | |
} | |
} | |
... | |
Test using devel/php page | |
$basicArticleService = Drupal::service("basic.basic_hero_articles"); | |
kint($basicArticleService->getHeroArticles()); die(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment