phpstorm - Generate event hints for "hook_civicrm_pre::Entity" (and similar)
authorTim Otten <totten@civicrm.org>
Sat, 26 Aug 2023 02:59:34 +0000 (19:59 -0700)
committerTim Otten <totten@civicrm.org>
Sat, 26 Aug 2023 02:59:34 +0000 (19:59 -0700)
tools/extensions/phpstorm/Civi/PhpStorm/EventGenerator.php

index 561e95ec968e9c4339d164f0814b3c6dabe70d25..81202ff2ffcbb14139cac6a838dbe3745849593c 100644 (file)
@@ -22,8 +22,21 @@ class EventGenerator extends AutoService implements EventSubscriberInterface {
   public function generate() {
     $inspector = new CiviEventInspector();
 
+    $entities = \Civi\Api4\Entity::get(FALSE)->addSelect('name')->execute()->column('name');
+    $specialEvents = ['hook_civicrm_post', 'hook_civicrm_pre', 'civi.api4.validate'];
+    foreach ($entities as $entity) {
+      foreach ($specialEvents as $specialEvent) {
+        $entityEvents [] = "$specialEvent::$entity";
+      }
+    }
+    // PHP 7.4 can simplify:
+    // $entityEvents = array_map(fn($pair) => implode('::', $pair), \CRM_Utils_Array::product([$entities, $specialEvents]));
+
+
+    $all = array_merge(array_keys($inspector->getAll()), $entityEvents);
+
     $builder = new PhpStormMetadata('events', __CLASS__);
-    $builder->registerArgumentsSet('events', ...array_keys($inspector->getAll()));
+    $builder->registerArgumentsSet('events', ...$all);
 
     foreach ([CiviEventDispatcher::class, CiviEventDispatcherInterface::class] as $class) {
       foreach (['dispatch', 'addListener', 'removeListener', 'getListeners', 'hasListeners'] as $method) {