abstract class ActionFormBase extends EntityForm {
/**
- * The action plugin being configured.
+ * The action storage.
*
- * @var \Drupal\Core\Action\ActionInterface
+ * @var \Drupal\Core\Entity\EntityStorageInterface
*/
- protected $plugin;
+ protected $storage;
/**
- * The action storage.
+ * The action entity.
*
- * @var \Drupal\Core\Entity\EntityStorageInterface
+ * @var \Drupal\system\ActionConfigEntityInterface
*/
- protected $storage;
+ protected $entity;
/**
* Constructs a new action form.
);
}
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, FormStateInterface $form_state) {
- $this->plugin = $this->entity->getPlugin();
- return parent::buildForm($form, $form_state);
- }
-
/**
* {@inheritdoc}
*/
'#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);
* Determines if the action already exists.
*
* @param string $id
- * The action ID
+ * The action ID.
*
* @return bool
* TRUE if the action exists, FALSE otherwise.
*/
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);
}
}
*/
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);
}
}
$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;
+ }
+
}