Merge pull request #22152 from eileenmcnaughton/n1
[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 * @since 5.19
23 * @package Civi\Api4
24 */
25 class Route extends \Civi\Api4\Generic\AbstractEntity {
26
27 /**
28 * @param bool $checkPermissions
29 * @return Generic\BasicGetAction
30 */
31 public static function get($checkPermissions = TRUE) {
32 return (new Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
33 $result = [];
34 // Pulling from ::items() rather than DB -- because it provides the final/live/altered data.
35 foreach (\CRM_Core_Menu::items() as $path => $item) {
36 $result[] = ['path' => $path] + $item;
37 }
38 return $result;
39 }))->setCheckPermissions($checkPermissions);
40 }
41
42 /**
43 * @param bool $checkPermissions
44 * @return Generic\BasicGetFieldsAction
45 */
46 public static function getFields($checkPermissions = TRUE) {
47 return (new Generic\BasicGetFieldsAction(__CLASS__, __FUNCTION__, function() {
48 return [
49 [
50 'name' => 'path',
51 'title' => 'Relative Path',
52 'data_type' => 'String',
53 ],
54 [
55 'name' => 'title',
56 'title' => 'Page Title',
57 'data_type' => 'String',
58 ],
59 [
60 'name' => 'page_callback',
61 'title' => 'Page Callback',
62 'data_type' => 'String',
63 ],
64 [
65 'name' => 'page_arguments',
66 'title' => 'Page Arguments',
67 'data_type' => 'String',
68 ],
69 [
70 'name' => 'path_arguments',
71 'title' => 'Path Arguments',
72 'data_type' => 'String',
73 ],
74 [
75 'name' => 'access_arguments',
76 'title' => 'Access Arguments',
77 'data_type' => 'Array',
78 ],
79 ];
80 }))->setCheckPermissions($checkPermissions);
81 }
82
83 /**
84 * @return array
85 */
86 public static function permissions() {
87 return [
88 "meta" => ["access CiviCRM"],
89 "default" => ["administer CiviCRM"],
90 ];
91 }
92
93 }