5 * Theme functions for privatemsg.
9 * @defgroup theming Theming documentation
11 * It is possible to theme many aspect of privatemsg with theme functions.
13 * For the thread list, so called theme patterns are used to allow flexible
14 * theming of the table and its columns (including columns added by other
17 * Columns are defined with hook_privatemsg_header_info(). The default weight
18 * and if they are enabled or not can by set by default but can be overriden in
19 * the admin user interface.
21 * Additionally, a theme function needs to be defined that defaults to the name
22 * 'privatemsg_list_field__$key', where $key is the name of the header/column.
24 * Every theme function will receive the $thread array as single argument, which
25 * is everything that has been returned by the query built in
26 * privatemsg_sql_list(). The theme function should return either a string or a
27 * theme_table() compatible array.
29 * To change what information is available in that array, it is possible to
30 * either implement hook_privatemsg_sql_list_alter() or alter $form['#data'] of
31 * privatemsg_list(). See privatemsg_filter_form_privatemsg_list_alter() for an
34 * To override an already existing theme function, use the following structure:
35 * themename_privatemsg_list_field_fieldname. It is possible to change the
36 * header definition with hook_privatemsg_header_info_alter() but that is often
46 * Theme the participants field.
48 function phptemplate_privatemsg_list_field__participants($thread) {
49 $participants = _privatemsg_generate_user_array($thread['participants'], -4);
51 $field['data'] = _privatemsg_format_participants($participants, 3, TRUE
);
52 $field['class'] = 'privatemsg-list-participants';
57 * Theme the subject of the thread.
59 function phptemplate_privatemsg_list_field__subject($thread) {
63 if (!empty($thread['is_new'])) {
64 $is_new = theme_mark(MARK_NEW
);
65 $options['fragment'] = 'new';
67 $field['data'] = l($thread['subject'], privatemsg_get_dynamic_url_prefix() .
'/view/' .
$thread['thread_id'], $options) .
$is_new;
68 $field['class'] = 'privatemsg-list-subject';
73 * Theme the replies field.
75 function phptemplate_privatemsg_list_field__count($thread) {
77 $field['data'] = $thread['count'];
79 if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
80 $options['fragment'] = 'new';
81 $field['data'] .
= '<br />' .
l((format_plural($thread['is_new'], '(1 new)', '(@count new)')), privatemsg_get_dynamic_url_prefix() .
'/view/' .
$thread['thread_id'], $options);
83 $field['class'] = 'privatemsg-list-count';
88 * Theme the last updated column.
90 function phptemplate_privatemsg_list_field__last_updated($thread) {
92 $field['data'] = format_date($thread['last_updated'], 'small');
93 $field['class'] = 'privatemsg-list-date';
98 * Theme the thread started column.
100 function phptemplate_privatemsg_list_field__thread_started($thread) {
102 $field['data'] = format_date($thread['thread_started'], 'small');
103 $field['class'] = 'privatemsg-list-date-started';
108 * Theme to display the privatemsg list.
110 * This theme builds a table with paging based on the data which has been built
111 * by the header and field theme patterns.
113 function theme_privatemsg_list($form) {
114 $has_posts = !empty($form['#data']);
116 drupal_add_css(drupal_get_path('module', 'privatemsg') .
'/styles/privatemsg-list.css');
119 $headers = privatemsg_get_headers(TRUE
);
120 $themed_rows = array();
121 // Check if there is atleast a single thread.
123 foreach ($form['#data'] as
$thread_id => $data) {
125 $row = _privatemsg_list_thread($data);
127 // Render the checkbox.
128 $data[] = array('data' => drupal_render($form['threads'][$thread_id]), 'class' => 'privatemsg-list-select');
130 // Store the #rows data in the same order as the header is,
131 // the key property of the header refers to the field that belongs to it.
132 foreach ($headers as
$key => $header) {
133 $data[] = isset($row['data'][$key]) ?
$row['data'][$key] : '';
136 $row['data'] = $data;
137 $themed_rows[] = $row;
139 // Add select all checkox to header array.
140 array_unshift($headers, theme('table_select_header_cell'));
143 // Display a message if now messages are available.
144 $themed_rows[] = array(array('data' => t('No messages available.'), 'colspan' => count($headers)));
147 // Remove any data in header that we don't need anymore.
148 foreach ($headers as
$id => $header) {
149 unset($headers[$id]['key']);
150 unset($headers[$id]['#weight']);
153 // Theme the table, pass all generated information to the table theme function.
154 $form['list'] = array('#value' => theme('table', $headers, $themed_rows, array('class' => 'privatemsg-list')), '#weight' => 5);
155 return drupal_render($form);
159 * Theme a block which displays the number of new messages a user has.
161 function theme_privatemsg_new_block($count) {
163 $text = t('Click here to go to your messages.');
166 $text = format_plural($count, 'You have a new message! Click here to read it.',
167 'You have @count new messages! Click here to read them.',
168 array('@count' => $count));
171 return l($text, privatemsg_get_dynamic_url_prefix(), array('attributes' => array('id' => 'privatemsg-new-link')));
175 * Used to theme and display user recipients.
177 * Wrapper for theme_username() with a few additional options.
179 function theme_privatemsg_username($recipient, $options) {
180 if (!isset($recipient->uid
)) {
181 $recipient->uid
= $recipient->recipient
;
183 if (!empty($options['plain'])) {
184 $name = $recipient->name
;
185 if (!empty($options['unique'])) {
191 return theme('username', $recipient);
196 * Output the admin settings display fields and weight settings as a
197 * drag and drop sortable table.
199 function theme_privatemsg_admin_settings_display_fields($element = array()) {
201 array('data' => t('Field'), 'class' => 'field'),
202 array('data' => t('Enable'), 'class' => 'enable'),
203 array('data' => t('Weight'), 'class' => 'weight'),
206 foreach (element_children($element['privatemsg_display_fields']) as
$child) {
210 $row[] = array('data' => $element['privatemsg_display_fields'][$child]['#title'], 'class' => 'field');
211 unset($element['privatemsg_display_fields'][$child]['#title']);
214 $row[] = array('data' => drupal_render($element['privatemsg_display_fields'][$child]), 'class' => 'enable');
217 unset($element['privatemsg_display_fields_weights'][$child]['#title']);
218 $element['privatemsg_display_fields_weights'][$child]['#attributes']['class'] = 'privatemsg-display-fields-weight';
220 'data' => drupal_render($element['privatemsg_display_fields_weights'][$child]),
224 $rows[] = array('data' => $row, 'class' => 'draggable');
227 drupal_add_tabledrag('privatemsg-list-display-fields', 'order', 'sibling', 'privatemsg-display-fields-weight');
228 return theme('table', $header, $rows, array('id' => 'privatemsg-list-display-fields')) .
drupal_render($element);
231 return drupal_render($element);