Adding multiple Contacts to case bulk action
Overview
We want to add multiple clients to a single case.
Example use-case
- Click on Search > Find Contacts
- Click on the Search submit button
- Select any number of contacts
- Click on Actions > Add to case as role
- Assign to any open case
-
Relationship Type should be client
⚠
Current behaviour
The are no client relationships.
We treat client as a relationship when we show them on the case's roles panel, but don't show this relationship type on the bulk actions.
We understand this issue happens because CiviCRM manages relationships between contacts, and Cases are an entity. But, for the user perspective, we should add support to this type of relationship.
Proposed behaviour
We have two proposals:
- Add client as a relationship type for the Relationship Type dropdown on the Add to case as role bulk action. This can be added through hooks (more on that in a bit)
- Add a new Add to case as client bulk action.
Option 1
We push ['client' => 'Client
]` directly to the list of relationship types here:
https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/AddToCaseAsRole.php#L13
then we handle the form differently if the selected role was client:
// ...
public function postProcess() {
$values = $this->controller->exportValues();
$caseId = (int) $values['assign_to'];
$roleTypeId = (string) $values['role_type']; // need to change this
$contacts = $this->_contactIds;
// if "client" was selected then we handle the form diferently
if ($roleTypeId === 'client') {
// add selected contacts as clients
} else {
// handle the form as normal when no custom handlers have been defined
}
}
Option 1 using hooks
This could be accomplished by allowing a hook on this line: https://github.com/civicrm/civicrm-core/blob/master/CRM/Case/Form/AddToCaseAsRole.php#L13
The code could look as follows
<?php
// ...
public function buildQuickForm() {
$roleTypes = $this->getRoleTypes();
// this is a sample class that triggers the hook by passing these
// role types and allowing the array to be manipulated by hooks:
CRM_Hooks_updateBulkActionRoleTypes($roleTypes);
// continue building the form as usual...
}
The hook's implementer could do the following:
myextension_civicrm_updateBulkActionRoleTypes(&$roleTypes) {
$roleTypes[] = ['client' => 'Client'];
}
Then, when the form is processed we can trigger a hook to get handlers:
// ...
public function postProcess() {
$values = $this->controller->exportValues();
$caseId = (int) $values['assign_to'];
$roleTypeId = (string) $values['role_type']; // need to change this
$contacts = $this->_contactIds;
$addToCaseAsRoleHandlers = [];
// a custom hook as well:
CRM_Hooks_getAddToCaseAsRoleHandlers($addToCaseAsRoleHandlers);
// if we have custom handlers we run them:
if (count($addToCaseAsRoleHandlers)) {
foreach ($addToCaseAsRoleHandlers as $addToCaseAsRoleHandler) {
$addToCaseAsRoleHandlers->run([
'caseId' => $caseId,
'roleTypeId' => $roleTypeId,
'contacts' => $contacts
]);
} else {
// handle the form as normal when no custom handlers have been defined
}
}
Option 2
We add "Add to case as client" directly to the list of bulk action tasks: https://github.com/civicrm/civicrm-core/blob/master/CRM/Contact/Task.php#L60
We add a custom form to handle adding the clients to the case.
Option 2 using hooks
We would do something similar to option #1 (closed) by executing a hook that adds more bulk actions task to a list. In this case the extensions can add their own bulk action:
myextension_civicrm_getBulkActions(&$bulkActions) {
$bulkActions['ADD_TO_CASE_AS_CLIENT'] = array(
'title' => 'Add to case as client',
'class' => 'CRM_Case_Form_AddToCaseAsClient',
'result' => FALSE,
);
}
Comments
Let me know which option you would prefer. There are advantages to implementing them directly into core, or going the hook route:
- if we implement them directly everyone benefits from this feature.
- if we use hooks we don't add a feature that users might not need, but allow developers to customise the experience.