Commit | Line | Data |
---|---|---|
19b53e5b | 1 | <?php |
380f3545 TO |
2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
41498ac5 | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
41498ac5 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 | */ |
18 | ||
19b53e5b C |
19 | namespace Civi\Api4; |
20 | ||
0493ec47 CW |
21 | /** |
22 | * CiviCRM menu route. | |
23 | * | |
24 | * Provides page routes registered in the CiviCRM menu system. | |
25 | * | |
26 | * Note: this is a read-only api as routes are set via xml files and hooks. | |
27 | * | |
28 | * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMenu/ | |
09815e9c | 29 | * @searchable false |
0493ec47 CW |
30 | * @package Civi\Api4 |
31 | */ | |
19b53e5b C |
32 | class Route extends \Civi\Api4\Generic\AbstractEntity { |
33 | ||
34 | /** | |
6764a9d3 | 35 | * @param bool $checkPermissions |
19b53e5b C |
36 | * @return \Civi\Api4\Generic\BasicGetAction |
37 | */ | |
6764a9d3 CW |
38 | public static function get($checkPermissions = TRUE) { |
39 | return (new \Civi\Api4\Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) { | |
19b53e5b C |
40 | // Pulling from ::items() rather than DB -- because it provides the final/live/altered data. |
41 | $items = \CRM_Core_Menu::items(); | |
42 | $result = []; | |
43 | foreach ($items as $path => $item) { | |
44 | $result[] = ['path' => $path] + $item; | |
45 | } | |
46 | return $result; | |
6764a9d3 | 47 | }))->setCheckPermissions($checkPermissions); |
19b53e5b C |
48 | } |
49 | ||
6764a9d3 CW |
50 | /** |
51 | * @param bool $checkPermissions | |
52 | * @return Generic\BasicGetFieldsAction | |
53 | */ | |
54 | public static function getFields($checkPermissions = TRUE) { | |
55 | return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() { | |
19b53e5b C |
56 | return [ |
57 | [ | |
58 | 'name' => 'path', | |
59 | 'title' => 'Relative Path', | |
60 | 'required' => TRUE, | |
61 | 'data_type' => 'String', | |
62 | ], | |
63 | [ | |
64 | 'name' => 'title', | |
65 | 'title' => 'Page Title', | |
66 | 'required' => TRUE, | |
67 | 'data_type' => 'String', | |
68 | ], | |
69 | [ | |
70 | 'name' => 'page_callback', | |
71 | 'title' => 'Page Callback', | |
72 | 'required' => TRUE, | |
73 | 'data_type' => 'String', | |
74 | ], | |
75 | [ | |
76 | 'name' => 'page_arguments', | |
77 | 'title' => 'Page Arguments', | |
78 | 'required' => FALSE, | |
79 | 'data_type' => 'String', | |
80 | ], | |
81 | [ | |
82 | 'name' => 'path_arguments', | |
83 | 'title' => 'Path Arguments', | |
84 | 'required' => FALSE, | |
85 | 'data_type' => 'String', | |
86 | ], | |
87 | [ | |
88 | 'name' => 'access_arguments', | |
89 | 'title' => 'Access Arguments', | |
90 | 'required' => FALSE, | |
91 | 'data_type' => 'Array', | |
92 | ], | |
93 | ]; | |
6764a9d3 | 94 | }))->setCheckPermissions($checkPermissions); |
19b53e5b C |
95 | } |
96 | ||
97 | /** | |
98 | * @return array | |
99 | */ | |
100 | public static function permissions() { | |
101 | return [ | |
102 | "meta" => ["access CiviCRM"], | |
103 | "default" => ["administer CiviCRM"], | |
104 | ]; | |
105 | } | |
106 | ||
107 | } |