Mercurial > hg > isophonics-drupal-site
diff 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 |
line wrap: on
line diff
--- a/core/modules/action/src/ActionFormBase.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/modules/action/src/ActionFormBase.php Mon Apr 23 09:46:53 2018 +0100 @@ -14,13 +14,6 @@ abstract class ActionFormBase extends EntityForm { /** - * The action plugin being configured. - * - * @var \Drupal\Core\Action\ActionInterface - */ - protected $plugin; - - /** * The action storage. * * @var \Drupal\Core\Entity\EntityStorageInterface @@ -28,6 +21,13 @@ protected $storage; /** + * The action entity. + * + * @var \Drupal\system\ActionConfigEntityInterface + */ + protected $entity; + + /** * Constructs a new action form. * * @param \Drupal\Core\Entity\EntityStorageInterface $storage @@ -49,14 +49,6 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state) { - $this->plugin = $this->entity->getPlugin(); - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ public function form(array $form, FormStateInterface $form_state) { $form['label'] = [ '#type' => 'textfield', @@ -85,8 +77,8 @@ '#value' => $this->entity->getType(), ]; - if ($this->plugin instanceof PluginFormInterface) { - $form += $this->plugin->buildConfigurationForm($form, $form_state); + if ($plugin = $this->getPlugin()) { + $form += $plugin->buildConfigurationForm($form, $form_state); } return parent::form($form, $form_state); @@ -96,7 +88,7 @@ * Determines if the action already exists. * * @param string $id - * The action ID + * The action ID. * * @return bool * TRUE if the action exists, FALSE otherwise. @@ -120,9 +112,8 @@ */ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); - - if ($this->plugin instanceof PluginFormInterface) { - $this->plugin->validateConfigurationForm($form, $form_state); + if ($plugin = $this->getPlugin()) { + $plugin->validateConfigurationForm($form, $form_state); } } @@ -131,9 +122,8 @@ */ public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - - if ($this->plugin instanceof PluginFormInterface) { - $this->plugin->submitConfigurationForm($form, $form_state); + if ($plugin = $this->getPlugin()) { + $plugin->submitConfigurationForm($form, $form_state); } } @@ -147,4 +137,17 @@ $form_state->setRedirect('entity.action.collection'); } + /** + * Gets the action plugin while ensuring it implements configuration form. + * + * @return \Drupal\Core\Action\ActionInterface|\Drupal\Core\Plugin\PluginFormInterface|null + * The action plugin, or NULL if it does not implement configuration forms. + */ + protected function getPlugin() { + if ($this->entity->getPlugin() instanceof PluginFormInterface) { + return $this->entity->getPlugin(); + } + return NULL; + } + }