(REF) AfformSubmitEvent - Provide $afform, $formDataModel, and $apiRequest
authorTim Otten <totten@civicrm.org>
Thu, 11 Feb 2021 01:39:06 +0000 (17:39 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 17 Feb 2021 09:24:25 +0000 (01:24 -0800)
ext/afform/core/Civi/Afform/Event/AfformBaseEvent.php [new file with mode: 0644]
ext/afform/core/Civi/Afform/Event/AfformSubmitEvent.php
ext/afform/core/Civi/Api4/Action/Afform/Submit.php

diff --git a/ext/afform/core/Civi/Afform/Event/AfformBaseEvent.php b/ext/afform/core/Civi/Afform/Event/AfformBaseEvent.php
new file mode 100644 (file)
index 0000000..805cb5b
--- /dev/null
@@ -0,0 +1,43 @@
+<?php
+namespace Civi\Afform\Event;
+
+use Symfony\Component\EventDispatcher\Event;
+
+class AfformBaseEvent extends Event {
+
+  /**
+   * @var array
+   *   The main 'Afform' record/configuration.
+   */
+  public $afform;
+
+  /**
+   * @var \Civi\Afform\FormDataModel
+   */
+  public $formDataModel;
+
+  /**
+   * @var \Civi\Api4\Generic\AbstractAction
+   */
+  public $apiRequest;
+
+  /**
+   * AfformBaseEvent constructor.
+   * @param array $afform
+   * @param \Civi\Afform\FormDataModel $formDataModel
+   * @param \Civi\Api4\Generic\AbstractAction $apiRequest
+   */
+  public function __construct(array $afform, \Civi\Afform\FormDataModel $formDataModel, \Civi\Api4\Generic\AbstractAction $apiRequest) {
+    $this->afform = $afform;
+    $this->formDataModel = $formDataModel;
+    $this->apiRequest = $apiRequest;
+  }
+
+  /**
+   * @return \Civi\Api4\Generic\AbstractAction
+   */
+  public function getApiRequest() {
+    return $this->apiRequest;
+  }
+
+}
index 4eff408c40ebbfc33e1b7a878dcb44f8bcccc840..88112fd87302cfe917816da443cb5857ed5e2307 100644 (file)
@@ -1,7 +1,8 @@
 <?php
 namespace Civi\Afform\Event;
 
-use Symfony\Component\EventDispatcher\Event;
+use Civi\Afform\FormDataModel;
+use Civi\Api4\Action\Afform\Submit;
 
 /**
  * Class AfformSubmitEvent
@@ -15,7 +16,7 @@ use Symfony\Component\EventDispatcher\Event;
  * methods. For the moment, this is only expected to be used internally,
  * so KISS.
  */
-class AfformSubmitEvent extends Event {
+class AfformSubmitEvent extends AfformBaseEvent {
 
   /**
    * @var array
@@ -33,10 +34,15 @@ class AfformSubmitEvent extends Event {
 
   /**
    * AfformSubmitEvent constructor.
-   * @param $entityDefns
+   *
+   * @param array $afform
+   * @param \Civi\Afform\FormDataModel $formDataModel
+   * @param \Civi\Api4\Action\Afform\Submit $apiRequest
+   * @param array $entityDefns
    * @param array $entityValues
    */
-  public function __construct($entityDefns, array $entityValues) {
+  public function __construct(array $afform, FormDataModel $formDataModel, Submit $apiRequest, $entityDefns, array $entityValues) {
+    parent::__construct($afform, $formDataModel, $apiRequest);
     $this->entityDefns = $entityDefns;
     $this->entityValues = $entityValues;
   }
index 1f6e3e754c27a21dbcf0ff22f092d5eccb8d1948..dda6a41739b6916b859598680dba33a167cf7fe9 100644 (file)
@@ -32,8 +32,7 @@ class Submit extends AbstractProcessor {
         }
       }
     }
-
-    $event = new AfformSubmitEvent($this->_formDataModel->getEntities(), $entityValues);
+    $event = new AfformSubmitEvent($this->_afform, $this->_formDataModel, $this, $this->_formDataModel->getEntities(), $entityValues);
     \Civi::dispatcher()->dispatch(self::EVENT_NAME, $event);
     foreach ($event->entityValues as $entityType => $entities) {
       if (!empty($entities)) {