2eea4c39b435f0aedaaa03128275368296d7bb2b
[civicrm-core.git] / Civi / Api4 / Route.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11 namespace Civi\Api4;
12
13 /**
14 * CiviCRM menu route.
15 *
16 * Provides page routes registered in the CiviCRM menu system.
17 *
18 * Note: this is a read-only api as routes are set via xml files and hooks.
19 *
20 * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMenu/
21 * @searchable none
22 * @package Civi\Api4
23 */
24 class Route extends \Civi\Api4\Generic\AbstractEntity {
25
26 /**
27 * @param bool $checkPermissions
28 * @return Generic\BasicGetAction
29 */
30 public static function get($checkPermissions = TRUE) {
31 return (new Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
32 $result = [];
33 // Pulling from ::items() rather than DB -- because it provides the final/live/altered data.
34 foreach (\CRM_Core_Menu::items() as $path => $item) {
35 $result[] = ['path' => $path] + $item;
36 }
37 return $result;
38 }))->setCheckPermissions($checkPermissions);
39 }
40
41 /**
42 * @param bool $checkPermissions
43 * @return Generic\BasicGetFieldsAction
44 */
45 public static function getFields($checkPermissions = TRUE) {
46 return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
47 return [
48 [
49 'name' => 'path',
50 'title' => 'Relative Path',
51 'data_type' => 'String',
52 ],
53 [
54 'name' => 'title',
55 'title' => 'Page Title',
56 'data_type' => 'String',
57 ],
58 [
59 'name' => 'page_callback',
60 'title' => 'Page Callback',
61 'data_type' => 'String',
62 ],
63 [
64 'name' => 'page_arguments',
65 'title' => 'Page Arguments',
66 'data_type' => 'String',
67 ],
68 [
69 'name' => 'path_arguments',
70 'title' => 'Path Arguments',
71 'data_type' => 'String',
72 ],
73 [
74 'name' => 'access_arguments',
75 'title' => 'Access Arguments',
76 'data_type' => 'Array',
77 ],
78 ];
79 }))->setCheckPermissions($checkPermissions);
80 }
81
82 /**
83 * @return array
84 */
85 public static function permissions() {
86 return [
87 "meta" => ["access CiviCRM"],
88 "default" => ["administer CiviCRM"],
89 ];
90 }
91
92 }