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 * Builds a form of shortcodes that can be added to WP posts.
21 * Use hook_civicrm_preProcess to modify this list.
23 class CRM_Core_Form_ShortCode
extends CRM_Core_Form
{
25 * List of entities supported by shortcodes, and their form properties.
27 * Keys should be the "component" string for the shortcode
28 * Values should be an array with label and select.
29 * Select can be NULL if there is no entity to select.
30 * Otherwise it contains the shortcode key for this entity id (usually 'id') plus an array of params for the EntityRef field
34 * label => Option Label
35 * select => key + EntityRef params
37 * @see CRM_Core_Form::addEntityRef
39 public $components = [];
42 * List of radio option groups to display on the form
44 * Control the conditional logic of showing/hiding each group via the "components" array.
45 * Or set 'components' => TRUE if it applies to all
48 * [key, components, options]
53 * Build form data. Can be modified via hook_civicrm_preProcess.
55 public function preProcess() {
56 $this->components
['user-dashboard'] = [
57 'label' => ts("User Dashboard"),
60 $this->components
['profile'] = [
61 'label' => ts("Profile"),
64 'entity' => 'UFGroup',
65 'select' => ['minimumInputLength' => 0],
68 'id' => $this->profileAccess(),
74 if (CRM_Core_Component
::isEnabled('CiviContribute')) {
75 $this->components
['contribution'] = [
76 'label' => ts("Contribution Page"),
79 'entity' => 'ContributionPage',
80 'select' => ['minimumInputLength' => 0],
83 $this->components
['pcp'] = [
84 'label' => ts("Personal Campaign Page"),
88 'select' => ['minimumInputLength' => 0],
93 if (CRM_Core_Component
::isEnabled('CiviEvent')) {
94 $this->components
['event'] = [
95 'label' => ts("Event Page"),
99 'select' => ['minimumInputLength' => 0],
104 if (CRM_Core_Component
::isEnabled('CiviCampaign')) {
105 $this->components
['petition'] = [
106 'label' => ts("Petition"),
109 'entity' => 'Survey',
110 'select' => ['minimumInputLength' => 0],
113 'activity_type_id' => "Petition",
123 'components' => ['contribution'],
125 'transact' => ts('Contribution Page'),
126 'setup' => ts('Setup a Personal Campaign Page'),
131 'components' => ['event'],
133 'info' => ts('Event Info Page'),
134 'register' => ts('Event Registration Page'),
139 'components' => ['pcp'],
141 'info' => ts('Info Page'),
142 'transact' => ts('Contribution Page'),
147 'components' => ['contribution', 'pcp', 'event'],
149 'live' => ts('Live Mode'),
150 'test' => ts('Test Drive'),
155 'components' => ['profile'],
157 'create' => ts('Create'),
158 'edit' => ts('Edit'),
159 'view' => ts('View'),
160 'search' => ts('Search/Public Directory'),
161 'map' => ts('Map View'),
166 'components' => TRUE,
167 'label' => ts('If you only insert one shortcode, you can choose to override all page content with the content of the shortcode.'),
169 '0' => ts("Don't override"),
170 '1' => ts('Override page content'),
177 * Build form elements based on the above metadata.
179 public function buildQuickForm() {
180 $components = CRM_Utils_Array
::collect('label', $this->components
);
181 $data = CRM_Utils_Array
::collect('select', $this->components
);
183 $this->add('select', 'component', NULL, $components, FALSE, ['class' => 'crm-select2', 'data-key' => 'component', 'data-entities' => json_encode($data)]);
184 $this->add('text', 'entity', NULL, ['placeholder' => ts('- select -')]);
186 $options = $defaults = [];
187 foreach ($this->options
as $num => $field) {
188 $this->addRadio("option_$num", CRM_Utils_Array
::value('label', $field), $field['options'], ['allowClear' => FALSE, 'data-key' => $field['key']]);
189 if ($field['components'] === TRUE) {
190 $field['components'] = array_keys($this->components
);
192 $options["option_$num"] = $field;
194 // Select 1st option as default
195 $keys = array_keys($field['options']);
196 $defaults["option_$num"] = $keys[0];
199 $this->assign('options', $options);
200 $this->assign('selects', array_keys(array_filter($data)));
201 $this->setDefaults($defaults);
205 * The CiviCRM api (and therefore EntityRef) does not support OR logic, ACLs or joins.
207 * I'm not proud of this, but here's a workaround to pre-filter the api params
211 private function profileAccess() {
214 FROM civicrm_uf_group g, civicrm_uf_join j
215 WHERE g.is_active = 1
217 AND ( group_type LIKE '%Individual%'
218 OR group_type LIKE '%Contact%' )
219 AND g.id = j.uf_group_id
220 AND j.module = 'Profile'
222 $dao = CRM_Core_DAO
::executeQuery($sql);
224 while ($dao->fetch()) {
227 return ['IN' => $ids];
230 // No postProccess fn; this form never gets submitted