From: Coleman Watts Date: Sat, 26 Aug 2023 02:14:23 +0000 (-0700) Subject: phpstorm - Generate hints about civicrm_api4() X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a8d33773b9d56af2ca6a44cf6633c6c16b23c1dd;p=civicrm-core.git phpstorm - Generate hints about civicrm_api4() --- diff --git a/tools/extensions/phpstorm/Civi/PhpStorm/Api4Generator.php b/tools/extensions/phpstorm/Civi/PhpStorm/Api4Generator.php new file mode 100644 index 0000000000..62a6f6598d --- /dev/null +++ b/tools/extensions/phpstorm/Civi/PhpStorm/Api4Generator.php @@ -0,0 +1,44 @@ + 'generate', + 'hook_civicrm_post::CustomGroup' => 'generate', + ]; + } + + public function generate() { + /* + * FIXME: PHPSTORM_META doesn't seem to support compound dynamic arguments + * so even if you give it separate lists like + * ``` + * expectedArguments(\civicrm_api4('Contact'), 1, 'a', 'b'); + * expectedArguments(\civicrm_api4('Case'), 1, 'c', 'd'); + * ``` + * It doesn't differentiate them and always offers a,b,c,d for every entity. + * If they ever fix that upstream we could fetch a different list of actions per entity, + * but for now there's no point. + */ + + $entities = \Civi\Api4\Entity::get(FALSE)->addSelect('name')->execute()->column('name'); + $actions = ['get', 'save', 'create', 'update', 'delete', 'replace', 'revert', 'export', 'autocomplete', 'getFields', 'getActions', 'checkAccess']; + + $builder = new PhpStormMetadata('api4', __CLASS__); + $builder->registerArgumentsSet('api4Entities', ...$entities); + $builder->registerArgumentsSet('api4Actions', ...$actions); + $builder->addExpectedArguments('\civicrm_api4()', 0, 'api4Entities'); + $builder->addExpectedArguments('\civicrm_api4()', 1, 'api4Actions'); + $builder->write(); + } + +}