Commit 728c22a4 authored by RoSk0's avatar RoSk0

#12540: Added ability to add activity prior to select contact.

parent 6058e8dd
......@@ -9,28 +9,37 @@
* Implements hook_menu().
*/
function crm_core_activity_ui_menu() {
$items['crm-core/contact/%crm_core_contact/activity/add'] = array(
'title' => 'Add an activity',
'page callback' => 'crm_core_activity_ui_add_activity',
'page arguments' => array(2),
'access callback' => 'entity_access',
'access arguments' => array('create_view', 'crm_core_activity'),
'type' => MENU_LOCAL_ACTION,
'file' => 'crm_core_activity_ui.pages.inc',
$activity_paths = array(
'no_contact' => 'crm-core/activity/add',
'contact' => 'crm-core/contact/%crm_core_contact/activity/add',
);
foreach (crm_core_activity_types() as $type => $info) {
$items['crm-core/contact/%crm_core_contact/activity/add/' . $type] = array(
'title' => 'Add activity @type',
'title arguments' => array('@type' => $info->label),
'description' => $info->description,
'page callback' => 'crm_core_activity_entity_ui_get_form_wrapper',
'page arguments' => array(2, 5),
foreach ($activity_paths as $key => $path) {
$items[$path] = array(
'title' => 'Add an activity',
'page callback' => 'crm_core_activity_ui_add_activity',
'page arguments' => array(($key == 'contact' ? 2 : NULL)),
'access callback' => 'entity_access',
'access arguments' => array('create', 'crm_core_activity', 5),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('create_view', 'crm_core_activity'),
'type' => MENU_LOCAL_ACTION,
'file' => 'crm_core_activity_ui.pages.inc',
);
if ($key == 'no_contact') {
$items[$path]['weight'] = 100;
}
foreach (crm_core_activity_types() as $type => $info) {
$items[$path . '/' . $type] = array(
'title' => 'Add activity @type',
'title arguments' => array('@type' => $info->label),
'description' => $info->description,
'page callback' => 'crm_core_activity_entity_ui_get_form_wrapper',
'page arguments' => ($key == 'contact' ? array(2, 5) : array(NULL, 3)),
'access callback' => 'entity_access',
'access arguments' => array('create', 'crm_core_activity', 5),
'type' => MENU_NORMAL_ITEM,
'file' => 'crm_core_activity_ui.pages.inc',
);
}
}
$items['crm-core/activity/%crm_core_activity'] = array(
......@@ -145,6 +154,7 @@ function crm_core_activity_ui_admin_menu_map() {
// Create expansion arguments for the '%crm_core_activity_type' placeholder.
'arguments' => $arguments,
);
return $map;
}
......@@ -215,5 +225,6 @@ function _crm_core_activity_ui_set_breadcrumb($contact) {
*/
function crm_core_activity_ui_view($activity, $contact) {
_crm_core_activity_ui_set_breadcrumb($contact);
return crm_core_activity_view($activity);
}
......@@ -12,18 +12,21 @@
* @param string $type
*/
function crm_core_activity_entity_ui_get_form_wrapper($contact, $type) {
$values = array(
'type' => $type,
'field_activity_participants' => array(
LANGUAGE_NONE => array(array(
$values = array('type' => $type);
if ($contact) {
$values['field_activity_participants'] = array(
LANGUAGE_NONE => array(
array(
'target_id' => $contact->contact_id,
'target_type' => 'crm_core_contact',
),
),
),
);
);
}
$activity = entity_create('crm_core_activity', $values);
return entity_ui_get_form('crm_core_activity', $activity, 'add');
}
......@@ -153,13 +156,20 @@ function crm_core_activity_form_submit_delete($form, &$form_state) {
unset($_GET['destination']);
}
$activity = $form_state['crm_core_activity'];
$form_state['redirect'] = array('crm-core/activity/' . $activity->activity_id . '/delete', array('query' => $destination));
$form_state['redirect'] = array(
'crm-core/activity/' . $activity->activity_id . '/delete',
array('query' => $destination)
);
}
function crm_core_activity_form_delete_confirm($form, &$form_state, $activity) {
$form_state['activity'] = $activity;
// Always provide entity id in the same form key as in the entity edit form.
$form['activity_id'] = array('#type' => 'value', '#value' => $activity->activity_id);
$form['activity_id'] = array(
'#type' => 'value',
'#value' => $activity->activity_id
);
return confirm_form($form,
t('Are you sure you want to delete activity %title?', array('%title' => $activity->title)),
'crm-core/activity/' . $activity->activity_id,
......@@ -177,7 +187,10 @@ function crm_core_activity_form_delete_confirm_submit($form, &$form_state) {
$activity = $form_state['activity'];
crm_core_activity_delete($activity);
watchdog('crm_core_activity', '@type: deleted %title.', array('@type' => $activity->type, '%title' => $activity->title));
watchdog('crm_core_activity', '@type: deleted %title.', array(
'@type' => $activity->type,
'%title' => $activity->title
));
drupal_set_message(t('@type %title has been deleted.', array(
'@type' => crm_core_activity_type_get_name($activity->type),
'%title' => $activity->title,
......@@ -194,28 +207,48 @@ function crm_core_activity_form_delete_confirm_submit($form, &$form_state) {
}
/**
* Add activity page callback
* Add activity page callback.
*
* @param $contact object
* CRM Core contact.
* @param object $contact
* CRM Core contact.
*
* @return string
* Activity types list or empty text.
*/
function crm_core_activity_ui_add_activity($contact) {
function crm_core_activity_ui_add_activity($contact = NULL) {
global $user;
$items = array();
drupal_set_title(t('Add a activity'));
_crm_core_activity_ui_set_breadcrumb($contact);
$items = array();
$contact_uri = $contact->uri();
foreach (crm_core_activity_types() as $info) {
if (entity_access('create', 'crm_core_activity', $info->type, $user)) {
$items[] = array(
'title' => $info->label,
'href' => $contact_uri['path'] . '/activity/add/' . $info->type,
'localized_options' => array(),
'description' => $info->description,
);
if ($contact) {
_crm_core_activity_ui_set_breadcrumb($contact);
$contact_uri = $contact->uri();
foreach (crm_core_activity_types() as $info) {
if (entity_access('create', 'crm_core_activity', $info->type, $user)) {
$items[] = array(
'title' => $info->label,
'href' => $contact_uri['path'] . '/activity/add/' . $info->type,
'localized_options' => array(),
'description' => $info->description,
);
}
}
}
else {
foreach (crm_core_activity_types() as $info) {
if (entity_access('create', 'crm_core_activity', $info->type, $user)) {
$items[] = array(
'title' => $info->label,
'href' => 'crm-core/activity/add/' . $info->type,
'localized_options' => array(),
'description' => $info->description,
);
}
}
}
$empty = 'It is not possible to create Activities yet. Please create Activity Type fist.';
return empty($items) ? t($empty) : theme('crm_core_contact_ui_add_list', array('content' => $items));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment