Commit | Line | Data |
---|---|---|
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 |
11 | namespace Civi\Api4; |
12 | ||
13 | /** | |
14 | * Retrieves information about all Api4 entities. | |
15 | * | |
0493ec47 CW |
16 | * @see \Civi\Api4\Generic\AbstractEntity |
17 | * | |
aa998597 | 18 | * @searchable none |
d44cc3cb | 19 | * @since 5.19 |
19b53e5b C |
20 | * @package Civi\Api4 |
21 | */ | |
22 | class Entity extends Generic\AbstractEntity { | |
23 | ||
24 | /** | |
6764a9d3 | 25 | * @param bool $checkPermissions |
19b53e5b C |
26 | * @return Action\Entity\Get |
27 | */ | |
6764a9d3 CW |
28 | public static function get($checkPermissions = TRUE) { |
29 | return (new Action\Entity\Get('Entity', __FUNCTION__)) | |
30 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
31 | } |
32 | ||
33 | /** | |
6764a9d3 CW |
34 | * @param bool $checkPermissions |
35 | * @return Generic\BasicGetFieldsAction | |
19b53e5b | 36 | */ |
6764a9d3 | 37 | public static function getFields($checkPermissions = TRUE) { |
15244a15 | 38 | return (new Generic\BasicGetFieldsAction('Entity', __FUNCTION__, function(Generic\BasicGetFieldsAction $getFields) { |
19b53e5b | 39 | return [ |
f827fe49 CW |
40 | [ |
41 | 'name' => 'name', | |
42 | 'description' => 'Entity name', | |
43 | ], | |
60f88aac CW |
44 | [ |
45 | 'name' => 'title', | |
9813ae79 CW |
46 | 'description' => 'Localized title (singular)', |
47 | ], | |
48 | [ | |
49 | 'name' => 'title_plural', | |
50 | 'description' => 'Localized title (plural)', | |
60f88aac | 51 | ], |
90908aac CW |
52 | [ |
53 | 'name' => 'type', | |
465bc32a | 54 | 'data_type' => 'Array', |
90908aac | 55 | 'description' => 'Base class for this entity', |
15244a15 | 56 | 'options' => $getFields->getLoadOptions() ? self::getEntityTypes() : TRUE, |
90908aac | 57 | ], |
f827fe49 CW |
58 | [ |
59 | 'name' => 'description', | |
60 | 'description' => 'Description from docblock', | |
61 | ], | |
62 | [ | |
63 | 'name' => 'comment', | |
64 | 'description' => 'Comments from docblock', | |
65 | ], | |
60f88aac CW |
66 | [ |
67 | 'name' => 'icon', | |
68 | 'description' => 'crm-i icon class associated with this entity', | |
69 | ], | |
70 | [ | |
71 | 'name' => 'dao', | |
72 | 'description' => 'Class name for dao-based entities', | |
73 | ], | |
8b6b7576 CW |
74 | [ |
75 | 'name' => 'table_name', | |
76 | 'description' => 'Name of sql table, if applicable', | |
77 | ], | |
482a26e2 | 78 | [ |
b675a457 | 79 | 'name' => 'primary_key', |
650fec8e | 80 | 'data_type' => 'Array', |
b675a457 | 81 | 'description' => 'Name of unique identifier field(s) (e.g. [id])', |
482a26e2 | 82 | ], |
8ab43c93 | 83 | [ |
b441e024 | 84 | 'name' => 'label_field', |
8ab43c93 CW |
85 | 'description' => 'Field to show when displaying a record', |
86 | ], | |
076fe09a CW |
87 | [ |
88 | 'name' => 'order_by', | |
89 | 'description' => 'Default column to sort results', | |
90 | ], | |
09815e9c CW |
91 | [ |
92 | 'name' => 'searchable', | |
aa998597 CW |
93 | 'description' => 'How should this entity be presented in search UIs', |
94 | 'options' => [ | |
95 | 'primary' => ts('Primary'), | |
96 | 'secondary' => ts('Secondary'), | |
c5076889 | 97 | 'bridge' => ts('Bridge'), |
aa998597 CW |
98 | 'none' => ts('None'), |
99 | ], | |
09815e9c | 100 | ], |
a7bd99ff CW |
101 | [ |
102 | 'name' => 'paths', | |
103 | 'data_type' => 'Array', | |
104 | 'description' => 'System paths for accessing this entity', | |
105 | ], | |
f827fe49 CW |
106 | [ |
107 | 'name' => 'see', | |
e15f9453 | 108 | 'data_type' => 'Array', |
f827fe49 CW |
109 | 'description' => 'Any @see annotations from docblock', |
110 | ], | |
d44cc3cb CW |
111 | [ |
112 | 'name' => 'since', | |
113 | 'data_type' => 'String', | |
114 | 'description' => 'Version this API entity was added', | |
115 | ], | |
a75e3a97 CW |
116 | [ |
117 | 'name' => 'class', | |
118 | 'data_type' => 'String', | |
119 | 'description' => 'PHP class name', | |
120 | ], | |
e01b30d7 CW |
121 | [ |
122 | 'name' => 'class_args', | |
123 | 'data_type' => 'Array', | |
124 | 'description' => 'Arguments needed by php action factory functions (used when multiple entities share a class, e.g. CustomValue).', | |
125 | ], | |
c5368b3b CW |
126 | [ |
127 | 'name' => 'bridge', | |
128 | 'data_type' => 'Array', | |
129 | 'description' => 'Connecting fields for EntityBridge types', | |
130 | ], | |
2f616560 CW |
131 | [ |
132 | 'name' => 'ui_join_filters', | |
133 | 'data_type' => 'Array', | |
134 | 'description' => 'When joining entities in the UI, which fields should be presented by default in the ON clause', | |
135 | ], | |
204c3c29 CW |
136 | [ |
137 | 'name' => 'group_weights_by', | |
138 | 'data_type' => 'Array', | |
139 | 'description' => 'For sortable entities, what field groupings are used to order by weight', | |
140 | ], | |
19b53e5b | 141 | ]; |
6764a9d3 | 142 | }))->setCheckPermissions($checkPermissions); |
19b53e5b C |
143 | } |
144 | ||
145 | /** | |
6764a9d3 | 146 | * @param bool $checkPermissions |
ac018ab9 | 147 | * @deprecated |
19b53e5b C |
148 | * @return Action\Entity\GetLinks |
149 | */ | |
6764a9d3 CW |
150 | public static function getLinks($checkPermissions = TRUE) { |
151 | return (new Action\Entity\GetLinks('Entity', __FUNCTION__)) | |
152 | ->setCheckPermissions($checkPermissions); | |
19b53e5b C |
153 | } |
154 | ||
155 | /** | |
156 | * @return array | |
157 | */ | |
158 | public static function permissions() { | |
159 | return [ | |
160 | 'default' => ['access CiviCRM'], | |
161 | ]; | |
162 | } | |
163 | ||
15244a15 CW |
164 | /** |
165 | * Collect the 'type' values from every entity. | |
166 | * | |
167 | * @return array | |
168 | */ | |
169 | private static function getEntityTypes() { | |
170 | $provider = \Civi::service('action_object_provider'); | |
171 | $entityTypes = []; | |
172 | foreach ($provider->getEntities() as $entity) { | |
173 | foreach ($entity['type'] ?? [] as $type) { | |
174 | $entityTypes[$type] = $type; | |
175 | } | |
176 | } | |
177 | return $entityTypes; | |
178 | } | |
179 | ||
19b53e5b | 180 | } |