DomainControllerBase.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Drupal\domain\Controller;
  3. use Drupal\Core\Controller\ControllerBase;
  4. use Drupal\Core\Entity\EntityTypeManagerInterface;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. use Drupal\domain\DomainStorageInterface;
  7. /**
  8. * Sets a base class for injecting domain information into controllers.
  9. *
  10. * This class is useful in cases where your controller needs to respond to
  11. * a domain argument. Drupal doesn't do that natively, so we use this base
  12. * class to allow router arguments to be passed a domain object.
  13. *
  14. * @see \Drupal\domain_alias\Controller\DomainAliasController
  15. */
  16. class DomainControllerBase extends ControllerBase {
  17. /**
  18. * The entity storage.
  19. *
  20. * @var \Drupal\domain\DomainStorageInterface
  21. */
  22. protected $domainStorage;
  23. /**
  24. * The entity manager.
  25. *
  26. * @var \Drupal\Core\Entity\EntityTypeManagerInterface
  27. */
  28. protected $entityTypeManager;
  29. /**
  30. * Constructs a new DomainControllerBase.
  31. *
  32. * @param \Drupal\domain\DomainStorageInterface $domain_storage
  33. * The storage controller.
  34. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
  35. * The entity manager.
  36. */
  37. public function __construct(DomainStorageInterface $domain_storage, EntityTypeManagerInterface $entity_type_manager) {
  38. $this->domainStorage = $domain_storage;
  39. $this->entityTypeManager = $entity_type_manager;
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public static function create(ContainerInterface $container) {
  45. return new static(
  46. $container->get('entity_type.manager')->getStorage('domain'),
  47. $container->get('entity_type.manager')
  48. );
  49. }
  50. }