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
17 class CRM_Contribute_Form_ContributionPage_Widget
extends CRM_Contribute_Form_ContributionPage
{
22 public function preProcess() {
24 $this->setSelectedChild('widget');
26 $this->_widget
= new CRM_Contribute_DAO_Widget();
27 $this->_widget
->contribution_page_id
= $this->_id
;
28 if (!$this->_widget
->find(TRUE)) {
29 $this->_widget
= NULL;
32 $this->assign('widget_id', $this->_widget
->id
);
34 // check of home url is set, if set then it flash widget might be in use.
35 $this->assign('showStatus', FALSE);
36 if ($this->_widget
->url_homepage
) {
37 $this->assign('showStatus', TRUE);
41 $this->assign('cpageId', $this->_id
);
43 $this->assign('widgetExternUrl', CRM_Utils_System
::externUrl('extern/widget', "cpageId={$this->_id}&widgetId=" . ($this->_widget
->id ??
'') . "&format=3"));
45 $config = CRM_Core_Config
::singleton();
46 $title = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage',
59 ts('URL to Logo Image'),
72 $this->_colorFields
= [
74 ts('Title Text Color'),
80 ts('Progress Bar Color'),
85 'color_main_text' => [
86 ts('Additional Text Color'),
92 ts('Background Color'),
98 ts('Background Color Top Area'),
109 'color_about_link' => [
110 ts('Button Text Color'),
116 ts('Button Background Color'),
121 'color_homepage_link' => [
122 ts('Homepage Link Color'),
131 * Set default values for the form.
133 public function setDefaultValues() {
135 // check if there is a widget already created
136 if ($this->_widget
) {
137 CRM_Core_DAO
::storeValues($this->_widget
, $defaults);
140 foreach ($this->_fields
as $name => $val) {
141 $defaults[$name] = $val[3];
143 foreach ($this->_colorFields
as $name => $val) {
144 $defaults[$name] = $val[3];
146 $defaults['about'] = CRM_Core_DAO
::getFieldValue('CRM_Contribute_DAO_ContributionPage',
152 $showHide = new CRM_Core_ShowHideBlocks();
153 $showHide->addHide('id-colors');
154 $showHide->addToTemplate();
158 public function buildQuickForm() {
159 $attributes = CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Widget');
161 $this->addElement('checkbox',
163 ts('Enable Widget?'),
165 ['onclick' => "widgetBlock(this)"]
168 $this->add('wysiwyg', 'about', ts('About'), $attributes['about']);
170 foreach ($this->_fields
as $name => $val) {
178 foreach ($this->_colorFields
as $name => $val) {
187 $this->assign_by_ref('fields', $this->_fields
);
188 $this->assign_by_ref('colorFields', $this->_colorFields
);
190 $this->_refreshButtonName
= $this->getButtonName('refresh');
191 $this->addElement('xbutton',
192 $this->_refreshButtonName
,
193 ts('Save and Preview'),
194 ['type' => 'submit', 'class' => 'crm-button crm-form-submit crm-button-type-submit']
196 parent
::buildQuickForm();
197 $this->addFormRule(['CRM_Contribute_Form_ContributionPage_Widget', 'formRule'], $this);
203 * @param array $params
204 * (ref.) an assoc array of name/value pairs.
210 * mixed true or array of errors
212 public static function formRule($params, $files, $self) {
214 if (!empty($params['is_active'])) {
215 if (empty($params['title'])) {
216 $errors['title'] = ts('Title is a required field.');
218 if (empty($params['about'])) {
219 $errors['about'] = ts('About is a required field.');
222 foreach ($params as $key => $val) {
223 if (substr($key, 0, 6) == 'color_' && empty($params[$key])) {
224 $errors[$key] = ts('%1 is a required field.', [1 => $self->_colorFields
[$key][0]]);
228 return empty($errors) ?
TRUE : $errors;
231 public function postProcess() {
232 //to reset quickform elements of next (pcp) page.
233 if ($this->controller
->getNextName('Widget') == 'PCP') {
234 $this->controller
->resetPage('PCP');
237 // get the submitted form values.
238 $params = $this->controller
->exportValues($this->_name
);
240 if ($this->_widget
) {
241 $params['id'] = $this->_widget
->id
;
243 $params['contribution_page_id'] = $this->_id
;
244 $params['is_active'] = CRM_Utils_Array
::value('is_active', $params, FALSE);
245 $params['url_homepage'] = 'null';
247 $widget = new CRM_Contribute_DAO_Widget();
248 $widget->copyValues($params);
251 $buttonName = $this->controller
->getButtonName();
252 if ($buttonName == $this->_refreshButtonName
) {
255 parent
::endPostProcess();
259 * Return a descriptive name for the page, used in wizard header
263 public function getTitle() {
264 return ts('Widget Settings');