88112fd87302cfe917816da443cb5857ed5e2307
[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 * AfformSubmitEvent constructor.
37 *
38 * @param array $afform
39 * @param \Civi\Afform\FormDataModel $formDataModel
40 * @param \Civi\Api4\Action\Afform\Submit $apiRequest
41 * @param array $entityDefns
42 * @param array $entityValues
43 */
44 public function __construct(array $afform, FormDataModel $formDataModel, Submit $apiRequest, $entityDefns, array $entityValues) {
45 parent::__construct($afform, $formDataModel, $apiRequest);
46 $this->entityDefns = $entityDefns;
47 $this->entityValues = $entityValues;
48 }
49
50 /**
51 * List of entity types which need processing.
52 *
53 * @return array
54 * Ex: ['Contact', 'Activity']
55 */
56 public function getTypes() {
57 return array_keys($this->entityValues);
58 }
59
60 }