1adec996536209eb5f0895784ff09efa91927681
[yaffs-website] / Plugin / Deriver / EntityDeriverBase.php
1 <?php
2
3 namespace Drupal\ctools\Plugin\Deriver;
4
5
6 use Drupal\Component\Plugin\Derivative\DeriverBase;
7 use Drupal\Core\Entity\EntityManagerInterface;
8 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
9 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 use Drupal\Core\StringTranslation\TranslationInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 /**
14  * An abstract base class that sets up the needs of entity specific derivers.
15  */
16 abstract class EntityDeriverBase extends DeriverBase implements ContainerDeriverInterface {
17
18   use StringTranslationTrait;
19
20   /**
21    * The entity manager.
22    *
23    * @var \Drupal\Core\Entity\EntityManagerInterface
24    */
25   protected $entityManager;
26
27   /**
28    * Constructs new EntityViewDeriver.
29    *
30    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
31    *   The entity manager.
32    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
33    *   The string translation service.
34    */
35   public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
36     $this->entityManager = $entity_manager;
37     $this->stringTranslation = $string_translation;
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public static function create(ContainerInterface $container, $base_plugin_id) {
44     return new static(
45       $container->get('entity.manager'),
46       $container->get('string_translation')
47     );
48   }
49
50 }
51