function farm_group_entity_view_alter in farmOS 7
Implements hook_entity_view_alter().
File
- modules/
farm/ farm_group/ farm_group.module, line 89
Code
function farm_group_entity_view_alter(&$build, $type) {
// If it's not a farm_asset, or if the entity object is not available, bail.
if ($type != 'farm_asset' || empty($build['#entity'])) {
return;
}
// Get the asset's group membership.
$membership = farm_group_asset_membership($build['#entity']);
// If no group membership information was found, bail.
if (empty($membership)) {
return;
}
// Start an output string.
$output = '<strong>' . t('Group membership') . ':</strong> ';
// Iterate through the group memberships and add links to them.
$group_links = array();
foreach ($membership as $group) {
$uri = entity_uri('farm_asset', $group);
if (!empty($uri['path'])) {
$group_links[] = l(entity_label('farm_asset', $group), $uri['path']);
}
}
$output .= implode(', ', $group_links);
// Add it to the build array.
$build['group'] = array(
'#markup' => $output,
'#prefix' => '<div class="group-membership">',
'#suffix' => '</div>',
'#weight' => -110,
);
}