3 namespace Drupal\Core\Entity;
5 use Drupal\Core\DependencyInjection\DependencySerializationTrait;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 * Provides a base class for entity handlers.
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.
19 abstract class EntityHandlerBase {
20 use StringTranslationTrait;
21 use DependencySerializationTrait;
24 * The module handler to invoke hooks on.
26 * @var \Drupal\Core\Extension\ModuleHandlerInterface
28 protected $moduleHandler;
31 * Gets the module handler.
33 * @return \Drupal\Core\Extension\ModuleHandlerInterface
36 protected function moduleHandler() {
37 if (!$this->moduleHandler) {
38 $this->moduleHandler = \Drupal::moduleHandler();
40 return $this->moduleHandler;
44 * Sets the module handler for this handler.
46 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
51 public function setModuleHandler(ModuleHandlerInterface $module_handler) {
52 $this->moduleHandler = $module_handler;