f2bdf951aa6de02bc05be7697e20b325b4580676
[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 * List of definitions of the entities.
24 * $entityDefns['spouse'] = ['type' => 'Individual'];
25 */
26 public $entityDefns;
27
28 /**
29 * @var array
30 * List of submitted entities to save.
31 * $entityValues['Contact']['spouse'] = ['first_name' => 'Optimus Prime'];
32 */
33 public $entityValues;
34
35 /**
36 * @var array
37 * List of Submitted Entities and their matching ids
38 * $entityIds['Individual1'] = 1;
39 */
40 public $entityIds;
41
42 public $entityWeights;
43
44 public $entityMapping;
45
46 /**
47 * AfformSubmitEvent constructor.
48 *
49 * @param array $afform
50 * @param \Civi\Afform\FormDataModel $formDataModel
51 * @param \Civi\Api4\Action\Afform\Submit $apiRequest
52 * @param array $entityDefns
53 * @param array $entityValues
54 * @param array $entityIds
55 * @param array $entityWeights
56 * @param array $entityMapping
57 */
58 public function __construct(array $afform, FormDataModel $formDataModel, Submit $apiRequest, $entityDefns, array $entityValues, array $entityIds, array $entityWeights, array $entityMapping) {
59 parent::__construct($afform, $formDataModel, $apiRequest);
60 $this->entityDefns = $entityDefns;
61 $this->entityValues = $entityValues;
62 $this->entityIds = $entityIds;
63 $this->entityWeights = $entityWeights;
64 $this->entityMapping = $entityMapping;
65 }
66
67 /**
68 * List of entity types which need processing.
69 *
70 * @return array
71 * Ex: ['Contact', 'Activity']
72 */
73 public function getTypes() {
74 return array_keys($this->entityValues);
75 }
76
77 }