Skip to content

Commit

Permalink
Issue: #2503949 by mccrodp: Fixed redirection for deletion of private…
Browse files Browse the repository at this point in the history
… messages
  • Loading branch information
mccrodp committed Jun 12, 2015
1 parent dc1aa72 commit f862ec2
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion message_private.module
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ function message_private_menu_alter(&$items) {
$items['message/%message/edit']['access callback'] = 'message_private_access_control';
$items['message/%message/delete']['access callback'] = 'message_private_access_control';

$items['message/%message/delete']['page arguments'] = array('message_private_instance_delete', 1);

// Override page arguments for message edit forms.
$items['message/%message/edit']['page arguments'] = array('message_private_instance_message_manage', 1);

Expand Down Expand Up @@ -284,7 +286,7 @@ function message_private_instance_message_manage($form, &$form_state, $message)
|| $message == 'private_message') {
global $user;

$referer = $_SERVER['HTTP_REFERER']; // Get the referer uri from globals.
$referer = $_SERVER['HTTP_REFERER']; // Get the referrer 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'));
Expand All @@ -293,6 +295,60 @@ function message_private_instance_message_manage($form, &$form_state, $message)
return $form;
}

/**
* Deleting the message.
*
* Override message_ui : message_ui_instance_delete.
*/
function message_private_instance_delete($form, &$form_state, Message $message) {
// When the bundle is exported - display a message to the user.
$form_state['#entity'] = $message;

$redirect_uri = 'admin/content/message'; // Set redirect uri to default.

// For private messages, alter the redirect url.
if ($message->type == 'private_message') {
global $user;

// Redirect back to user message inbox.
$redirect_uri = 'user/' . $user->uid . '/messages';
}

// Always provide entity id in the same form key as in the entity edit form.
return confirm_form($form,
t('Are you sure you want to delete the @type message instance?',
array('@type' => $message->type)),
$redirect_uri,
t('Are you sure you want to delete the message instance? This action cannot be undone.'),
t('Delete'),
t('Cancel'));
}

/**
* Deleting the sub theme submit handler.
*
* Override message_ui : message_ui_instance_delete_submit.
*/
function message_private_instance_delete_submit($form, &$form_state) {
if ($form_state['clicked_button']['#type']) {
$form_state['#entity']->delete();

$form_state['redirect'] = 'admin/content/message';

// For private messages, alter the redirect url.
if ($form_state['#entity']->type == 'private_message') {
global $user;

// Redirect back to user message inbox.
$form_state['redirect'] = 'user/' . $user->uid . '/messages';
}

drupal_set_message(t('The message instance @type deleted successfully', array(
'@type' => $form_state['#entity']->type,
)));
}
}

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

0 comments on commit f862ec2

Please sign in to comment.