function theme_views_view_field__message_example__name in Message 6
Theme the user name, and add an icon before it, based on the message name.
File
- modules/
message_example/ message_example.module, line 219
Code
function theme_views_view_field__message_example__name($view, $field, $row) {
// Add out custom CSS to the view.
$css =& ctools_static(__FUNCTION__, FALSE);
if (!$css) {
// Add our css.
drupal_add_css(drupal_get_path('module', 'message_example') . '/message_example.css');
$css = TRUE;
}
// TODO: Isn't there a shorter way?
$output = $view->field[$field->options['id']]
->advanced_render($row);
if (!empty($view->field['name_1']->field_alias) && ($message_name = $row->{$view->field['name_1']->field_alias})) {
$image = '';
// Check if the message name has a matching icon in the images folder.
switch ($message_name) {
case 'message_example_node_insert':
case 'message_example_comment_insert':
case 'message_example_flag_user':
case 'message_example_flag_node':
// Remove the module name prefix.
$message_name = str_replace('message_example_', '', $message_name);
// Replace underscore with hyphens.
$image = str_replace('_', '-', $message_name);
break;
}
if ($image) {
// Add the image.
$image = theme('image', drupal_get_path('module', 'message_example') . '/images/' . $image . '.png');
$output = $image . ' ' . $output;
}
}
return $output;
}