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 overridden 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
47 * Theme the participants field.
49 function theme_privatemsg_list_field__participants($variables) {
50 $thread = $variables['thread'];
51 $participants = _privatemsg_generate_user_array($thread['participants'], -4);
53 $field['data'] = _privatemsg_format_participants($participants, 3, TRUE
);
54 $field['class'][] = 'privatemsg-list-participants';
59 * Theme the subject of the thread.
61 function theme_privatemsg_list_field__subject($variables) {
62 $thread = $variables['thread'];
66 if (!empty($thread['is_new'])) {
67 $is_new = theme('mark', array('type' => MARK_NEW
));
68 $options['fragment'] = 'new';
70 $subject = $thread['subject'];
71 if ($thread['has_tokens']) {
72 $message = privatemsg_message_load($thread['thread_id']);
73 $subject = privatemsg_token_replace($subject, array('privatemsg_message' => $message), array('sanitize' => TRUE
, 'privatemsg-show-span' => FALSE
));
75 $field['data'] = l($subject, 'messages/view/' .
$thread['thread_id'], $options) .
$is_new;
76 $field['class'][] = 'privatemsg-list-subject';
81 * Theme the replies field.
83 function theme_privatemsg_list_field__count($variables) {
84 $thread = $variables['thread'];
86 $field['data'] = $thread['count'];
88 if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
89 $options['fragment'] = 'new';
90 $field['data'] .
= '<br />' .
l((format_plural($thread['is_new'], '(1 new)', '(@count new)')), 'messages/view/' .
$thread['thread_id'], $options);
92 $field['class'][] = 'privatemsg-list-count';
97 * Theme the last updated column.
99 function theme_privatemsg_list_field__last_updated($variables) {
100 $thread = $variables['thread'];
101 $field['data'] = privatemsg_format_date($thread['last_updated']);
102 $field['class'][] = 'privatemsg-list-date';
107 * Theme the thread started column.
109 function theme_privatemsg_list_field__thread_started($variables) {
110 $thread = $variables['thread'];
112 $field['data'] = privatemsg_format_date($thread['thread_started']);
113 $field['class'][] = 'privatemsg-list-date-started';
118 * Theme a block which displays the number of new messages a user has.
120 function theme_privatemsg_new_block($count) {
121 $count = $count['count'];
123 $text = t('Click here to go to your messages.');
126 $text = format_plural($count, 'You have a new message! Click here to read it.',
127 'You have @count new messages! Click here to read them.');
130 return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
134 * Used to theme and display user recipients.
136 * Wrapper for theme_username() with a few additional options.
138 function theme_privatemsg_username($variables) {
139 $recipient = $variables['recipient'];
140 $options = $variables['options'];
141 if (!isset($recipient->uid
)) {
142 $recipient->uid
= $recipient->recipient
;
144 if (!empty($options['plain'])) {
145 $name = check_plain(format_username($recipient));
146 if (!empty($options['unique'])) {
152 return theme('username', array('account' => $recipient));
157 * Output the admin settings display fields and weight settings as a
158 * drag and drop sortable table.
160 function theme_privatemsg_admin_settings_display_fields($variables) {
161 $element = $variables['element'];
163 array('data' => t('Field'), 'class' => array('field')),
164 array('data' => t('Enable'), 'class' => array('enable')),
165 array('data' => t('Weight'), 'class' => array('weight')),
168 foreach (element_children($element['privatemsg_display_fields']) as
$child) {
172 $row[] = array('data' => $element['privatemsg_display_fields'][$child]['#title'], 'class' => array('field'));
173 unset($element['privatemsg_display_fields'][$child]['#title']);
176 $row[] = array('data' => drupal_render($element['privatemsg_display_fields'][$child]), 'class' => array('enable'));
179 unset($element['privatemsg_display_fields_weights'][$child]['#title']);
180 $element['privatemsg_display_fields_weights'][$child]['#attributes']['class'] = array('privatemsg-display-fields-weight');
182 'data' => drupal_render($element['privatemsg_display_fields_weights'][$child]),
183 'class' => array('weight'),
186 $rows[] = array('data' => $row, 'class' => array('draggable'));
189 drupal_add_tabledrag('privatemsg-list-display-fields', 'order', 'sibling', 'privatemsg-display-fields-weight');
190 return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'privatemsg-list-display-fields'))) .
drupal_render_children($element);
193 return drupal_render_children($element);