Replace 'distributed' custom data form with an actual custom data form & use it to...
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 13 May 2015 23:46:08 +0000 (11:46 +1200)
committerColeman Watts <coleman@civicrm.org>
Thu, 25 Jun 2015 18:23:10 +0000 (14:23 -0400)
CRM/Core/xml/Menu/CustomFieldByType.xml [new file with mode: 0644]
CRM/Custom/Form/CustomData.php
CRM/Custom/Form/CustomDataByType.php [new file with mode: 0644]
templates/CRM/Custom/Form/CustomDataByType.tpl [new file with mode: 0644]
templates/CRM/common/customData.tpl

diff --git a/CRM/Core/xml/Menu/CustomFieldByType.xml b/CRM/Core/xml/Menu/CustomFieldByType.xml
new file mode 100644 (file)
index 0000000..1e0f5fe
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="iso-8859-1" ?>
+
+<menu>
+  <item>
+     <path>civicrm/custom</path>
+     <page_callback>CRM_Custom_Form_CustomDataByType</page_callback>
+  </item>
+</menu>
index 9b4f1fa5f696f7eb8c9ef1e105681b46c405d493..5efa472f200f8e4e547cb1b3d0e31a6c8d6a5522 100644 (file)
@@ -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 (file)
index 0000000..1bac428
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+/*
+  +--------------------------------------------------------------------+
+  | CiviCRM version 4.6                                                |
+  +--------------------------------------------------------------------+
+  | Copyright CiviCRM LLC (c) 2004-2015                                |
+  +--------------------------------------------------------------------+
+  | This file is a part of CiviCRM.                                    |
+  |                                                                    |
+  | CiviCRM is free software; you can copy, modify, and distribute it  |
+  | under the terms of the GNU Affero General Public License           |
+  | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+  |                                                                    |
+  | CiviCRM is distributed in the hope that it will be useful, but     |
+  | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+  | See the GNU Affero General Public License for more details.        |
+  |                                                                    |
+  | You should have received a copy of the GNU Affero General Public   |
+  | License and the CiviCRM Licensing Exception along                  |
+  | with this program; if not, contact CiviCRM LLC                     |
+  | at info[AT]civicrm[DOT]org. If you have questions about the        |
+  | GNU Affero General Public License or the licensing of CiviCRM,     |
+  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+  +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2015
+ */
+
+/**
+ * This form is intended to replace the overloading of many forms to generate a snippet for custom data.
+ */
+class CRM_Custom_Form_CustomDataByType extends CRM_Core_Form {
+
+  /**
+   * Preprocess function.
+   */
+  public function preProcess() {
+
+    $this->_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 (file)
index 0000000..d95bb4b
--- /dev/null
@@ -0,0 +1 @@
+{include file="CRM/Custom/Form/CustomData.tpl"}
index 9524e30395504801197f0996788698ee39ea2a84..3e6883a2d144d7f5466e33eb1c1b33a76f595f49 100644 (file)
@@ -26,7 +26,7 @@
 {literal}
 <script type="text/javascript">
 CRM.buildCustomData = function( type, subType, subName, cgCount, groupID, isMultiple ) {
-  var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&type='}"{literal} + type;
+  var dataUrl = {/literal}"{crmURL p='civicrm/custom' h=0 q='snippet=4&type='}"{literal} + type;
 
   if ( subType ) {
     dataUrl = dataUrl + '&subType=' + subType;
@@ -50,9 +50,6 @@ CRM.buildCustomData = function( type, subType, subName, cgCount, groupID, isMult
     {if $groupID}
       dataUrl = dataUrl + '&groupID=' + '{$groupID}'
     {/if}
-    {if $qfKey}
-      dataUrl = dataUrl + '&qfKey=' + '{$qfKey}'
-    {/if}
     {if $entityID}
       dataUrl = dataUrl + '&entityID=' + '{$entityID}'
     {/if}