Merge pull request #23965 from MegaphoneJon/contribution-view-perm-fix
[civicrm-core.git] / Civi / Api4 / Extension.php
CommitLineData
510b3477
CW
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 */
11namespace Civi\Api4;
12
13/**
14 * Extensions - add-on modules extend the functionality of CiviCRM.
15 *
16 * @see https://docs.civicrm.org/user/en/latest/introduction/extensions/
17 * @searchable secondary
18 * @since 5.48
19 * @package Civi\Api4
20 */
21class Extension extends Generic\AbstractEntity {
22
23 /**
24 * @param bool $checkPermissions
25 * @return Generic\BasicGetAction
26 */
27 public static function get($checkPermissions = TRUE) {
28 return (new Generic\BasicGetAction(__CLASS__, __FUNCTION__, function($action) {
29 $statuses = \CRM_Extension_System::singleton()->getManager()->getStatuses();
30 $mapper = \CRM_Extension_System::singleton()->getMapper();
31 $result = [];
32 foreach ($statuses as $key => $status) {
33 try {
34 $obj = $mapper->keyToInfo($key);
35 $info = \CRM_Extension_System::createExtendedInfo($obj);
36 $result[] = $info;
37 }
38 catch (\CRM_Extension_Exception $ex) {
39 \Civi::log()->error(sprintf('Failed to read extension (%1). Please refresh the extension list.', [1 => $key]));
40 }
41 }
42 return $result;
43 }))->setCheckPermissions($checkPermissions);
44 }
45
46 /**
47 * @param bool $checkPermissions
48 * @return Generic\BasicGetFieldsAction
49 */
50 public static function getFields($checkPermissions = TRUE) {
51 return (new Generic\BasicGetFieldsAction(static::getEntityName(), __FUNCTION__, function() {
52 return [
53 [
54 'name' => 'key',
55 'description' => 'Long, unique extension identifier',
56 ],
57 [
58 'name' => 'file',
59 'description' => 'Short, unique extension identifier',
60 ],
61 [
62 'name' => 'label',
63 'description' => 'User-facing extension title',
64 ],
65 [
66 'name' => 'description',
67 'description' => 'Additional information about the extension',
68 ],
69 [
70 'name' => 'version',
71 'description' => 'Current version number (string)',
72 ],
73 [
74 'name' => 'tags',
75 'data_type' => 'Array',
76 'description' => "Tags which characterize the extension's purpose or functionality",
77 ],
78 [
79 'name' => 'status',
80 'description' => 'Extension enabled/disabled/uninstalled status',
81 'options' => [
82 \CRM_Extension_Manager::STATUS_UNINSTALLED => ts('Uninstalled'),
83 \CRM_Extension_Manager::STATUS_DISABLED => ts('Disabled'),
84 \CRM_Extension_Manager::STATUS_INSTALLED => ts('Enabled'),
85 \CRM_Extension_Manager::STATUS_DISABLED_MISSING => ts('Disabled (Missing)'),
86 \CRM_Extension_Manager::STATUS_INSTALLED_MISSING => ts('Enabled (Missing)'),
87 ],
88 ],
89 ];
90 }))->setCheckPermissions($checkPermissions);
91 }
92
93 /**
94 * @inheritDoc
95 */
96 public static function getInfo() {
97 $info = parent::getInfo();
98 $info['title'] = ts('Extension');
99 $info['title_plural'] = ts('Extensions');
100 $info['primary_key'] = ['key'];
101 $info['label_field'] = 'label';
102 return $info;
103 }
104
105}