crumbs.og.inc in Crumbs, the Breadcrumbs suite 7
File
plugins/crumbs.og.inc
View source
<?php
function og_crumbs_plugins($api) {
$api
->multiPlugin('group_post');
$api
->monoPlugin('groups_overview_title');
$api
->multiPlugin('groups_overview', new og_CrumbsMultiPlugin_groups_overview('group-list'));
$api
->multiPlugin('my_groups_overview', new og_CrumbsMultiPlugin_my_groups_overview('user-groups'));
}
class og_CrumbsMultiPlugin_group_post implements crumbs_MultiPlugin {
function describe($api) {
$types = node_type_get_types();
foreach ($types as $type) {
if (og_is_group_content_type('node', $type->type)) {
$api
->addRule($type->type);
}
}
}
function findParent__node_x($path, $item) {
$node = $item['map'][1];
$node = is_numeric($node) ? node_load($node) : $node;
$items = field_get_items('node', $node, 'group_audience');
if ($items) {
foreach ($items as $item) {
$row = db_query("SELECT * FROM {og} WHERE gid = :gid", array(
':gid' => $item['gid'],
))
->fetchObject();
if ($row && $row->entity_type === 'node') {
$parent_path = $this
->getParentPath($row->etid, $node);
return array(
$node->type => $parent_path,
);
}
}
}
}
protected function getParentPath($group_nid, $group_post) {
return 'node/' . $group_nid;
}
}
class og_CrumbsMultiPlugin_groups_overview implements crumbs_MultiPlugin {
protected $groupsOverviewPath;
function __construct($groups_overview_path) {
$this->groupsOverviewPath = $groups_overview_path;
}
function describe($api) {
$types = node_type_get_types();
foreach ($types as $type) {
if (og_is_group_type('node', $type->type)) {
$api
->addRule($type->type);
}
}
}
function findParent__node_x($path, $item) {
$node = $item['map'][1];
$node = is_numeric($node) ? node_load($node) : $node;
$items = field_get_items('node', $node, 'group_group');
if ($items) {
return array(
$node->type => 'group-list',
);
}
}
}
class og_CrumbsMonoPlugin_groups_overview_title implements crumbs_MonoPlugin {
function describe($api) {
return t('Set "Group" as the title for item for "group-list".');
}
function findTitle($path, $item) {
if ($item['route'] === 'group-list') {
return t('Groups');
}
}
}
class og_CrumbsMultiPlugin_my_groups_overview implements crumbs_MultiPlugin {
protected $myGroupsPath;
function __construct($my_groups_path) {
$this->myGroupsPath = $my_groups_path;
}
function describe($api) {
$types = node_type_get_types();
foreach ($types as $type) {
if (og_is_group_type('node', $type->type)) {
$api
->addRule($type->type);
}
}
}
function findParent__node_x($path, $item) {
$node = $item['map'][1];
$node = is_numeric($node) ? node_load($node) : $node;
if (og_is_group_type('node', $node->type)) {
$group = og_get_group('node', $node->nid);
if (!empty($group)) {
if (og_is_member($group->gid)) {
return array(
$node->type => 'user-groups',
);
}
}
}
}
}