Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity / src / Menu / EntityAddLocalAction.php
1 <?php
2
3 namespace Drupal\entity\Menu;
4
5 use Drupal\Core\Entity\EntityTypeInterface;
6 use Drupal\Core\Menu\LocalActionDefault;
7 use Drupal\Core\Routing\RouteProviderInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 use Drupal\Core\StringTranslation\TranslationInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11 use Symfony\Component\HttpFoundation\Request;
12
13 /**
14  * Provides a local action to add an entity.
15  */
16 class EntityAddLocalAction extends LocalActionDefault {
17
18   use StringTranslationTrait;
19
20   /**
21    * The entity type.
22    *
23    * @var \Drupal\Core\Entity\EntityTypeInterface
24    */
25   protected $entityType;
26
27   /**
28    * Constructs a EntityAddLocalAction object.
29    *
30    * @param array $configuration
31    *   A configuration array containing information about the plugin instance.
32    * @param string $plugin_id
33    *   The plugin_id for the plugin instance.
34    * @param mixed $plugin_definition
35    *   The plugin implementation definition.
36    * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
37    *   The route provider to load routes by name.
38    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
39    *   The entity type.
40    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
41    *   The string translation service.
42    */
43   public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, EntityTypeInterface $entity_type, TranslationInterface $string_translation) {
44     parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider);
45
46     $this->entityType = $entity_type;
47     $this->setStringTranslation($string_translation);
48   }
49
50   /**
51    * {@inheritdoc}
52    */
53   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
54     /* @var \Drupal\Core\Entity\EntityTypeManagerInterface */
55     $entity_type_manager = $container->get('entity_type.manager');
56     // The plugin ID is of the form
57     // "entity.entity_actions:entity.$entity_type_id.collection".
58     // @see entity.links.action.yml
59     // @see \Drupal\entity\Menu\EntityCollectionLocalActionProvider::buildLocalActions()
60     list(, $derivate_id) = explode(':', $plugin_id);
61     list(, $entity_type_id, ) = explode('.', $derivate_id);
62     return new static(
63       $configuration,
64       $plugin_id,
65       $plugin_definition,
66       $container->get('router.route_provider'),
67       $entity_type_manager->getDefinition($entity_type_id),
68       $container->get('string_translation')
69     );
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   public function getTitle(Request $request = NULL) {
76     return (string) $this->t('Add @entity', [
77       '@entity' => (string) $this->entityType->getSingularLabel(),
78     ]);
79   }
80
81 }