CRM-15965: Extracted task list building logic from buildQuickForm method.
[civicrm-core.git] / CRM / Contact / Form / Search.php
index f9d1d1717803787fe780d2d1629515019bd668f1..a9515deae80efa925da5d16b1acc13c5131aab45 100644 (file)
@@ -329,38 +329,50 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
   }
 
   /**
-   * Build the common elements between the search/advanced form
+   * Builds the list of tasks or actions that a searcher can perform on a result set.
    *
-   * @access public
+   * The result is passed to $this->addTaskList, which is responsible for building
+   * the menu and adding it to the form.
    *
-   * @return void
+   * @access public
+   * @return array
    */
-  function buildQuickForm() {
-    parent::buildQuickForm();
-    CRM_Core_Resources::singleton()
-      // jsTree is needed for tags popup
-      ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
-      ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
-    $permission = CRM_Core_Permission::getPermission();
-    // some tasks.. what do we want to do with the selected contacts ?
+  public function buildTaskList() {
     $tasks = array();
+    $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 {
+    } else {
       $className = $this->_modeValue['taskClassName'];
       $tasks += $className::permissionedTaskTitles($permission, false);
     }
 
-    if (isset($this->_ssID)) {
-      if ($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) {
+      $tasks = $tasks + CRM_Contact_Task::optionalTaskTitle();
+    }
+
+    return $tasks;
+  }
 
-      $search_custom_id =
-        CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');
+  /**
+   * Build the common elements between the search/advanced form.
+   *
+   * @return void
+   */
+  public function buildQuickForm() {
+    parent::buildQuickForm();
+    CRM_Core_Resources::singleton()
+      // jsTree is needed for tags popup
+      ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
+      ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header');
+
+    if (isset($this->_ssID)) {
+      $search_custom_id
+        = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $this->_ssID, 'search_custom_id');
 
       $savedSearchValues = array(
         'id' => $this->_ssID,
@@ -455,6 +467,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
       $this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
     }
     else {
+      $tasks = $this->buildTaskList();
       $this->addTaskMenu($tasks);
     }