EntityHandlerBase.php 1.4 KB

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