Skip to content

Commit

Permalink
CIVIPLUS-180: Simplify afform event naming
Browse files Browse the repository at this point in the history
  • Loading branch information
ahed-compucorp committed Jun 8, 2021
1 parent 6321d16 commit bca2359
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ext/afform/core/Civi/Api4/Action/Afform/Submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*/
class Submit extends AbstractProcessor {

/**
* @deprecated - You may simply use the event name directly. dev/core#1744
*/
const EVENT_NAME = 'civi.afform.submit';

/**
Expand All @@ -34,7 +37,7 @@ protected function processForm() {
}

$event = new AfformSubmitEvent($this->_formDataModel->getEntities(), $entityValues);
\Civi::dispatcher()->dispatch(self::EVENT_NAME, $event);
\Civi::dispatcher()->dispatch('civi.afform.submit', $event);
foreach ($event->entityValues as $entityType => $entities) {
if (!empty($entities)) {
throw new \API_Exception(sprintf("Failed to process entities (type=%s; name=%s)", $entityType, implode(',', array_keys($entities))));
Expand Down
5 changes: 2 additions & 3 deletions ext/afform/core/afform.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_once 'afform.civix.php';
use CRM_Afform_ExtensionUtil as E;
use Civi\Api4\Action\Afform\Submit;

/**
* Filter the content of $params to only have supported afform fields.
Expand Down Expand Up @@ -49,8 +48,8 @@ function afform_civicrm_config(&$config) {
}
Civi::$statics[__FUNCTION__] = 1;

Civi::dispatcher()->addListener(Submit::EVENT_NAME, [Submit::class, 'processContacts'], 500);
Civi::dispatcher()->addListener(Submit::EVENT_NAME, [Submit::class, 'processGenericEntity'], -1000);
Civi::dispatcher()->addListener('civi.afform.submit', ['\Civi\Api4\Action\Afform\Submit', 'processContacts'], 500);
Civi::dispatcher()->addListener('civi.afform.submit', ['\Civi\Api4\Action\Afform\Submit', 'processGenericEntity'], -1000);
Civi::dispatcher()->addListener('hook_civicrm_angularModules', ['\Civi\Afform\AngularDependencyMapper', 'autoReq'], -1000);
Civi::dispatcher()->addListener('hook_civicrm_alterAngular', ['\Civi\Afform\AfformMetadataInjector', 'preprocess']);
}
Expand Down

0 comments on commit bca2359

Please sign in to comment.