Avatars in your Activity
Last updated on
30 April 2025
You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules
1) create a view field handler for the message field
/**
* Field handler to provide the activity message
*/
class my_module_views_handler_field_message extends activity_views_handler_field_message {
function query() {
return activity_views_handler_field_message::query();
}
function pre_render($values) {
return activity_views_handler_field_message::pre_render($values);
}
function render($values) {
$status = activity_views_handler_field_message::render($values);
$status = _render_user_avatars($status);
return $status;
}
function _render_user_avatars($status) {
preg_match_all("@<a[^<]*profile[^<]*</a>@", $status, $result, PREG_SET_ORDER);
foreach ($result as $matches) {
foreach ($matches as $match) {
$username = strip_tags($match);
$user = user_load(array("name" => $username));
$token = "<span class='user-picture-token'>".theme("user_picture", $user).theme("username", $user)."</span>";
$status = str_replace($match, $token, $status);
}
}
return $status;
}
}
2) Register the handler
/**
* Implementation of hook_views_handlers().
*/
function my_module_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'my_module'),
),
'handlers' => array(
'my_module_views_handler_field_message' => array(
'parent' => 'activity_views_handler_field_message',
),
),
);
}
3) Hook in to the api, set to use the new handler
function my_module_views_api() {
return array(
'api' => 2,
);
}
function my_module_views_data_alter(&$data) {
$data['activity_messages']['message']['field']['handler'] = 'my_module_views_handler_field_message';
}
4) Rebuild cache and go
Go to admin/settings/performance and clear cache, then give it a go.
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion