Mercurial > hg > isophonics-drupal-site
comparison core/modules/action/src/ActionFormBase.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 | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
13:5fb285c0d0e3 | 14:1fec387a4317 |
---|---|
12 * Provides a base form for action forms. | 12 * Provides a base form for action forms. |
13 */ | 13 */ |
14 abstract class ActionFormBase extends EntityForm { | 14 abstract class ActionFormBase extends EntityForm { |
15 | 15 |
16 /** | 16 /** |
17 * The action plugin being configured. | |
18 * | |
19 * @var \Drupal\Core\Action\ActionInterface | |
20 */ | |
21 protected $plugin; | |
22 | |
23 /** | |
24 * The action storage. | 17 * The action storage. |
25 * | 18 * |
26 * @var \Drupal\Core\Entity\EntityStorageInterface | 19 * @var \Drupal\Core\Entity\EntityStorageInterface |
27 */ | 20 */ |
28 protected $storage; | 21 protected $storage; |
22 | |
23 /** | |
24 * The action entity. | |
25 * | |
26 * @var \Drupal\system\ActionConfigEntityInterface | |
27 */ | |
28 protected $entity; | |
29 | 29 |
30 /** | 30 /** |
31 * Constructs a new action form. | 31 * Constructs a new action form. |
32 * | 32 * |
33 * @param \Drupal\Core\Entity\EntityStorageInterface $storage | 33 * @param \Drupal\Core\Entity\EntityStorageInterface $storage |
42 */ | 42 */ |
43 public static function create(ContainerInterface $container) { | 43 public static function create(ContainerInterface $container) { |
44 return new static( | 44 return new static( |
45 $container->get('entity.manager')->getStorage('action') | 45 $container->get('entity.manager')->getStorage('action') |
46 ); | 46 ); |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 public function buildForm(array $form, FormStateInterface $form_state) { | |
53 $this->plugin = $this->entity->getPlugin(); | |
54 return parent::buildForm($form, $form_state); | |
55 } | 47 } |
56 | 48 |
57 /** | 49 /** |
58 * {@inheritdoc} | 50 * {@inheritdoc} |
59 */ | 51 */ |
83 $form['type'] = [ | 75 $form['type'] = [ |
84 '#type' => 'value', | 76 '#type' => 'value', |
85 '#value' => $this->entity->getType(), | 77 '#value' => $this->entity->getType(), |
86 ]; | 78 ]; |
87 | 79 |
88 if ($this->plugin instanceof PluginFormInterface) { | 80 if ($plugin = $this->getPlugin()) { |
89 $form += $this->plugin->buildConfigurationForm($form, $form_state); | 81 $form += $plugin->buildConfigurationForm($form, $form_state); |
90 } | 82 } |
91 | 83 |
92 return parent::form($form, $form_state); | 84 return parent::form($form, $form_state); |
93 } | 85 } |
94 | 86 |
95 /** | 87 /** |
96 * Determines if the action already exists. | 88 * Determines if the action already exists. |
97 * | 89 * |
98 * @param string $id | 90 * @param string $id |
99 * The action ID | 91 * The action ID. |
100 * | 92 * |
101 * @return bool | 93 * @return bool |
102 * TRUE if the action exists, FALSE otherwise. | 94 * TRUE if the action exists, FALSE otherwise. |
103 */ | 95 */ |
104 public function exists($id) { | 96 public function exists($id) { |
118 /** | 110 /** |
119 * {@inheritdoc} | 111 * {@inheritdoc} |
120 */ | 112 */ |
121 public function validateForm(array &$form, FormStateInterface $form_state) { | 113 public function validateForm(array &$form, FormStateInterface $form_state) { |
122 parent::validateForm($form, $form_state); | 114 parent::validateForm($form, $form_state); |
123 | 115 if ($plugin = $this->getPlugin()) { |
124 if ($this->plugin instanceof PluginFormInterface) { | 116 $plugin->validateConfigurationForm($form, $form_state); |
125 $this->plugin->validateConfigurationForm($form, $form_state); | |
126 } | 117 } |
127 } | 118 } |
128 | 119 |
129 /** | 120 /** |
130 * {@inheritdoc} | 121 * {@inheritdoc} |
131 */ | 122 */ |
132 public function submitForm(array &$form, FormStateInterface $form_state) { | 123 public function submitForm(array &$form, FormStateInterface $form_state) { |
133 parent::submitForm($form, $form_state); | 124 parent::submitForm($form, $form_state); |
134 | 125 if ($plugin = $this->getPlugin()) { |
135 if ($this->plugin instanceof PluginFormInterface) { | 126 $plugin->submitConfigurationForm($form, $form_state); |
136 $this->plugin->submitConfigurationForm($form, $form_state); | |
137 } | 127 } |
138 } | 128 } |
139 | 129 |
140 /** | 130 /** |
141 * {@inheritdoc} | 131 * {@inheritdoc} |
145 drupal_set_message($this->t('The action has been successfully saved.')); | 135 drupal_set_message($this->t('The action has been successfully saved.')); |
146 | 136 |
147 $form_state->setRedirect('entity.action.collection'); | 137 $form_state->setRedirect('entity.action.collection'); |
148 } | 138 } |
149 | 139 |
140 /** | |
141 * Gets the action plugin while ensuring it implements configuration form. | |
142 * | |
143 * @return \Drupal\Core\Action\ActionInterface|\Drupal\Core\Plugin\PluginFormInterface|null | |
144 * The action plugin, or NULL if it does not implement configuration forms. | |
145 */ | |
146 protected function getPlugin() { | |
147 if ($this->entity->getPlugin() instanceof PluginFormInterface) { | |
148 return $this->entity->getPlugin(); | |
149 } | |
150 return NULL; | |
151 } | |
152 | |
150 } | 153 } |