CRM-15965: Refactored for a more object-oriented approach, and moved the task list...
authorFrank J. Gómez <frank@ginkgostreet.com>
Thu, 12 Feb 2015 22:01:13 +0000 (17:01 -0500)
committerFrank J. Gómez <frank@ginkgostreet.com>
Thu, 12 Feb 2015 22:01:13 +0000 (17:01 -0500)
CRM/Contact/Form/Search.php
CRM/Contact/Form/Search/Custom.php
CRM/Contact/Form/Search/Custom/Base.php
CRM/Contact/Form/Search/Interface.php
CRM/Core/Form/Search.php

index a9515deae80efa925da5d16b1acc13c5131aab45..79824f368b2cbfd9b76249433bb397b6ff5ad03c 100644 (file)
@@ -331,31 +331,28 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
   /**
    * Builds the list of tasks or actions that a searcher can perform on a result set.
    *
-   * The result is passed to $this->addTaskList, which is responsible for building
-   * the menu and adding it to the form.
-   *
-   * @access public
    * @return array
    */
-  public function buildTaskList() {
-    $tasks = array();
-    $permission = CRM_Core_Permission::getPermission();
+  function buildTaskList() {
+    if ($this->_context !== 'amtg') {
+      $permission = CRM_Core_Permission::getPermission();
 
-    if ($this->_componentMode == 1 || $this->_componentMode == 7) {
-      $tasks += CRM_Contact_Task::permissionedTaskTitles($permission,
-        CRM_Utils_Array::value('deleted_contacts', $this->_formValues)
-      );
-    } else {
-      $className = $this->_modeValue['taskClassName'];
-      $tasks += $className::permissionedTaskTitles($permission, false);
-    }
+      if ($this->_componentMode == 1 || $this->_componentMode == 7) {
+        $this->_taskList += CRM_Contact_Task::permissionedTaskTitles($permission,
+          CRM_Utils_Array::value('deleted_contacts', $this->_formValues)
+        );
+      } else {
+        $className = $this->_modeValue['taskClassName'];
+        $this->_taskList += $className::permissionedTaskTitles($permission, false);
+      }
 
-    // Only offer the "Update Smart Group" task if a smart group/saved search is already in play
-    if (isset($this->_ssID) && $permission == CRM_Core_Permission::EDIT) {
-      $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
+      // Only offer the "Update Smart Group" task if a smart group/saved search is already in play
+      if (isset($this->_ssID) && $permission == CRM_Core_Permission::EDIT) {
+        $this->_taskList += CRM_Contact_Task::optionalTaskTitle();
+      }
     }
 
-    return $tasks;
+    return $this->_taskList;
   }
 
   /**
@@ -466,10 +463,6 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
       $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
       $this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
     }
-    else {
-      $tasks = $this->buildTaskList();
-      $this->addTaskMenu($tasks);
-    }
 
     $selectedContactIds = array();
     $qfKeyParam = CRM_Utils_Array::value('qfKey', $this->_formValues);
index 2f4e9103388bfd952905f72e3366c84fd0212b73..1c5baee64de9d4312c384fe184f87722cd1a2d2f 100644 (file)
@@ -108,11 +108,15 @@ class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
     return $this->_formValues;
   }
 
+  /**
+   * Builds the list of tasks or actions that a searcher can perform on a result set.
+   *
+   * @return array
+   */
   function buildTaskList() {
-    if (method_exists($this->_customSearchClass, 'buildTaskList')) {
-      return $this->_customClass->buildTaskList();
-    }
-    return parent::buildTaskList();
+    // call the parent method to populate $this->_taskList for the custom search
+    parent::buildTaskList();
+    return $this->_customClass->buildTaskList($this);
   }
 
   function buildQuickForm() {
index 5ef3c868e169662e7b0a17941c02d25635791f81..7484c92b2bfad38c23c0579b38a297a0d6f4e45e 100644 (file)
@@ -47,6 +47,19 @@ class CRM_Contact_Form_Search_Custom_Base {
     $this->_formValues = &$formValues;
   }
 
+  /**
+   * Builds the list of tasks or actions that a searcher can perform on a result set.
+   *
+   * The returned array completely replaces the task list, so a child class that
+   * wants to modify the existing list should manipulate the result of this method.
+   *
+   * @param CRM_Core_Form_Search $form
+   * @return array
+   */
+  function buildTaskList(CRM_Core_Form_Search $form) {
+    return $form->getVar('_taskList');
+  }
+
   /**
    * @return null|string
    */
index 92cf44aba233bffcf8aacf65dbb50c88db70d3d0..b128c87bb2427116e61b0e5cf3e04f1b7022dfd7 100644 (file)
@@ -39,6 +39,14 @@ interface CRM_Contact_Form_Search_Interface {
    */
   function __construct(&$formValues);
 
+  /**
+   * Builds the list of tasks or actions that a searcher can perform on a result set.
+   *
+   * @param CRM_Core_Form_Search $form
+   * @return array
+   */
+  function buildTaskList(CRM_Core_Form_Search $form);
+
   /**
    * Builds the quickform for this search
    */
index 9b9cbc0f7eea6948d29c3e2238c25e342d634455..1e02fde170a492fa8facd915728af0964edd77be 100644 (file)
@@ -77,6 +77,25 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    */
   protected $_context = NULL;
 
+  /**
+   * The list of tasks or actions that a searcher can perform on a result set.
+   *
+   * @var array
+   */
+  protected $_taskList = array();
+
+  /**
+   * Builds the list of tasks or actions that a searcher can perform on a result set.
+   *
+   * To modify the task list, child classes should alter $this->_taskList,
+   * preferably by extending this method.
+   *
+   * @return array
+   */
+  protected function buildTaskList() {
+    return $this->_taskList;
+  }
+
   /**
    * Common buildform tasks required by all searches
    */
@@ -99,6 +118,11 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
     ));
 
     $this->addClass('crm-search-form');
+
+    // for backwards compatibility we pass an argument to addTaskMenu even though
+    // it could just as well access $this->_taskList internally
+    $tasks = $this->buildTaskList();
+    $this->addTaskMenu($tasks);
   }
 
   /**