From 5b15263aad651d054bfa986cde5303a34c3d3eab Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 14 May 2015 11:46:08 +1200 Subject: [PATCH] Replace 'distributed' custom data form with an actual custom data form & use it to get snippets --- CRM/Core/xml/Menu/CustomFieldByType.xml | 8 ++ CRM/Custom/Form/CustomData.php | 58 ++++++++----- CRM/Custom/Form/CustomDataByType.php | 83 +++++++++++++++++++ .../CRM/Custom/Form/CustomDataByType.tpl | 1 + templates/CRM/common/customData.tpl | 5 +- 5 files changed, 130 insertions(+), 25 deletions(-) create mode 100644 CRM/Core/xml/Menu/CustomFieldByType.xml create mode 100644 CRM/Custom/Form/CustomDataByType.php create mode 100644 templates/CRM/Custom/Form/CustomDataByType.tpl diff --git a/CRM/Core/xml/Menu/CustomFieldByType.xml b/CRM/Core/xml/Menu/CustomFieldByType.xml new file mode 100644 index 0000000000..1e0f5fed1a --- /dev/null +++ b/CRM/Core/xml/Menu/CustomFieldByType.xml @@ -0,0 +1,8 @@ + + + + + civicrm/custom + CRM_Custom_Form_CustomDataByType + + diff --git a/CRM/Custom/Form/CustomData.php b/CRM/Custom/Form/CustomData.php index 9b4f1fa5f6..5efa472f20 100644 --- a/CRM/Custom/Form/CustomData.php +++ b/CRM/Custom/Form/CustomData.php @@ -118,7 +118,41 @@ class CRM_Custom_Form_CustomData { $subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($subType, CRM_Core_DAO::VALUE_SEPARATOR)); } - $groupTree = &CRM_Core_BAO_CustomGroup::getTree($form->_type, + self::setGroupTree($form, $subType, $gid, $onlySubType, $getCachedTree); + } + + /** + * @param CRM_Core_Form $form + * + * @return array + */ + public static function setDefaultValues(&$form) { + $defaults = array(); + CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action')); + return $defaults; + } + + /** + * @param CRM_Core_Form $form + */ + public static function buildQuickForm(&$form) { + $form->addElement('hidden', 'hidden_custom', 1); + $form->addElement('hidden', "hidden_custom_group_count[{$form->_groupID}]", $form->_groupCount); + CRM_Core_BAO_CustomGroup::buildQuickForm($form, $form->_groupTree); + } + + /** + * @param $form + * @param $subType + * @param $gid + * @param $onlySubType + * @param $getCachedTree + * + * @return array + */ + public static function setGroupTree(&$form, $subType, $gid, $onlySubType, $getCachedTree = FALSE) { + + $groupTree = CRM_Core_BAO_CustomGroup::getTree($form->_type, $form, $form->_entityId, $gid, @@ -139,30 +173,12 @@ class CRM_Custom_Form_CustomData { foreach ($keys as $key) { $form->_groupTree[$key] = $groupTree[$key]; } + return array($form, $groupTree); } else { $form->_groupTree = $groupTree; + return array($form, $groupTree); } } - /** - * @param CRM_Core_Form $form - * - * @return array - */ - public static function setDefaultValues(&$form) { - $defaults = array(); - CRM_Core_BAO_CustomGroup::setDefaults($form->_groupTree, $defaults, FALSE, FALSE, $form->get('action')); - return $defaults; - } - - /** - * @param CRM_Core_Form $form - */ - public static function buildQuickForm(&$form) { - $form->addElement('hidden', 'hidden_custom', 1); - $form->addElement('hidden', "hidden_custom_group_count[{$form->_groupID}]", $form->_groupCount); - CRM_Core_BAO_CustomGroup::buildQuickForm($form, $form->_groupTree); - } - } diff --git a/CRM/Custom/Form/CustomDataByType.php b/CRM/Custom/Form/CustomDataByType.php new file mode 100644 index 0000000000..1bac428d1a --- /dev/null +++ b/CRM/Custom/Form/CustomDataByType.php @@ -0,0 +1,83 @@ +_type = $this->_cdType = CRM_Utils_Request::retrieve('type', 'String', CRM_Core_DAO::$_nullObject, TRUE); + $this->_subType = CRM_Utils_Request::retrieve('subType', 'String'); + $this->_subName = CRM_Utils_Request::retrieve('subName', 'String'); + $this->_groupCount = CRM_Utils_Request::retrieve('cgcount', 'Positive'); + $this->_entityId = CRM_Utils_Request::retrieve('entityID', 'Positive'); + $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive'); + $this->assign('cdType', FALSE); + $this->assign('cgCount', $this->_groupCount); + + // Carry qf key, since this form is not inheriting core form (unclear is still the case). + if ($qfKey = CRM_Utils_Request::retrieve('qfKey', 'String')) { + $this->assign('qfKey', $qfKey); + } + if (!is_array($this->_subType) && strstr($this->_subType, CRM_Core_DAO::VALUE_SEPARATOR)) { + $this->_subType = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ',', trim($this->_subType, CRM_Core_DAO::VALUE_SEPARATOR)); + } + CRM_Custom_Form_CustomData::setGroupTree($this, $this->_subType, NULL, $this->_groupID); + } + + /** + * Set defaults. + * + * @return array + */ + public function setDefaultValues() { + $defaults = array(); + CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE, $this->get('action')); + return $defaults; + } + + /** + * Build quick form. + */ + public function buildQuickForm() { + $this->addElement('hidden', 'hidden_custom', 1); + $this->addElement('hidden', "hidden_custom_group_count[{$this->_groupID}]", $this->_groupCount); + CRM_Core_BAO_CustomGroup::buildQuickForm($this, $this->_groupTree); + } + +} diff --git a/templates/CRM/Custom/Form/CustomDataByType.tpl b/templates/CRM/Custom/Form/CustomDataByType.tpl new file mode 100644 index 0000000000..d95bb4bb20 --- /dev/null +++ b/templates/CRM/Custom/Form/CustomDataByType.tpl @@ -0,0 +1 @@ +{include file="CRM/Custom/Form/CustomData.tpl"} diff --git a/templates/CRM/common/customData.tpl b/templates/CRM/common/customData.tpl index 9524e30395..3e6883a2d1 100644 --- a/templates/CRM/common/customData.tpl +++ b/templates/CRM/common/customData.tpl @@ -26,7 +26,7 @@ {literal}