3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for Extensions.
21 class CRM_Admin_Form_Extensions
extends CRM_Admin_Form
{
24 * Form pre-processing.
26 public function preProcess() {
29 $mainPage = new CRM_Admin_Page_Extensions();
30 $localExtensionRows = $mainPage->formatLocalExtensionRows();
31 $this->assign('localExtensionRows', $localExtensionRows);
33 $remoteExtensionRows = $mainPage->formatRemoteExtensionRows($localExtensionRows);
34 $this->assign('remoteExtensionRows', $remoteExtensionRows);
36 $this->_key
= CRM_Utils_Request
::retrieve('key', 'String',
39 if (!CRM_Utils_Type
::validate($this->_key
, 'ExtensionKey') && !empty($this->_key
)) {
40 throw new CRM_Core_Exception('Extension Key does not match expected standard');
42 $session = CRM_Core_Session
::singleton();
43 $url = CRM_Utils_System
::url('civicrm/admin/extensions', 'reset=1&action=browse');
44 $session->pushUserContext($url);
45 $this->assign('id', $this->_id
);
46 $this->assign('key', $this->_key
);
48 switch ($this->_action
) {
49 case CRM_Core_Action
::ADD
:
50 case CRM_Core_Action
::DELETE
:
51 case CRM_Core_Action
::ENABLE
:
52 case CRM_Core_Action
::DISABLE
:
53 $info = CRM_Extension_System
::singleton()->getMapper()->keyToInfo($this->_key
);
54 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
55 $this->assign('extension', $extInfo);
58 case CRM_Core_Action
::UPDATE
:
59 if (!CRM_Extension_System
::singleton()->getBrowser()->isEnabled()) {
60 CRM_Core_Error
::statusBounce(ts('The system administrator has disabled this feature.'));
62 $info = CRM_Extension_System
::singleton()->getBrowser()->getExtension($this->_key
);
63 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
64 $this->assign('extension', $extInfo);
68 CRM_Core_Error
::statusBounce(ts('Unsupported action'));
74 * Set default values for the form.
76 public function setDefaultValues() {
82 * Build the form object.
84 public function buildQuickForm() {
85 switch ($this->_action
) {
86 case CRM_Core_Action
::ADD
:
87 $buttonName = ts('Install');
88 $title = ts('Install "%1"?', [
93 case CRM_Core_Action
::UPDATE
:
94 $buttonName = ts('Download and Install');
95 $title = ts('Download and Install "%1"?', [
100 case CRM_Core_Action
::DELETE
:
101 $buttonName = ts('Uninstall');
102 $title = ts('Uninstall "%1"?', [
107 case CRM_Core_Action
::ENABLE
:
108 $buttonName = ts('Enable');
109 $title = ts('Enable "%1"?', [
114 case CRM_Core_Action
::DISABLE
:
115 $buttonName = ts('Disable');
116 $title = ts('Disable "%1"?', [
122 $this->assign('title', $title);
126 'name' => $buttonName,
131 'name' => ts('Cancel'),
139 * @param array $fields
140 * The input form values.
141 * @param array $files
142 * The uploaded files if any.
147 * true if no errors, else an array of errors
149 public static function formRule($fields, $files, $self) {
152 return empty($errors) ?
TRUE : $errors;
156 * Process the form submission.
158 public function postProcess() {
159 CRM_Utils_System
::flushCache();
161 if ($this->_action
& CRM_Core_Action
::DELETE
) {
163 CRM_Extension_System
::singleton()->getManager()->uninstall([$this->_key
]);
164 CRM_Core_Session
::setStatus("", ts('Extension Uninstalled'), "success");
166 catch (CRM_Extension_Exception_DependencyException
$e) {
167 // currently only thrown for payment-processor dependencies
168 CRM_Core_Session
::setStatus(ts('Cannot uninstall this extension - there is at least one payment processor using the payment processor type provided by it.'), ts('Uninstall Error'), 'error');
172 if ($this->_action
& CRM_Core_Action
::ADD
) {
173 civicrm_api3('Extension', 'install', ['keys' => $this->_key
]);
174 CRM_Core_Session
::setStatus("", ts('Extension Installed'), "success");
177 if ($this->_action
& CRM_Core_Action
::ENABLE
) {
178 civicrm_api3('Extension', 'enable', ['keys' => $this->_key
]);
179 CRM_Core_Session
::setStatus("", ts('Extension Enabled'), "success");
182 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
183 CRM_Extension_System
::singleton()->getManager()->disable([$this->_key
]);
184 CRM_Core_Session
::setStatus("", ts('Extension Disabled'), "success");
187 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
188 $result = civicrm_api('Extension', 'download', [
190 'key' => $this->_key
,
192 if (empty($result['is_error'])) {
193 CRM_Core_Session
::setStatus("", ts('Extension Upgraded'), "success");
196 CRM_Core_Session
::setStatus($result['error_message'], ts('Extension Upgrade Failed'), "error");
200 CRM_Utils_System
::redirect(
201 CRM_Utils_System
::url(
202 'civicrm/admin/extensions',
203 'reset=1&action=browse'