Skip to content

Commit

Permalink
Issue #2467975 by mccrodp: Added new page argument in hook_menu_alter…
Browse files Browse the repository at this point in the history
… allowing override of Cancel link on the private message form.
  • Loading branch information
mccrodp committed May 16, 2015
1 parent 04d0035 commit e5382bf
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions message_private.module
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ function message_private_menu_local_tasks_alter(&$data, $router_item, $root_path
*/
function message_private_menu_alter(&$items) {

// Override access callbacks.
$items['message/%message']['access callback'] = 'message_private_access_control';
$items['message/%message/view']['access callback'] = 'message_private_access_control';
$items['message/%message/edit']['access callback'] = 'message_private_access_control';
$items['message/%message/delete']['access callback'] = 'message_private_access_control';

// Override page arguments for message create & edit forms.
$items['admin/content/message/create/private-message']['page arguments'] = array('message_private_instance_message_manage', 'private_message');
$items['message/%message/edit']['page arguments'] = array('message_private_instance_message_manage', 1);

return $items;
}

Expand Down Expand Up @@ -282,6 +287,30 @@ function message_private_access_control($operation, $message, $user_obj = NULL)
return FALSE;
}

/**
* The UI for creating/editing the message.
*
* This function is defined to override that provided by Message UI module. This
* allows override specific values of the form such as the cancel link.
*/
function message_private_instance_message_manage($form, &$form_state, $message) {
// Call message_ui to create the UI.
$form = message_ui_instance_message_manage($form, $form_state, $message);

// When the message is a private message override the cancel link.
if ((!empty($message->type) && $message->type == 'private_message')
|| $message == 'private_message') {
global $user;

$referer = $_SERVER['HTTP_REFERER']; // Get the referer uri from globals.
// Redirect back to referer uri is exists, otherwise to user message inbox.
$form['actions']['cancel']['#markup'] =
l(t('Cancel'), (!empty($referer) ? $referer : 'user/'. $user->uid . '/messages'));
}

return $form;
}

/**
* Implements hook_form_FORM_ID_alter().
*
Expand Down

0 comments on commit e5382bf

Please sign in to comment.