function commons_groups_related_groups_text in Drupal Commons 7.3
Build the related-groups text for nodes.
Parameters
$related_groups: Array of groups referenced by the node.
Return value
String containing the related groups.
1 call to commons_groups_related_groups_text()
- commons_groups_tokens in modules/
commons/ commons_groups/ commons_groups.module - Implements hook_tokens().
File
- modules/
commons/ commons_groups/ commons_groups.module, line 647
Code
function commons_groups_related_groups_text($related_groups) {
// In 1 group: "in the x group"
if (count($related_groups) == 1) {
return t(' in the !group group', array(
'!group' => l($related_groups[0]->title, 'node/' . $related_groups[0]->nid),
));
}
// In 2 groups: "in the x and y groups"
if (count($related_groups) == 2) {
return t(' in the !group-0 and !group-1 groups', array(
'!group-0' => l($related_groups[0]->title, 'node/' . $related_groups[0]->nid),
'!group-1' => l($related_groups[1]->title, 'node/' . $related_groups[1]->nid),
));
}
// In more than 2 groups: "in the x, y and z groups"
if (count($related_groups) > 2) {
// Separate the last group.
$last_group = array_pop($related_groups);
$text = ' in the ';
// Prepare tokens for t() for each of the other groups.
foreach ($related_groups as $key => $this_group) {
$text .= "!group-{$key}, ";
$t_args["!group-{$key}"] = l($this_group->title, 'node/' . $this_group->nid);
}
// Prepare the last group token.
$text .= " and !group-{$last_group->nid} groups.";
$t_args["!group-{$last_group->nid}"] = l($last_group->title, 'node/' . $last_group->nid);
// Prepare the full text with all of the groups and their tokens:
return t($text, $t_args);
}
}