You are here

function theme_privatemsg_list in Privatemsg 6

Same name and namespace in other branches
  1. 6.2 privatemsg.theme.inc \theme_privatemsg_list()

Theme to display the privatemsg list.

This theme builds a table with paging based on the data which has been built by the header and field theme patterns.

Related topics

File

./privatemsg.theme.inc, line 239
Theme functions for privatemsg.

Code

function theme_privatemsg_list($form) {
  $has_posts = !empty($form['#data']);
  drupal_add_css(drupal_get_path('module', 'privatemsg') . '/styles/privatemsg-list.css');

  // Load the table columns.
  $columns = array_merge(array(
    'subject',
    'last_updated',
  ), array_filter(variable_get('privatemsg_display_fields', array(
    'participants',
  ))));

  // Load the themed list headers based on the available data.
  $headers = _privatemsg_list_headers(!empty($form['#data']), $columns);

  // sort the headers array based on the #weight property.
  usort($headers, 'element_sort');
  $themed_rows = array();

  // Check if there is atleast a single thread.
  if ($has_posts) {
    foreach ($form['#data'] as $thread_id => $data) {

      // Theme the row.
      $row = _privatemsg_list_thread($data);
      $data = array();

      // Render the checkbox.
      $data[] = array(
        'data' => drupal_render($form['threads'][$thread_id]),
        'class' => 'privatemsg-list-select',
      );

      // Store the #rows data in the same order as the header is, the key property of the header refers to the field that belongs to it.
      foreach ($headers as $header) {
        if (!empty($header['key'])) {
          if (isset($row['data'][$header['key']])) {
            $data[] = $row['data'][$header['key']];
          }
          else {

            // Store a empty value so that the order is still correct.
            $data[] = '';
          }
        }
      }

      // Replace the data
      $row['data'] = $data;
      $themed_rows[] = $row;
    }
  }
  else {

    // Display a message if now messages are available.
    $themed_rows[] = array(
      array(
        'data' => t('No messages available.'),
        'colspan' => count($headers),
      ),
    );
  }

  // Remove any data in header that we don't need anymore.
  foreach ($headers as $id => $header) {
    unset($headers[$id]['key']);
    unset($headers[$id]['#weight']);
  }

  // Theme the table, pass all generated information to the table theme function.
  $form['list'] = array(
    '#value' => theme('table', $headers, $themed_rows, array(
      'class' => 'privatemsg-list',
    )),
    '#weight' => 5,
  );
  return drupal_render($form);
}