CRM-19122 Group Organization & parent default code should be the same
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 25 Jul 2016 06:00:46 +0000 (18:00 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 13 Oct 2016 18:12:40 +0000 (19:12 +0100)
CRM/Contact/Form/Task/SaveSearch.php
CRM/Group/Form/Edit.php
templates/CRM/Contact/Form/Task/SaveSearch.tpl
templates/CRM/Group/Form/Edit.tpl
templates/CRM/Group/Form/GroupsCommon.tpl [moved from templates/CRM/Group/Form/ParentGroups.tpl with 85% similarity]

index 2e1f7a9e77303bf5098f47e5fd65c977381969d2..e8632ccdaef733d075871510e2ecd35d6dfbed7c 100644 (file)
@@ -118,6 +118,7 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
 
     //CRM-14190
     CRM_Group_Form_Edit::buildParentGroups($this);
+    CRM_Group_Form_Edit::buildGroupOrganizations($this);
 
     // get the group id for the saved search
     $groupID = NULL;
@@ -240,4 +241,17 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
     }
   }
 
+  /**
+   * Set form defaults.
+   *
+   * return array
+   */
+  public function setDefaultValues() {
+    $defaults = array();
+    if (empty($defaults['parents'])) {
+      $defaults['parents'] = CRM_Core_BAO_Domain::getGroupId();
+    }
+    return $defaults;
+  }
+
 }
index 2537155e9603a30966161484961673de3ecdaf73..e3c97df4b6cf61941844901ef0b7200b31c6f5ca 100644 (file)
@@ -254,12 +254,7 @@ class CRM_Group_Form_Edit extends CRM_Core_Form {
 
     //CRM-14190
     $parentGroups = self::buildParentGroups($this);
-
-    if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
-      //group organization Element
-      $props = array('api' => array('params' => array('contact_type' => 'Organization')));
-      $this->addEntityRef('organization_id', ts('Organization'), $props);
-    }
+    self::buildGroupOrganizations($this);
 
     // is_reserved property CRM-9936
     $this->addElement('checkbox', 'is_reserved', ts('Reserved Group?'));
@@ -484,4 +479,20 @@ WHERE  title = %1
     return $parentGroups;
   }
 
+  /**
+   * Add the group organization checkbox to the form.
+   *
+   * Note this was traditionally a multisite thing - there is no particular reason why it is not available
+   * as a general field - it's historical use-case driven.
+   *
+   * @param CRM_Core_Form $form
+   */
+  public static function buildGroupOrganizations(&$form) {
+    if (CRM_Core_Permission::check('administer Multiple Organizations') && CRM_Core_Permission::isMultisiteEnabled()) {
+      //group organization Element
+      $props = array('api' => array('params' => array('contact_type' => 'Organization')));
+      $form->addEntityRef('organization_id', ts('Organization'), $props);
+    }
+  }
+
 }
index 209303d93a034bcad0799e51946912797aa2cafd..cb5218fe3ec01066270b54955efc07a5a24b5803 100644 (file)
@@ -59,7 +59,7 @@
   </table>
 
   {*CRM-14190*}
-  {include file="CRM/Group/Form/ParentGroups.tpl"}
+  {include file="CRM/Group/Form/GroupsCommon.tpl"}
 
   <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
 </div>
index 04a0c91a02e632730e75e8c9091635d6725d7aa9..8283067deb272396d2171a99fa2708b03cf4f924 100644 (file)
     </table>
 
   {*CRM-14190*}
-  {include file="CRM/Group/Form/ParentGroups.tpl"}
-
-    {if $form.organization_id}
-  <h3>{ts}Associated Organization{/ts} {help id="id-group-organization" file="CRM/Group/Page/Group.hlp"}</h3>
-          <table class="form-layout-compressed">
-        <tr class="crm-group-form-block-organization">
-            <td class="label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$form.organization_id.label}</td>
-      <td>{$form.organization_id.html|crmAddClass:huge}
-      </td>
-        </tr>
-    </table>
-    {/if}
+  {include file="CRM/Group/Form/GroupsCommon.tpl"}
 
     <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
     {if $action neq 1}
       {/if}
   </div>
     {/if}
-</fieldset>
 
 {literal}
 <script type="text/javascript">
similarity index 85%
rename from templates/CRM/Group/Form/ParentGroups.tpl
rename to templates/CRM/Group/Form/GroupsCommon.tpl
index 667ead1ea4bb0fc053d94fa26d27b1dd05b4a6ca..8d31528ab6702a584a1cd14c7e0b02179b34e9f0 100644 (file)
     </tr>
   </table>
 {/if}
+{if $form.organization_id}
+  <h3>{ts}Associated Organization{/ts} {help id="id-group-organization" file="CRM/Group/Page/Group.hlp"}</h3>
+  <table class="form-layout-compressed">
+    <tr class="crm-group-form-block-organization">
+      <td class="label">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$form.organization_id.label}</td>
+      <td>{$form.organization_id.html|crmAddClass:huge}
+      </td>
+    </tr>
+  </table>
+{/if}