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