Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityHandlerBase.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
5 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8
9 /**
10  * Provides a base class for entity handlers.
11  *
12  * @deprecated in Drupal 8.0.x, will be removed before Drupal 9.0.0.
13  *   Implement the container injection pattern of
14  *   \Drupal\Core\Entity\EntityHandlerInterface::createInstance() to obtain the
15  *   module handler service for your class.
16  *
17  * @ingroup entity_api
18  */
19 abstract class EntityHandlerBase {
20   use StringTranslationTrait;
21   use DependencySerializationTrait;
22
23   /**
24    * The module handler to invoke hooks on.
25    *
26    * @var \Drupal\Core\Extension\ModuleHandlerInterface
27    */
28   protected $moduleHandler;
29
30   /**
31    * Gets the module handler.
32    *
33    * @return \Drupal\Core\Extension\ModuleHandlerInterface
34    *   The module handler.
35    */
36   protected function moduleHandler() {
37     if (!$this->moduleHandler) {
38       $this->moduleHandler = \Drupal::moduleHandler();
39     }
40     return $this->moduleHandler;
41   }
42
43   /**
44    * Sets the module handler for this handler.
45    *
46    * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
47    *   The module handler.
48    *
49    * @return $this
50    */
51   public function setModuleHandler(ModuleHandlerInterface $module_handler) {
52     $this->moduleHandler = $module_handler;
53     return $this;
54   }
55
56 }