You are here

function privatemsg_list_submit in Privatemsg 7

Same name and namespace in other branches
  1. 6.2 privatemsg.pages.inc \privatemsg_list_submit()
  2. 6 privatemsg.module \privatemsg_list_submit()
  3. 7.2 privatemsg.pages.inc \privatemsg_list_submit()

Process privatemsg_list form submissions.

Execute the chosen action on the selected messages. This function is based on node_admin_nodes_submit().

1 string reference to 'privatemsg_list_submit'
privatemsg_list in ./privatemsg.pages.inc

File

./privatemsg.pages.inc, line 222
User menu callbacks for Privatemsg.

Code

function privatemsg_list_submit($form, &$form_state) {

  // Load all available operation definitions.
  $operations = module_invoke_all('privatemsg_thread_operations', $form['#list_argument']);
  drupal_alter('privatemsg_thread_operations', $operations, $form['#list_argument']);

  // Default "default" operation, which won't do anything.
  $operation = array(
    'callback' => 0,
  );

  // Check if a valid operation has been submitted.
  if (isset($form_state['values']['operation']) && isset($operations[$form_state['values']['operation']])) {
    $operation = $operations[$form_state['values']['operation']];
  }
  if (!empty($form_state['values']['op'])) {

    // Load all keys where the value is the current op.
    $keys = array_keys($form_state['values'], $form_state['values']['op']);

    // Loop over them and detect if a matching button was pressed.
    foreach ($keys as $key) {
      if ($key != 'op' && isset($operations[$key])) {
        $operation = $operations[$key];
      }
    }
  }

  // Only execute something if we have a valid callback and at least one checked thread.
  if (!empty($operation['callback'])) {

    // Hack to fix destination during ajax requests.
    if (isset($form_state['input']['ajax_page_state'])) {
      $destination = 'messages';
      if (!empty($form['#list_argument'])) {
        $destination .= '/' . $form['#list_argument'];
      }
      $_GET['destination'] = $destination;
    }
    privatemsg_operation_execute($operation, $form_state['values']['list'], $form_state['values']['account']);
  }
  $form_state['rebuild'] = TRUE;
  $form_state['input'] = array();
}