Mercurial > hg > isophonics-drupal-site
comparison core/modules/media/src/Plugin/Derivative/DynamicLocalTasks.php @ 18:af1871eacc83
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:33:08 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:129ea1e6d783 | 18:af1871eacc83 |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\media\Plugin\Derivative; | |
4 | |
5 use Drupal\Component\Plugin\Derivative\DeriverBase; | |
6 use Drupal\Core\Config\ConfigFactoryInterface; | |
7 use Drupal\Core\Entity\EntityTypeManagerInterface; | |
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 * Generates media-related local tasks. | |
15 */ | |
16 class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface { | |
17 | |
18 use StringTranslationTrait; | |
19 | |
20 /** | |
21 * The entity type manager. | |
22 * | |
23 * @var \Drupal\Core\Entity\EntityTypeManagerInterface | |
24 */ | |
25 protected $entityTypeManager; | |
26 | |
27 /** | |
28 * The media settings config. | |
29 * | |
30 * @var \Drupal\Core\Config\ImmutableConfig | |
31 */ | |
32 protected $config; | |
33 | |
34 /** | |
35 * Creates a DynamicLocalTasks object. | |
36 * | |
37 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation | |
38 * The translation manager. | |
39 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager | |
40 * The entity type manager. | |
41 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory | |
42 * The config factory. | |
43 */ | |
44 public function __construct(TranslationInterface $string_translation, EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory) { | |
45 $this->stringTranslation = $string_translation; | |
46 $this->entityTypeManager = $entity_type_manager; | |
47 $this->config = $config_factory->get('media.settings'); | |
48 } | |
49 | |
50 /** | |
51 * {@inheritdoc} | |
52 */ | |
53 public static function create(ContainerInterface $container, $base_plugin_id) { | |
54 return new static( | |
55 $container->get('string_translation'), | |
56 $container->get('entity_type.manager'), | |
57 $container->get('config.factory') | |
58 ); | |
59 } | |
60 | |
61 /** | |
62 * {@inheritdoc} | |
63 */ | |
64 public function getDerivativeDefinitions($base_plugin_definition) { | |
65 // Provide an edit_form task if standalone media URLs are enabled. | |
66 $this->derivatives["entity.media.canonical"] = [ | |
67 'route_name' => "entity.media.canonical", | |
68 'title' => $this->t('Edit'), | |
69 'base_route' => "entity.media.canonical", | |
70 'weight' => 1, | |
71 ] + $base_plugin_definition; | |
72 | |
73 if ($this->config->get('standalone_url')) { | |
74 $this->derivatives["entity.media.canonical"]['title'] = $this->t('View'); | |
75 | |
76 $this->derivatives["entity.media.edit_form"] = [ | |
77 'route_name' => "entity.media.edit_form", | |
78 'title' => $this->t('Edit'), | |
79 'base_route' => 'entity.media.canonical', | |
80 'weight' => 2, | |
81 ] + $base_plugin_definition; | |
82 } | |
83 | |
84 $this->derivatives["entity.media.delete_form"] = [ | |
85 'route_name' => "entity.media.delete_form", | |
86 'title' => $this->t('Delete'), | |
87 'base_route' => "entity.media.canonical", | |
88 'weight' => 10, | |
89 ] + $base_plugin_definition; | |
90 | |
91 return $this->derivatives; | |
92 } | |
93 | |
94 } |