Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / action / src / ActionFormBase.php
index 3fafd035eeef4231cb0811844b87b814a6e09c80..46b70ede45a55e60736784272eea513bc8c8f324 100644 (file)
@@ -14,18 +14,18 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
 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.
@@ -46,14 +46,6 @@ abstract class ActionFormBase extends EntityForm {
     );
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function buildForm(array $form, FormStateInterface $form_state) {
-    $this->plugin = $this->entity->getPlugin();
-    return parent::buildForm($form, $form_state);
-  }
-
   /**
    * {@inheritdoc}
    */
@@ -85,8 +77,8 @@ abstract class ActionFormBase extends EntityForm {
       '#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 @@ abstract class ActionFormBase extends EntityForm {
    * 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 @@ abstract class ActionFormBase extends EntityForm {
    */
   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 @@ abstract class ActionFormBase extends EntityForm {
    */
   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 @@ abstract class ActionFormBase extends EntityForm {
     $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;
+  }
+
 }