Chris@0: entityManager) { Chris@0: $this->entityManager = $this->container()->get('entity.manager'); Chris@0: } Chris@0: return $this->entityManager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the entity type manager. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\EntityTypeManagerInterface Chris@0: * The entity type manager. Chris@0: */ Chris@0: protected function entityTypeManager() { Chris@0: if (!isset($this->entityTypeManager)) { Chris@0: $this->entityTypeManager = $this->container()->get('entity_type.manager'); Chris@0: } Chris@0: return $this->entityTypeManager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves the entity form builder. Chris@0: * Chris@0: * @return \Drupal\Core\Entity\EntityFormBuilderInterface Chris@0: * The entity form builder. Chris@0: */ Chris@0: protected function entityFormBuilder() { Chris@0: if (!$this->entityFormBuilder) { Chris@0: $this->entityFormBuilder = $this->container()->get('entity.form_builder'); Chris@0: } Chris@0: return $this->entityFormBuilder; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the requested cache bin. Chris@0: * Chris@0: * @param string $bin Chris@0: * (optional) The cache bin for which the cache object should be returned, Chris@0: * defaults to 'default'. Chris@0: * Chris@0: * @return \Drupal\Core\Cache\CacheBackendInterface Chris@0: * The cache object associated with the specified bin. Chris@0: */ Chris@0: protected function cache($bin = 'default') { Chris@0: return $this->container()->get('cache.' . $bin); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Retrieves a configuration object. Chris@0: * Chris@0: * This is the main entry point to the configuration API. Calling Chris@0: * @code $this->config('book.admin') @endcode will return a configuration Chris@0: * object in which the book module can store its administrative settings. Chris@0: * Chris@0: * @param string $name Chris@0: * The name of the configuration object to retrieve. The name corresponds to Chris@0: * a configuration file. For @code \Drupal::config('book.admin') @endcode, Chris@0: * the config object returned will contain the contents of book.admin Chris@0: * configuration file. Chris@0: * Chris@0: * @return \Drupal\Core\Config\Config Chris@0: * A configuration object. Chris@0: */ Chris@0: protected function config($name) { Chris@0: if (!$this->configFactory) { Chris@0: $this->configFactory = $this->container()->get('config.factory'); Chris@0: } Chris@0: return $this->configFactory->get($name); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a key/value storage collection. Chris@0: * Chris@0: * @param string $collection Chris@0: * Name of the key/value collection to return. Chris@0: * Chris@0: * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface Chris@0: */ Chris@0: protected function keyValue($collection) { Chris@0: if (!$this->keyValue) { Chris@0: $this->keyValue = $this->container()->get('keyvalue')->get($collection); Chris@0: } Chris@0: return $this->keyValue; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the state storage service. Chris@0: * Chris@0: * Use this to store machine-generated data, local to a specific environment Chris@0: * that does not need deploying and does not need human editing; for example, Chris@0: * the last time cron was run. Data which needs to be edited by humans and Chris@0: * needs to be the same across development, production, etc. environments Chris@0: * (for example, the system maintenance message) should use config() instead. Chris@0: * Chris@16: * @return \Drupal\Core\State\StateInterface Chris@0: */ Chris@0: protected function state() { Chris@0: if (!$this->stateService) { Chris@0: $this->stateService = $this->container()->get('state'); Chris@0: } Chris@0: return $this->stateService; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the module handler. Chris@0: * Chris@0: * @return \Drupal\Core\Extension\ModuleHandlerInterface Chris@0: */ Chris@0: protected function moduleHandler() { Chris@0: if (!$this->moduleHandler) { Chris@0: $this->moduleHandler = $this->container()->get('module_handler'); Chris@0: } Chris@0: return $this->moduleHandler; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the form builder service. Chris@0: * Chris@0: * @return \Drupal\Core\Form\FormBuilderInterface Chris@0: */ Chris@0: protected function formBuilder() { Chris@0: if (!$this->formBuilder) { Chris@0: $this->formBuilder = $this->container()->get('form_builder'); Chris@0: } Chris@0: return $this->formBuilder; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the current user. Chris@0: * Chris@0: * @return \Drupal\Core\Session\AccountInterface Chris@0: * The current user. Chris@0: */ Chris@0: protected function currentUser() { Chris@0: if (!$this->currentUser) { Chris@0: $this->currentUser = $this->container()->get('current_user'); Chris@0: } Chris@0: return $this->currentUser; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the language manager service. Chris@0: * Chris@0: * @return \Drupal\Core\Language\LanguageManagerInterface Chris@0: * The language manager. Chris@0: */ Chris@0: protected function languageManager() { Chris@0: if (!$this->languageManager) { Chris@0: $this->languageManager = $this->container()->get('language_manager'); Chris@0: } Chris@0: return $this->languageManager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the service container. Chris@0: * Chris@0: * This method is marked private to prevent sub-classes from retrieving Chris@0: * services from the container through it. Instead, Chris@0: * \Drupal\Core\DependencyInjection\ContainerInjectionInterface should be used Chris@0: * for injecting services. Chris@0: * Chris@0: * @return \Symfony\Component\DependencyInjection\ContainerInterface Chris@0: * The service container. Chris@0: */ Chris@0: private function container() { Chris@0: return \Drupal::getContainer(); Chris@0: } Chris@0: Chris@0: }