From 32795e8234264d532b15590cd0ea80e8bb2a0a0e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Frank=20J=2E=20G=C3=B3mez?= Date: Thu, 12 Feb 2015 10:47:34 -0500 Subject: [PATCH] CRM-15965: Extracted task list building logic from buildQuickForm method. --- CRM/Contact/Form/Search.php | 51 +++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index f9d1d17178..a9515deae8 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -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); } -- 2.25.1