Merge pull request #15083 from civicrm/5.17
[civicrm-core.git] / CRM / Admin / Form / Persistent.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
ce064e4f 35 * Customize the output to meet our specific requirements.
6a488035
TO
36 */
37class CRM_Admin_Form_Persistent extends CRM_Core_Form {
38
ce064e4f 39 /**
40 * Pre-process form.
41 */
6a488035
TO
42 public function preProcess() {
43 $this->_indexID = CRM_Utils_Request::retrieve('id', 'Integer', $this, FALSE);
353ffa53
TO
44 $this->_config = CRM_Utils_Request::retrieve('config', 'Integer', $this, 0);
45 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
6a488035
TO
46
47 $session = CRM_Core_Session::singleton();
48 $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/tplstrings', 'reset=1'));
49 CRM_Utils_System::setTitle(ts('DB Template Strings'));
50 parent::preProcess();
51 }
52
e0ef6999 53 /**
ce064e4f 54 * Set default values.
55 *
e0ef6999
EM
56 * @return array
57 */
6a488035 58 public function setDefaultValues() {
be2fb01f 59 $defaults = [];
6a488035
TO
60
61 if ($this->_indexID && ($this->_action & (CRM_Core_Action::UPDATE))) {
be2fb01f 62 $params = ['id' => $this->_indexID];
6a488035
TO
63 CRM_Core_BAO_Persistent::retrieve($params, $defaults);
64 if (CRM_Utils_Array::value('is_config', $defaults) == 1) {
65 $defaults['data'] = implode(',', $defaults['data']);
66 }
67 }
68 return $defaults;
69 }
70
71 public function buildQuickForm() {
72 $this->add('text', 'context', ts('Context:'), NULL, TRUE);
73 $this->add('text', 'name', ts('Name:'), NULL, TRUE);
be2fb01f
CW
74 $this->add('textarea', 'data', ts('Data:'), ['rows' => 4, 'cols' => 50], TRUE);
75 $this->addButtons([
0d48f1cc
TO
76 [
77 'type' => 'submit',
78 'name' => ts('Save'),
79 'isDefault' => TRUE,
80 ],
81 [
82 'type' => 'cancel',
83 'name' => ts('Cancel'),
84 ],
85 ]);
6a488035
TO
86 }
87
88 public function postProcess() {
be2fb01f 89 $params = $ids = [];
6a488035
TO
90 $params = $this->controller->exportValues($this->_name);
91
92 $params['is_config'] = $this->_config;
93
94 if ($this->_action & CRM_Core_Action::ADD) {
95 CRM_Core_Session::setStatus(ts('DB Template has been added successfully.'), ts("Saved"), "success");
96 }
97 if ($this->_action & CRM_Core_Action::UPDATE) {
98 $ids['persistent'] = $this->_indexID;
99 CRM_Core_Session::setStatus(ts('DB Template has been updated successfully.'), ts("Saved"), "success");
100 }
101 CRM_Core_BAO_Persistent::add($params, $ids);
102
103 CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/tplstrings', "reset=1"));
104 }
96025800 105
6a488035 106}