hansel_og.module in Hansel breadcrumbs 8
Same filename and directory in other branches
Hansel organic groups integration
This module provides switches and actions for organic groups.
File
og/hansel_og.moduleView source
<?php
/**
* @file
* Hansel organic groups integration
*
* This module provides switches and actions for organic groups.
*/
/**
* Implements hook_hansel_action_types().
*/
function hansel_og_hansel_action_types() {
return array(
'add og path' => array(
'get crumbs' => 'hansel_og_action_add_og_path_get_crumbs',
'info' => 'hansel_og_action_add_og_path_info',
'config form' => 'hansel_og_action_add_og_path_config_form',
),
);
}
/**
* Callback for "add og path" breadcrumb action
*
* @param array $arguments Values from the configuration form.
* @return array
*/
function hansel_og_action_add_og_path_get_crumbs($arguments) {
$links = array();
if (hansel_arg(0) == 'node' && is_numeric(hansel_arg(1))) {
if ($node = og_get_group_context()) {
if (in_array($node->type, $arguments['group'])) {
if ($arguments['type']) {
// Add the type of group in the breadcrumb
$links[] = array(
'title' => drupal_ucfirst($node->type),
'href' => $arguments['path_' . $node->type],
);
}
// Add group name to breadcrumb
$links[] = array(
'title' => $node->title,
'href' => $node->path,
);
}
}
}
return $links;
}
/**
* Callback for "add og path" action to generate the information line
*
* @param array $arguments Values from the configuration form.
* @return string
*/
function hansel_og_action_add_og_path_info($arguments) {
if (empty($arguments['group'])) {
return t('No group selected.');
}
else {
$groups = array();
foreach ($arguments['group'] as $group) {
if (!empty($group)) {
$groups[] = drupal_ucfirst($group);
}
}
$groups = implode(', ', $groups);
return t('Add og path for following groups: %groups', array(
'%groups' => $groups,
));
}
}
/**
* Callback to generate the configuration form for the "add og path" action
*
* @param array $arguments
* @return array
*/
function hansel_og_action_add_og_path_config_form($arguments) {
$form = array();
$options = array();
foreach (node_type_get_types() as $name => $type) {
$type_url_str = str_replace('_', '-', $type->type);
$usage = variable_get('og_content_type_usage_' . $type->type, 'omitted');
if ($usage == 'group') {
$options[$name] = drupal_ucfirst($type->name);
}
}
$form['group'] = array(
'#type' => 'checkboxes',
'#title' => t('Organic group'),
'#options' => $options,
'#description' => t('Use only for these groups. This only applies when this is a group type.'),
'#default_value' => isset($arguments['group']) ? $arguments['group'] : array(),
'#required' => TRUE,
'#attributes' => array(
'class' => 'hansel-og-checkboxes',
),
);
// Add configurable paths per type
foreach ($options as $key => $option) {
$form['path_' . $key] = array(
'#type' => 'textfield',
'#title' => t($option . ' path'),
'#description' => t('Provide a path to link to in the breadcrumb'),
'#default_value' => isset($arguments['path_' . $key]) ? $arguments['path_' . $key] : 'og',
'#attributes' => array(
'class' => 'og-hansel-path og-hansel-path-' . $key,
'display' => 'none',
),
);
}
$form['type'] = array(
'#type' => 'checkbox',
'#title' => t('Show type of group in breadcrumb'),
'#description' => t('Select this if you want to dipslay the type of group in the breadcrumb.'),
'#default_value' => isset($arguments['type']) ? $arguments['type'] : 0,
'#attributes' => array(
'class' => 'og-hansel-type',
),
);
return $form;
}
/**
* Implements hook_hansel_cache_parts_alter().
*/
function hansel_og_hansel_cache_parts_alter(&$parts) {
if ($node = og_get_group_context()) {
$parts[] = $node->nid;
}
}
Functions
Name![]() |
Description |
---|---|
hansel_og_action_add_og_path_config_form | Callback to generate the configuration form for the "add og path" action |
hansel_og_action_add_og_path_get_crumbs | Callback for "add og path" breadcrumb action |
hansel_og_action_add_og_path_info | Callback for "add og path" action to generate the information line |
hansel_og_hansel_action_types | Implements hook_hansel_action_types(). |
hansel_og_hansel_cache_parts_alter | Implements hook_hansel_cache_parts_alter(). |