Created
November 19, 2021 14:27
-
-
Save levmyshkin/1656f00b1792e0d532d0e582bd9b4383 to your computer and use it in GitHub Desktop.
Drupal Dependencies injection in a custom class/service
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: | |
book.manager: | |
class: Drupal\book\BookManager | |
arguments: ['@entity.manager', '@string_translation', '@config.factory', '@book.outline_storage', '@renderer'] |
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\book; | |
use Drupal\Core\Entity\EntityManagerInterface; | |
use Drupal\Core\Render\RendererInterface; | |
use Drupal\Core\StringTranslation\TranslationInterface; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
... | |
/** | |
* Defines a book manager. | |
*/ | |
class BookManager implements BookManagerInterface { | |
/** | |
* Entity manager Service Object. | |
* | |
* @var \Drupal\Core\Entity\EntityManagerInterface | |
*/ | |
protected $entityManager; | |
/** | |
* Config Factory Service Object. | |
* | |
* @var \Drupal\Core\Config\ConfigFactoryInterface | |
*/ | |
protected $configFactory; | |
/** | |
* Books Array. | |
* | |
* @var array | |
*/ | |
protected $books; | |
/** | |
* Book outline storage. | |
* | |
* @var \Drupal\book\BookOutlineStorageInterface | |
*/ | |
protected $bookOutlineStorage; | |
/** | |
* Stores flattened book trees. | |
* | |
* @var array | |
*/ | |
protected $bookTreeFlattened; | |
/** | |
* The renderer. | |
* | |
* @var \Drupal\Core\Render\RendererInterface | |
*/ | |
protected $renderer; | |
/** | |
* Constructs a BookManager object. | |
*/ | |
public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $translation, ConfigFactoryInterface $config_factory, BookOutlineStorageInterface $book_outline_storage, RendererInterface $renderer) { | |
$this->entityManager = $entity_manager; | |
$this->stringTranslation = $translation; | |
$this->configFactory = $config_factory; | |
$this->bookOutlineStorage = $book_outline_storage; | |
$this->renderer = $renderer; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment