3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2020 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2020
35 * Builds a form of shortcodes that can be added to WP posts.
37 * Use hook_civicrm_preProcess to modify this list.
39 class CRM_Core_Form_ShortCode
extends CRM_Core_Form
{
41 * List of entities supported by shortcodes, and their form properties.
43 * Keys should be the "component" string for the shortcode
44 * Values should be an array with label and select.
45 * Select can be NULL if there is no entity to select.
46 * Otherwise it contains the shortcode key for this entity id (usually 'id') plus an array of params for the EntityRef field
50 * label => Option Label
51 * select => key + EntityRef params
53 * @see CRM_Core_Form::addEntityRef
55 public $components = [];
58 * List of radio option groups to display on the form
60 * Control the conditional logic of showing/hiding each group via the "components" array.
61 * Or set 'components' => TRUE if it applies to all
64 * [key, components, options]
69 * Build form data. Can be modified via hook_civicrm_preProcess.
71 public function preProcess() {
72 $config = CRM_Core_Config
::singleton();
74 $this->components
['user-dashboard'] = [
75 'label' => ts("User Dashboard"),
78 $this->components
['profile'] = [
79 'label' => ts("Profile"),
82 'entity' => 'UFGroup',
83 'select' => ['minimumInputLength' => 0],
86 'id' => $this->profileAccess(),
92 if (in_array('CiviContribute', $config->enableComponents
)) {
93 $this->components
['contribution'] = [
94 'label' => ts("Contribution Page"),
97 'entity' => 'ContributionPage',
98 'select' => ['minimumInputLength' => 0],
103 if (in_array('CiviEvent', $config->enableComponents
)) {
104 $this->components
['event'] = [
105 'label' => ts("Event Page"),
109 'select' => ['minimumInputLength' => 0],
114 if (in_array('CiviCampaign', $config->enableComponents
)) {
115 $this->components
['petition'] = [
116 'label' => ts("Petition"),
119 'entity' => 'Survey',
120 'select' => ['minimumInputLength' => 0],
123 'activity_type_id' => "Petition",
133 'components' => ['event'],
135 'info' => ts('Event Info Page'),
136 'register' => ts('Event Registration Page'),
141 'components' => ['contribution', 'event'],
143 'live' => ts('Live Mode'),
144 'test' => ts('Test Drive'),
149 'components' => ['profile'],
151 'create' => ts('Create'),
152 'edit' => ts('Edit'),
153 'view' => ts('View'),
154 'search' => ts('Search/Public Directory'),
159 'components' => TRUE,
160 'label' => ts('If you only insert one shortcode, you can choose to override all page content with the content of the shortcode.'),
162 '0' => ts("Don't override"),
163 '1' => ts('Override page content'),
170 * Build form elements based on the above metadata.
172 public function buildQuickForm() {
173 $components = CRM_Utils_Array
::collect('label', $this->components
);
174 $data = CRM_Utils_Array
::collect('select', $this->components
);
176 $this->add('select', 'component', NULL, $components, FALSE, ['class' => 'crm-select2', 'data-key' => 'component', 'data-entities' => json_encode($data)]);
177 $this->add('text', 'entity', NULL, ['placeholder' => ts('- select -')]);
179 $options = $defaults = [];
180 foreach ($this->options
as $num => $field) {
181 $this->addRadio("option_$num", CRM_Utils_Array
::value('label', $field), $field['options'], ['allowClear' => FALSE, 'data-key' => $field['key']]);
182 if ($field['components'] === TRUE) {
183 $field['components'] = array_keys($this->components
);
185 $options["option_$num"] = $field;
187 // Select 1st option as default
188 $keys = array_keys($field['options']);
189 $defaults["option_$num"] = $keys[0];
192 $this->assign('options', $options);
193 $this->assign('selects', array_keys(array_filter($data)));
194 $this->setDefaults($defaults);
198 * The CiviCRM api (and therefore EntityRef) does not support OR logic, ACLs or joins.
200 * I'm not proud of this, but here's a workaround to pre-filter the api params
204 private function profileAccess() {
207 FROM civicrm_uf_group g, civicrm_uf_join j
208 WHERE g.is_active = 1
210 AND ( group_type LIKE '%Individual%'
211 OR group_type LIKE '%Contact%' )
212 AND g.id = j.uf_group_id
213 AND j.module = 'Profile'
215 $dao = CRM_Core_DAO
::executeQuery($sql);
217 while ($dao->fetch()) {
220 return ['IN' => $ids];
223 // No postProccess fn; this form never gets submitted