Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
bc77d7c0 TO |
7 | | This work is published under the GNU AGPLv3 license with some | |
8 | | permitted exceptions and without any warranty. For full license | | |
9 | | and copyright information, see https://civicrm.org/licensing | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
19b53e5b C |
20 | class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page { |
21 | ||
22 | public function run() { | |
9cea3619 | 23 | $apiDoc = new ReflectionFunction('civicrm_api4'); |
d7507e89 | 24 | $groupOptions = civicrm_api4('Group', 'getFields', ['loadOptions' => TRUE, 'select' => ['options', 'name'], 'where' => [['name', 'IN', ['visibility', 'group_type']]]]); |
19b53e5b C |
25 | $vars = [ |
26 | 'operators' => \CRM_Core_DAO::acceptedSQLOperators(), | |
cdeee725 | 27 | 'basePath' => Civi::resources()->getUrl('civicrm'), |
19b53e5b C |
28 | 'schema' => (array) \Civi\Api4\Entity::get()->setChain(['fields' => ['$name', 'getFields']])->execute(), |
29 | 'links' => (array) \Civi\Api4\Entity::getLinks()->execute(), | |
9cea3619 | 30 | 'docs' => \Civi\Api4\Utils\ReflectionUtils::parseDocBlock($apiDoc->getDocComment()), |
d7507e89 | 31 | 'groupOptions' => array_column((array) $groupOptions, 'options', 'name'), |
19b53e5b C |
32 | ]; |
33 | Civi::resources() | |
34 | ->addVars('api4', $vars) | |
d7507e89 | 35 | ->addPermissions(['access debug output', 'edit groups', 'administer reserved groups']) |
cdeee725 | 36 | ->addScriptFile('civicrm', 'js/load-bootstrap.js') |
0b873c9a | 37 | ->addScriptFile('civicrm', 'bower_components/js-yaml/dist/js-yaml.min.js') |
136ca5bb | 38 | ->addScriptFile('civicrm', 'bower_components/marked/marked.min.js') |
19b53e5b C |
39 | ->addScriptFile('civicrm', 'bower_components/google-code-prettify/bin/prettify.min.js') |
40 | ->addStyleFile('civicrm', 'bower_components/google-code-prettify/bin/prettify.min.css'); | |
41 | ||
42 | $loader = new Civi\Angular\AngularLoader(); | |
43 | $loader->setModules(['api4Explorer']); | |
44 | $loader->setPageName('civicrm/api4'); | |
45 | $loader->useApp([ | |
46 | 'defaultRoute' => '/explorer', | |
47 | ]); | |
48 | $loader->load(); | |
49 | parent::run(); | |
50 | } | |
51 | ||
52 | } |