Mercurial > hg > isophonics-drupal-site
comparison core/modules/action/src/ActionAddForm.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
1 <?php | 1 <?php |
2 | 2 |
3 namespace Drupal\action; | 3 namespace Drupal\action; |
4 | 4 |
5 use Drupal\Component\Utility\Crypt; | |
6 use Drupal\Core\Action\ActionManager; | |
7 use Drupal\Core\Entity\EntityStorageInterface; | |
8 use Drupal\Core\Form\FormStateInterface; | 5 use Drupal\Core\Form\FormStateInterface; |
9 use Symfony\Component\DependencyInjection\ContainerInterface; | |
10 | 6 |
11 /** | 7 /** |
12 * Provides a form for action add forms. | 8 * Provides a form for action add forms. |
9 * | |
10 * @internal | |
13 */ | 11 */ |
14 class ActionAddForm extends ActionFormBase { | 12 class ActionAddForm extends ActionFormBase { |
15 | |
16 /** | |
17 * The action manager. | |
18 * | |
19 * @var \Drupal\Core\Action\ActionManager | |
20 */ | |
21 protected $actionManager; | |
22 | |
23 /** | |
24 * Constructs a new ActionAddForm. | |
25 * | |
26 * @param \Drupal\Core\Entity\EntityStorageInterface $storage | |
27 * The action storage. | |
28 * @param \Drupal\Core\Action\ActionManager $action_manager | |
29 * The action plugin manager. | |
30 */ | |
31 public function __construct(EntityStorageInterface $storage, ActionManager $action_manager) { | |
32 parent::__construct($storage); | |
33 | |
34 $this->actionManager = $action_manager; | |
35 } | |
36 | |
37 /** | |
38 * {@inheritdoc} | |
39 */ | |
40 public static function create(ContainerInterface $container) { | |
41 return new static( | |
42 $container->get('entity.manager')->getStorage('action'), | |
43 $container->get('plugin.manager.action') | |
44 ); | |
45 } | |
46 | 13 |
47 /** | 14 /** |
48 * {@inheritdoc} | 15 * {@inheritdoc} |
49 * | 16 * |
50 * @param string $action_id | 17 * @param string $action_id |
51 * The hashed version of the action ID. | 18 * The action ID. |
52 */ | 19 */ |
53 public function buildForm(array $form, FormStateInterface $form_state, $action_id = NULL) { | 20 public function buildForm(array $form, FormStateInterface $form_state, $action_id = NULL) { |
54 // In \Drupal\action\Form\ActionAdminManageForm::buildForm() the action | 21 $this->entity->setPlugin($action_id); |
55 // are hashed. Here we have to decrypt it to find the desired action ID. | 22 |
56 foreach ($this->actionManager->getDefinitions() as $id => $definition) { | 23 // Derive the label and type from the action definition. |
57 $key = Crypt::hashBase64($id); | 24 $definition = $this->entity->getPluginDefinition(); |
58 if ($key === $action_id) { | 25 $this->entity->set('label', $definition['label']); |
59 $this->entity->setPlugin($id); | 26 $this->entity->set('type', $definition['type']); |
60 // Derive the label and type from the action definition. | |
61 $this->entity->set('label', $definition['label']); | |
62 $this->entity->set('type', $definition['type']); | |
63 break; | |
64 } | |
65 } | |
66 | 27 |
67 return parent::buildForm($form, $form_state); | 28 return parent::buildForm($form, $form_state); |
68 } | 29 } |
69 | 30 |
70 } | 31 } |