Merge pull request #16868 from twomice/contribution_detail_pledge
[civicrm-core.git] / CRM / Api4 / Page / Api4Explorer.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20 class CRM_Api4_Page_Api4Explorer extends CRM_Core_Page {
21
22 public function run() {
23 $apiDoc = new ReflectionFunction('civicrm_api4');
24 $groupOptions = civicrm_api4('Group', 'getFields', ['loadOptions' => TRUE, 'select' => ['options', 'name'], 'where' => [['name', 'IN', ['visibility', 'group_type']]]]);
25 $vars = [
26 'operators' => \CRM_Core_DAO::acceptedSQLOperators(),
27 'basePath' => Civi::resources()->getUrl('civicrm'),
28 'schema' => (array) \Civi\Api4\Entity::get()->setChain(['fields' => ['$name', 'getFields']])->execute(),
29 'links' => (array) \Civi\Api4\Entity::getLinks()->execute(),
30 'docs' => \Civi\Api4\Utils\ReflectionUtils::parseDocBlock($apiDoc->getDocComment()),
31 'groupOptions' => array_column((array) $groupOptions, 'options', 'name'),
32 ];
33 Civi::resources()
34 ->addVars('api4', $vars)
35 ->addPermissions(['access debug output', 'edit groups', 'administer reserved groups'])
36 ->addScriptFile('civicrm', 'js/load-bootstrap.js')
37 ->addScriptFile('civicrm', 'bower_components/js-yaml/dist/js-yaml.min.js')
38 ->addScriptFile('civicrm', 'bower_components/marked/marked.min.js')
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 }