Add in unit test of the submit action and re-work as per feedback from coleman
[civicrm-core.git] / ext / afform / core / Civi / Afform / Event / AfformSubmitEvent.php
1 <?php
2 namespace Civi\Afform\Event;
3
4 use Civi\Afform\FormDataModel;
5 use Civi\Api4\Action\Afform\Submit;
6
7 /**
8 * Class AfformSubmitEvent
9 * @package Civi\Afform\Event
10 *
11 * Handle submission of an "<af-form>".
12 * Listeners ought to take any recognized items from `entityValues`, handle
13 * them, and remove them.
14 *
15 * NOTE: I'm on the fence about whether to expose the arrays or more targeted
16 * methods. For the moment, this is only expected to be used internally,
17 * so KISS.
18 */
19 class AfformSubmitEvent extends AfformBaseEvent {
20
21 /**
22 * @var array
23 * Values to be saved for this entity
24 *
25 */
26 public $values;
27
28 /**
29 * @var string
30 * entityType
31 */
32 public $entityType;
33
34 /**
35 * @var string
36 * entityName e.g. Individual1, Activity1,
37 */
38 public $entityName;
39
40 /**
41 * @var array
42 * List of Submitted Entities and their matching ids
43 * $entityIds['Individual1'] = 1;
44 */
45 public $entityIds;
46
47 /**
48 * AfformSubmitEvent constructor.
49 *
50 * @param array $afform
51 * @param \Civi\Afform\FormDataModel $formDataModel
52 * @param \Civi\Api4\Action\Afform\Submit $apiRequest
53 * @param array $values
54 * @param string $entityType
55 * @param string $entityName
56 * @param array $entityIds
57 */
58 public function __construct(array $afform, FormDataModel $formDataModel, Submit $apiRequest, $values, string $entityType, string $entityName, array &$entityIds) {
59 parent::__construct($afform, $formDataModel, $apiRequest);
60 $this->values = $values;
61 $this->entityType = $entityType;
62 $this->entityName = $entityName;
63 $this->entityIds = $entityIds;
64 }
65
66 /**
67 * Set the entity type associated with this event
68 * @param string $entityType
69 */
70 public function setEntityType(string $entityType): void {
71 $this->entityType = $entityType;
72 }
73
74 /**
75 * Set the values associated with this event
76 * @param array $values
77 */
78 public function setValues(array $values): void {
79 $this->values = $values;
80 }
81
82 /**
83 * Set the entity name associated with this event
84 * @param string $entityName
85 */
86 public function setEntityName(string $entityName): void {
87 $this->entityName = $entityName;
88 }
89
90 }