Merge pull request #20741 from civicrm/5.39
[civicrm-core.git] / Civi / Api4 / Route.php
CommitLineData
19b53e5b 1<?php
380f3545
TO
2/*
3 +--------------------------------------------------------------------+
41498ac5 4 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 5 | |
41498ac5
TO
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 |
380f3545
TO
9 +--------------------------------------------------------------------+
10 */
19b53e5b
C
11namespace Civi\Api4;
12
0493ec47
CW
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/
aa998597 21 * @searchable none
d44cc3cb 22 * @since 5.19
0493ec47
CW
23 * @package Civi\Api4
24 */
19b53e5b
C
25class Route extends \Civi\Api4\Generic\AbstractEntity {
26
27 /**
6764a9d3 28 * @param bool $checkPermissions
f48d7e65 29 * @return Generic\BasicGetAction
19b53e5b 30 */
6764a9d3 31 public static function get($checkPermissions = TRUE) {
f48d7e65 32 return (new Generic\BasicGetAction(__CLASS__, __FUNCTION__, function ($get) {
19b53e5b 33 $result = [];
f48d7e65
CW
34 // Pulling from ::items() rather than DB -- because it provides the final/live/altered data.
35 foreach (\CRM_Core_Menu::items() as $path => $item) {
19b53e5b
C
36 $result[] = ['path' => $path] + $item;
37 }
38 return $result;
6764a9d3 39 }))->setCheckPermissions($checkPermissions);
19b53e5b
C
40 }
41
6764a9d3
CW
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() {
19b53e5b
C
48 return [
49 [
50 'name' => 'path',
51 'title' => 'Relative Path',
19b53e5b
C
52 'data_type' => 'String',
53 ],
54 [
55 'name' => 'title',
56 'title' => 'Page Title',
19b53e5b
C
57 'data_type' => 'String',
58 ],
59 [
60 'name' => 'page_callback',
61 'title' => 'Page Callback',
19b53e5b
C
62 'data_type' => 'String',
63 ],
64 [
65 'name' => 'page_arguments',
66 'title' => 'Page Arguments',
19b53e5b
C
67 'data_type' => 'String',
68 ],
69 [
70 'name' => 'path_arguments',
71 'title' => 'Path Arguments',
19b53e5b
C
72 'data_type' => 'String',
73 ],
74 [
75 'name' => 'access_arguments',
76 'title' => 'Access Arguments',
19b53e5b
C
77 'data_type' => 'Array',
78 ],
79 ];
6764a9d3 80 }))->setCheckPermissions($checkPermissions);
19b53e5b
C
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}