Skip to content

Commit

Permalink
Added fix for hook_form_alter change in 2nd last commit. Message Priv…
Browse files Browse the repository at this point in the history
…ate now uses message_ui callbacks for private_message form.
  • Loading branch information
mccrodp committed Jun 15, 2015
1 parent 69a0e80 commit c403455
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ displays sent messages and the "Group" local task which displays group messages.
SECURITY
--------
This module does not come with any security features out-of-the-box, but you can
easily configure your own, using methods and modules of you choice.
easily configure your own, using methods and modules of your choice.

Examples:

Expand All @@ -122,13 +122,14 @@ CAPTCHA method: https://www.drupal.org/project/recaptcha

DEVELOPMENT AND TEST
--------------------
* Threads will be created: https://www.drupal.org/node/2367729#comment-9480579.
* Threads will be created: https://www.drupal.org/node/2504863.
An admin setting can be used to enable or disable threads to turn on/off
replies on all private messages (Reply, Reply All). Perhaps a css file will
need to be added for indentation / presentation. Integrate with MessageJS,
nodeJS or socket.io.
* Flag module on user entity to block/unblock users from messaging them
* Flag module on message entity to show/hide messages from users own display
* Flag module on message entity to show/hide (delete) messages from users own
display
* Allow Operations links to display correctly on views, i.e. - show 'View' for
users with view permissions. Not showing currently due to custom permissions.
* Integrate with rolereference module or similar to provide sending to users
Expand Down
30 changes: 10 additions & 20 deletions message_private.module
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function message_private_menu() {
'title' => 'Private Message',
'description' => 'Create a new message Private Message instance',
'page callback' => 'drupal_get_form',
'page arguments' => array('message_private_instance_message_manage', 'private_message'),
'page arguments' => array('message_ui_instance_message_manage', 'private_message'),
'access arguments' => array('create', 'private_message'),
'access callback' => 'message_private_access_control',
);
Expand Down Expand Up @@ -266,12 +266,12 @@ function message_private_create_new_message_instance_list() {
return theme('item_list', array('items' => $items));
}


/**
* Implements hook_form_FORM_ID_alter().
*
* 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.
* allows override specific values of the form such as the cancel link. It hides
* the message_text on the edit and create form, and adds custom validation.
*/
function message_private_form_message_ui_instance_message_manage_alter(&$form, &$form_state, $form_id) {
if (!empty($form_state['#entity']) && $form_state['#entity']->type == 'private_message') {
Expand All @@ -281,6 +281,12 @@ function message_private_form_message_ui_instance_message_manage_alter(&$form, &
// 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'));

if (isset($form['text']['#type'])) {
$form['text']['#type'] = 'hidden';
}
$form['owner']['#access'] = user_access('bypass private message access control');
$form['#validate'][] = 'message_private_form_message_private_instance_message_manage_validate';
}
}

Expand Down Expand Up @@ -332,7 +338,7 @@ function message_private_menu_local_tasks_alter(&$data, $router_item, $root_path
$to_user = array_shift($router_item['page_arguments']);
}
// Only display the local task on other users profile, not current user's.
if (!empty($to_user) && !empty($to_user->uid) && $user->uid != $to_user->uid) {
if (!empty($to_user) && $user->uid != $to_user->uid) {
$item = menu_get_item('message/create/private-message');
$item['title'] = t('Create a new message for') . ' ' . $to_user->name;
$item['localized_options']['query'] = array('field_message_user_ref' => $to_user->uid);
Expand Down Expand Up @@ -385,22 +391,6 @@ function message_private_menu_local_tasks_alter(&$data, $router_item, $root_path
}
}

/**
* Implements hook_form_FORM_ID_alter().
*
* Hide the message_text field from the message edit form. It is only useful
* post creation. i.e. - contains user data. Also add custom validate function.
*/
function message_private_form_message_private_instance_message_manage_alter(&$form, &$form_state, $form_id) {
if ($form['#bundle'] == 'private_message') {
if (isset($form['text']['#type'])) {
$form['text']['#type'] = 'hidden';
}
$form['owner']['#access'] = user_access('bypass private message access control');
$form['#validate'][] = 'message_private_form_message_private_instance_message_manage_validate';
}
}

/**
* Validation for Private Message form.
*
Expand Down

0 comments on commit c403455

Please sign in to comment.