Afform - Use autoservice for event subscribers
authorColeman Watts <coleman@civicrm.org>
Sat, 12 Nov 2022 15:23:57 +0000 (10:23 -0500)
committerColeman Watts <coleman@civicrm.org>
Sat, 12 Nov 2022 21:11:33 +0000 (16:11 -0500)
ext/afform/core/Civi/Afform/Behavior/ContactDedupe.php
ext/afform/core/Civi/Api4/Subscriber/AfformAutocompleteSubscriber.php [moved from ext/afform/core/Civi/Api4/Subscriber/AutocompleteSubscriber.php with 94% similarity]
ext/afform/core/afform.php

index d28d3866473ed1ea95cfa6f40244795e329e4a86..6d47fa1b0d562e25849f62e8801a92b926cc44b1 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-namespace Civi\Afform\behavior;
+namespace Civi\Afform\Behavior;
 
 use Civi\Afform\AbstractBehavior;
 use Civi\Afform\Event\AfformSubmitEvent;
similarity index 94%
rename from ext/afform/core/Civi/Api4/Subscriber/AutocompleteSubscriber.php
rename to ext/afform/core/Civi/Api4/Subscriber/AfformAutocompleteSubscriber.php
index 685a99c95d94a60cb700bf15beba830998a83749..9f88e3cb21efb8a94a1fb80bb8776962df4a7dcc 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace Civi\Api4\Subscriber;
 
+use Civi\Core\Service\AutoService;
 use Civi\Afform\FormDataModel;
 use Civi\API\Events;
 use Civi\Api4\Afform;
@@ -18,8 +19,10 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
 /**
  * Preprocess api autocomplete requests
+ * @service
+ * @internal
  */
-class AutocompleteSubscriber implements EventSubscriberInterface {
+class AfformAutocompleteSubscriber extends AutoService implements EventSubscriberInterface {
 
   /**
    * @return array
@@ -34,7 +37,7 @@ class AutocompleteSubscriber implements EventSubscriberInterface {
    * @param \Civi\API\Event\PrepareEvent $event
    *   API preparation event.
    */
-  public function onApiPrepare(\Civi\API\Event\PrepareEvent $event) {
+  public function onApiPrepare(\Civi\API\Event\PrepareEvent $event): void {
     $apiRequest = $event->getApiRequest();
     if (is_object($apiRequest) && is_a($apiRequest, 'Civi\Api4\Generic\AutocompleteAction')) {
       $formName = $apiRequest->getFormName();
index 5041b7509d34c248e2cb86fd08b0bc7b1375be9b..06f81976155e42a93beeedbfe10434cfaf4c8bd4 100644 (file)
@@ -57,9 +57,6 @@ function afform_civicrm_config(&$config) {
   $dispatcher->addListener('hook_civicrm_alterAngular', ['\Civi\Afform\AfformMetadataInjector', 'preprocess']);
   $dispatcher->addListener('hook_civicrm_check', ['\Civi\Afform\StatusChecks', 'hook_civicrm_check']);
   $dispatcher->addListener('civi.afform.get', ['\Civi\Api4\Action\Afform\Get', 'getCustomGroupBlocks']);
-  $dispatcher->addSubscriber(new \Civi\Api4\Subscriber\AutocompleteSubscriber());
-  $dispatcher->addSubscriber(new \Civi\Afform\Behavior\ContactAutofill());
-  $dispatcher->addSubscriber(new \Civi\Afform\Behavior\ContactDedupe());
 
   // Register support for email tokens
   if (CRM_Extension_System::singleton()->getMapper()->isActiveModule('authx')) {