2 namespace Civi\Afform\Event
;
4 use Civi\Afform\FormDataModel
;
5 use Civi\Api4\Action\Afform\Submit
;
8 * Class AfformSubmitEvent
9 * @package Civi\Afform\Event
11 * Handle submission of an "<af-form>".
12 * Listeners ought to take any recognized items from `entityValues`, handle
13 * them, and remove them.
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,
19 class AfformSubmitEvent
extends AfformBaseEvent
{
23 * List of definitions of the entities.
24 * $entityDefns['spouse'] = ['type' => 'Individual'];
30 * List of submitted entities to save.
31 * $entityValues['Contact']['spouse'] = ['first_name' => 'Optimus Prime'];
37 * List of Submitted Entities and their matching ids
38 * $entityIds['Individual1'] = 1;
42 public $entityWeights;
44 public $entityMapping;
47 * AfformSubmitEvent constructor.
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
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;
68 * List of entity types which need processing.
71 * Ex: ['Contact', 'Activity']
73 public function getTypes() {
74 return array_keys($this->entityValues
);