*/
class CRM_Core_Form_ShortCode extends CRM_Core_Form {
/**
- * List of entities supported by shortcodes, and their form properties
+ * List of entities supported by shortcodes, and their form properties.
+ *
+ * Keys should be the "component" string for the shortcode
+ * Values should be an array with label and select.
+ * Select can be NULL if there is no entity to select.
+ * Otherwise it contains the shortcode key for this entity id (usually 'id') plus an array of params for the EntityRef field
+ * @see CRM_Core_Form::addEntityRef
*
* @var array
+ * [component => [
+ * label => Option Label
+ * select => key + EntityRef params
+ * ]]
*/
public $components = array();
/**
- * List of options to display on the form
+ * List of radio option groups to display on the form
+ *
+ * Control the conditional logic of showing/hiding each group via the "components" array.
+ * Or set 'components' => TRUE if it applies to all
*
* @var array
+ * [key, components, options]
*/
public $options = array();
/**
- * Build form data. Overridable via hook_civicrm_preProcess
+ * Build form data. Can be modified via hook_civicrm_preProcess
*
* @return void
*/
'label' => ts("Profile"),
'select' => array(
'key' => 'gid',
- 'entity' => 'Profile',
+ 'entity' => 'UFGroup',
'select' => array('minimumInputLength' => 0),
+ 'api' => array(
+ 'params' => array(
+ 'id' => $this->profileAccess(),
+ ),
+ ),
),
);
'key' => 'id',
'entity' => 'Survey',
'select' => array('minimumInputLength' => 0),
+ 'api' => array(
+ 'params' => array(
+ 'activity_type_id' => "Petition",
+ ),
+ ),
),
);
}
),
array(
'key' => 'hijack',
- 'components' => '*',
+ 'components' => TRUE,
'label' => ts('If you only insert one shortcode, you can choose to override all page content with the content of the shortcode.'),
'options' => array(
'0' => ts("Don't override"),
$options = $defaults = array();
foreach ($this->options as $num => $field) {
$this->addRadio("option_$num", CRM_Utils_Array::value('label', $field), $field['options'], array('allowClear' => FALSE, 'data-key' => $field['key']));
- if ($field['components'] === '*') {
+ if ($field['components'] === TRUE) {
$field['components'] = array_keys($this->components);
}
$options["option_$num"] = $field;
$this->setDefaults($defaults);
}
+ /**
+ * The CiviCRM api (and therefore EntityRef) does not support OR logic, ACLs or joins.
+ *
+ * I'm not proud of this, but here's a workaround to pre-filter the api params
+ *
+ * @return array
+ */
+ private function profileAccess() {
+ $sql = "
+ SELECT g.id
+ FROM civicrm_uf_group g, civicrm_uf_join j
+ WHERE g.is_active = 1
+ AND j.is_active = 1
+ AND ( group_type LIKE '%Individual%'
+ OR group_type LIKE '%Contact%' )
+ AND g.id = j.uf_group_id
+ AND j.module = 'Profile'
+ ";
+ $dao = CRM_Core_DAO::executeQuery($sql);
+ $ids = array();
+ while ($dao->fetch()) {
+ $ids[] = $dao->id;
+ }
+ return array('IN' => $ids);
+ }
+
// No postProccess fn; this form never gets submitted
}
*/
public function browse($action = NULL) {
$ufGroup = array();
- $allUFGroups = array();
$allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup();
if (empty($allUFGroups)) {
return;
}
$groupTypes = self::extractGroupTypes($value['group_type']);
- $groupComponents = array('Contribution', 'Membership', 'Activity', 'Participant', 'Case');
- // drop Create, Edit and View mode links if profile group_type is Contribution, Membership, Activities or Participant
+ // drop Create, Edit and View mode links if profile group_type is one of the following:
+ $groupComponents = array('Contribution', 'Membership', 'Activity', 'Participant', 'Case');
$componentFound = array_intersect($groupComponents, array_keys($groupTypes));
if (!empty($componentFound)) {
$action -= CRM_Core_Action::ADD;
}
- $groupTypesString = '';
- if (!empty($groupTypes)) {
- $groupTypesStrings = array();
- foreach ($groupTypes as $groupType => $typeValues) {
- if (is_array($typeValues)) {
- if ($groupType == 'Participant') {
- foreach ($typeValues as $subType => $subTypeValues) {
- $groupTypesStrings[] = $subType . '::' . implode(': ', $subTypeValues);
- }
- }
- else {
- $groupTypesStrings[] = $groupType . '::' . implode(': ', current($typeValues));
- }
- }
- else {
- $groupTypesStrings[] = $groupType;
- }
- }
- $groupTypesString = implode(', ', $groupTypesStrings);
- }
- $ufGroup[$id]['group_type'] = $groupTypesString;
+ $ufGroup[$id]['group_type'] = self::formatGroupTypes($groupTypes);
$ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
array('id' => $id),
return $returnGroupTypes;
}
+ /**
+ * Format 'group_type' field for display
+ *
+ * @param array $groupTypes
+ * output from self::extractGroupTypes
+ * @return string
+ */
+ public static function formatGroupTypes($groupTypes) {
+ $groupTypesString = '';
+ if (!empty($groupTypes)) {
+ $groupTypesStrings = array();
+ foreach ($groupTypes as $groupType => $typeValues) {
+ if (is_array($typeValues)) {
+ if ($groupType == 'Participant') {
+ foreach ($typeValues as $subType => $subTypeValues) {
+ $groupTypesStrings[] = $subType . '::' . implode(': ', $subTypeValues);
+ }
+ }
+ else {
+ $groupTypesStrings[] = $groupType . '::' . implode(': ', current($typeValues));
+ }
+ }
+ else {
+ $groupTypesStrings[] = $groupType;
+ }
+ }
+ $groupTypesString = implode(', ', $groupTypesStrings);
+ }
+ return $groupTypesString;
+ }
+
}
$result = CRM_Contribute_Form_Contribution_Confirm::submit($params);
return civicrm_api3_create_success($result, $params, 'ContributionPage', 'submit');
}
+
+
+/**
+ * Set default getlist parameters.
+ *
+ * @see _civicrm_api3_generic_getlist_defaults
+ *
+ * @param array $request
+ *
+ * @return array
+ */
+function _civicrm_api3_contribution_page_getlist_defaults(&$request) {
+ return array(
+ 'description_field' => array(
+ 'intro_text',
+ ),
+ 'params' => array(
+ 'is_active' => 1,
+ ),
+ );
+}
*
* @param array $result
* @param array $request
+ * @param string $entity
* @param array $fields
*
* @return array
function civicrm_api3_survey_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
+
+/**
+ * Set default getlist parameters.
+ *
+ * @see _civicrm_api3_generic_getlist_defaults
+ *
+ * @param array $request
+ *
+ * @return array
+ */
+function _civicrm_api3_survey_getlist_defaults(&$request) {
+ return array(
+ 'description_field' => array(
+ 'campaign_id',
+ ),
+ 'params' => array(
+ 'is_active' => 1,
+ ),
+ );
+}
function civicrm_api3_uf_group_delete($params) {
return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
+
+/**
+ * Set default getlist parameters.
+ *
+ * @see _civicrm_api3_generic_getlist_defaults
+ *
+ * @param array $request
+ *
+ * @return array
+ */
+function _civicrm_api3_uf_group_getlist_defaults(&$request) {
+ return array(
+ 'description_field' => array(
+ 'description',
+ 'group_type',
+ ),
+ 'params' => array(
+ 'is_active' => 1,
+ ),
+ );
+}
+
+/**
+ * Format getlist output
+ *
+ * @see _civicrm_api3_generic_getlist_output
+ *
+ * @param array $result
+ * @param array $request
+ * @param string $entity
+ * @param array $fields
+ *
+ * @return array
+ */
+function _civicrm_api3_uf_group_getlist_output($result, $request, $entity, $fields) {
+ $output = array();
+ if (!empty($result['values'])) {
+ foreach ($result['values'] as $row) {
+ $data = array(
+ 'id' => $row[$request['id_field']],
+ 'label' => $row[$request['label_field']],
+ );
+ if (!empty($request['description_field'])) {
+ $data['description'] = array();
+ foreach ((array) $request['description_field'] as $field) {
+ if (!empty($row[$field])) {
+ // Special formatting for group_type field
+ if ($field == 'group_type') {
+ $groupTypes = CRM_UF_Page_Group::extractGroupTypes($row[$field]);
+ $data['description'][] = CRM_UF_Page_Group::formatGroupTypes($groupTypes);
+ continue;
+ }
+ if (!isset($fields[$field]['pseudoconstant'])) {
+ $data['description'][] = $row[$field];
+ }
+ else {
+ $data['description'][] = CRM_Core_PseudoConstant::getLabel(
+ _civicrm_api3_get_BAO($entity),
+ $field,
+ $row[$field]
+ );
+ }
+ }
+ }
+ };
+ if (!empty($request['image_field'])) {
+ $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : '';
+ }
+ $output[] = $data;
+ }
+ }
+ return $output;
+}