Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20684: Standalone form for contact bulk actions #10471

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions CRM/Contact/Form/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,22 @@ public function preProcess() {
* @param bool $useTable
*/
public static function preProcessCommon(&$form, $useTable = FALSE) {

$form->_contactIds = array();
$form->_contactTypes = array();

$isStandAlone = (in_array('task', $form->urlPath));
if ($isStandAlone) {
list($form->_task, $title) = CRM_Contact_Task::getTaskAndTitleByClass(get_class($form));
if (!array_key_exists($form->_task, CRM_Contact_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission()))) {
CRM_Core_Error::fatal(ts('You do not have enough permission to do this task.'));
}
$form->_contactIds = explode(',', CRM_Utils_Request::retrieve('cids', 'String', $form, TRUE));
if (empty($form->_contactIds)) {
CRM_Core_Error::statusBounce(ts("You did't selected any contact to perform this task."));
}
$form->setTitle($title);
}

// get the submitted values of the search form
// we'll need to get fv from either search or adv search in the future
$fragment = 'search';
Expand All @@ -116,7 +128,7 @@ public static function preProcessCommon(&$form, $useTable = FALSE) {
self::$_searchFormValues = $form->controller->exportValues('Custom');
$fragment .= '/custom';
}
else {
elseif (!$isStandAlone) {
self::$_searchFormValues = $form->controller->exportValues('Basic');
}

Expand Down Expand Up @@ -183,7 +195,7 @@ public static function preProcessCommon(&$form, $useTable = FALSE) {
CRM_Core_DAO::executeQuery($sql);
}
}
else {
elseif (empty($form->_contactIds)) {
// filter duplicates here
// CRM-7058
// might be better to do this in the query, but that logic is a bit complex
Expand Down
35 changes: 35 additions & 0 deletions CRM/Contact/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@ public static function initTasks() {
self::GROUP_CONTACTS => array(
'title' => ts('Group - add contacts'),
'class' => 'CRM_Contact_Form_Task_AddToGroup',
'url' => 'civicrm/task/add-to-group',
),
self::REMOVE_CONTACTS => array(
'title' => ts('Group - remove contacts'),
'class' => 'CRM_Contact_Form_Task_RemoveFromGroup',
'url' => 'civicrm/task/remove-from-group',
),
self::TAG_CONTACTS => array(
'title' => ts('Tag - add to contacts'),
'class' => 'CRM_Contact_Form_Task_AddToTag',
'url' => 'civicrm/task/add-to-tag',
),
self::REMOVE_TAGS => array(
'title' => ts('Tag - remove from contacts'),
'class' => 'CRM_Contact_Form_Task_RemoveFromTag',
'url' => 'civicrm/task/remove-from-tag',
),
self::EXPORT_CONTACTS => array(
'title' => ts('Export contacts'),
Expand All @@ -108,11 +112,13 @@ public static function initTasks() {
'title' => ts('Email - send now (to 50 or less)'),
'class' => 'CRM_Contact_Form_Task_Email',
'result' => TRUE,
'url' => 'civicrm/task/send-email',
),
self::DELETE_CONTACTS => array(
'title' => ts('Delete contacts'),
'class' => 'CRM_Contact_Form_Task_Delete',
'result' => FALSE,
'url' => 'civicrm/task/delete-contact',
),
self::RECORD_CONTACTS => array(
'title' => ts('Add activity'),
Expand All @@ -137,6 +143,7 @@ public static function initTasks() {
'title' => ts('Mailing labels - print'),
'class' => 'CRM_Contact_Form_Task_Label',
'result' => TRUE,
'url' => 'civicrm/task/make-mailing-label',
),
self::BATCH_UPDATE => array(
'title' => ts('Update multiple contacts'),
Expand All @@ -145,19 +152,23 @@ public static function initTasks() {
'CRM_Contact_Form_Task_Batch',
),
'result' => TRUE,
'url' => 'civicrm/task/pick-profile',
),
self::PRINT_FOR_CONTACTS => array(
'title' => ts('Print/merge document'),
'class' => 'CRM_Contact_Form_Task_PDF',
'result' => TRUE,
'url' => 'civicrm/task/print-document',
),
self::EMAIL_UNHOLD => array(
'title' => ts('Email - unhold addresses'),
'class' => 'CRM_Contact_Form_Task_Unhold',
'url' => 'civicrm/task/unhold-email',
),
self::COMMUNICATION_PREFS => array(
'title' => ts('Communication preferences - alter'),
'class' => 'CRM_Contact_Form_Task_AlterPreferences',
'url' => 'civicrm/task/alter-contact-preference',
),
self::RESTORE => array(
'title' => ts('Restore contacts from trash'),
Expand Down Expand Up @@ -376,4 +387,28 @@ public static function getTask($value) {
);
}

/**
* Function to return the task information on basis of provided task's form name
*
* @param string $className
*
* @return array
*/
public static function getTaskAndTitleByClass($className) {
self::initTasks();

foreach (self::$_tasks as $task => $value) {
if (!empty($value['url']) && (
(is_array($value['class']) && in_array($className, $value['class'])) ||
($value['class'] == $className)
)
) {
return array(
$task,
CRM_Utils_Array::value('title', $value),
);
}
}
}

}
55 changes: 55 additions & 0 deletions CRM/Core/xml/Menu/Misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,59 @@
<access_arguments>access CiviCRM</access_arguments>
<title>Insert CiviCRM Content</title>
</item>
<item>
<path>civicrm/task/add-to-group</path>
<page_callback>CRM_Contact_Form_Task_AddToGroup</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/remove-from-group</path>
<page_callback>CRM_Contact_Form_Task_RemoveFromGroup</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/add-to-tag</path>
<page_callback>CRM_Contact_Form_Task_AddToTag</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/remove-from-tag</path>
<page_callback>CRM_Contact_Form_Task_RemoveFromTag</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/send-email</path>
<page_callback>CRM_Contact_Form_Task_Email</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/make-mailing-label</path>
<page_callback>CRM_Contact_Form_Task_Label</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/pick-profile</path>
<page_callback>CRM_Contact_Form_Task_PickProfile</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/print-document</path>
<page_callback>CRM_Contact_Form_Task_PDF</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/unhold-email</path>
<page_callback>CRM_Contact_Form_Task_Unhold</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/alter-contact-preference</path>
<page_callback>CRM_Contact_Form_Task_AlterPreferences</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/task/delete-contact</path>
<page_callback>CRM_Contact_Form_Task_Delete</page_callback>
<access_arguments>access CiviCRM</access_arguments>
</item>
</menu>