From c2053dfb70d7a71fa50b274211761b0e04e698f2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 25 Aug 2023 19:59:34 -0700 Subject: [PATCH] phpstorm - Generate event hints for "hook_civicrm_pre::Entity" (and similar) --- .../phpstorm/Civi/PhpStorm/EventGenerator.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/extensions/phpstorm/Civi/PhpStorm/EventGenerator.php b/tools/extensions/phpstorm/Civi/PhpStorm/EventGenerator.php index 561e95ec96..81202ff2ff 100644 --- a/tools/extensions/phpstorm/Civi/PhpStorm/EventGenerator.php +++ b/tools/extensions/phpstorm/Civi/PhpStorm/EventGenerator.php @@ -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) { -- 2.25.1