WIP Entity Reference Submission fields
[civicrm-core.git] / ext / afform / core / Civi / Afform / Event / AfformSubmitEvent.php
CommitLineData
fb388832
TO
1<?php
2namespace Civi\Afform\Event;
3
c4838b3d
TO
4use Civi\Afform\FormDataModel;
5use Civi\Api4\Action\Afform\Submit;
fb388832
TO
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 */
c4838b3d 19class AfformSubmitEvent extends AfformBaseEvent {
fb388832
TO
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
37bc0f61
SL
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
fb388832
TO
46 /**
47 * AfformSubmitEvent constructor.
c4838b3d
TO
48 *
49 * @param array $afform
50 * @param \Civi\Afform\FormDataModel $formDataModel
51 * @param \Civi\Api4\Action\Afform\Submit $apiRequest
52 * @param array $entityDefns
fb388832 53 * @param array $entityValues
37bc0f61
SL
54 * @param array $entityIds
55 * @param array $entityWeights
56 * @param array $entityMapping
fb388832 57 */
37bc0f61 58 public function __construct(array $afform, FormDataModel $formDataModel, Submit $apiRequest, $entityDefns, array $entityValues, array $entityIds, array $entityWeights, array $entityMapping) {
c4838b3d 59 parent::__construct($afform, $formDataModel, $apiRequest);
fb388832
TO
60 $this->entityDefns = $entityDefns;
61 $this->entityValues = $entityValues;
37bc0f61
SL
62 $this->entityIds = $entityIds;
63 $this->entityWeights = $entityWeights;
64 $this->entityMapping = $entityMapping;
fb388832
TO
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}