View source
<?php
$plugin = array(
'title' => t('Open Atrium Space Menu'),
'description' => t('The Open Atrium space-specific navigation menu.'),
'category' => array(
t('OA Admin'),
-9,
),
);
function oa_toolbar_oa_space_menu_content_type_render($subtype, $conf, $panel_args) {
$node = menu_get_object();
$front_panel = drupal_is_front_page() && !(isset($node) && $node->type == OA_SPACE_TYPE);
if ($front_panel) {
return;
}
$space_id = oa_core_get_space_context();
$space_id = $space_id ? oa_core_get_group_from_node($space_id) : NULL;
if ($space_id && ($space = node_load($space_id)) && node_access('view', $space)) {
}
else {
$space_id = NULL;
}
if (empty($space_id) || !variable_get('oa_space_menu_' . $space_id, TRUE)) {
return;
}
$vars = array();
if (module_exists('oa_appearance')) {
$field = field_get_items('node', $space, OA_SPACE_BANNER_POSITION);
$show_space_banner = !empty($field[0]['value']) && $field[0]['value'] == OA_SPACE_BANNER_SPACE_MENU;
if ($show_space_banner) {
$space_picture = field_get_items('node', $space, 'field_oa_banner');
if (!empty($space_picture)) {
$space_picture = array_shift($space_picture);
$vars['height'] = $space_picture['height'];
$vars['width'] = $space_picture['width'];
$vars['banner'] = theme('image_style', array(
'style_name' => 'oa_banner',
'path' => $space_picture['uri'],
'width' => $space_picture['width'],
'height' => $space_picture['height'],
'alt' => $space_picture['alt'],
'attributes' => array(
'class' => array(
'oa-banner-img',
),
),
));
$vars['banner'] = l($vars['banner'], 'node/' . $space_id, array(
'html' => true,
));
}
else {
$show_space_banner = FALSE;
}
}
}
$space_menu = ctools_content_render('og_menu_single_menu', '', array(
'og_menu_single_depth' => 1,
'og_menu_single_parent' => '0',
'override_title_text' => '',
'override_title' => TRUE,
), array());
if (!empty($space_menu->content)) {
$space_menu->content['#theme_wrappers'] = array(
'menu_tree__oa_navigation',
);
$terms = oa_sections_get_icons();
if (isset($node) && $node->type != OA_SECTION_TYPE) {
$parent_section = entity_load_single('node', oa_core_get_section_context());
if ($parent_section) {
$parent_section_id = $parent_section->nid;
}
}
elseif (isset($node) && $node->type == OA_SECTION_TYPE) {
$parent_section_id = $node->nid;
}
foreach (element_children($space_menu->content) as $mlid) {
$space_menu->content[$mlid]['#theme'] = 'menu_link__oa_navigation';
$item = menu_get_item($space_menu->content[$mlid]['#href']);
if (!$item['access']) {
$space_menu->content[$mlid]['#access'] = FALSE;
continue;
}
if (!isset($item['map'][1]->nid)) {
continue;
}
$item_node = $item['map'][1];
$icon = '';
if (isset($item_node->field_oa_section[LANGUAGE_NONE][0]['tid'])) {
$term_id = $item_node->field_oa_section[LANGUAGE_NONE][0]['tid'];
if (isset($terms[$term_id])) {
if (!empty($terms[$term_id]->field_oa_icon_class_value)) {
$icon = '<i class="' . check_plain($terms[$term_id]->field_oa_icon_class_value) . '"></i>';
}
else {
if (!empty($terms[$term_id]->field_oa_icon_image_fid)) {
$file = file_load($terms[$term_id]->field_oa_icon_image_fid);
$content = array(
'file' => array(
'#theme' => 'image_style',
'#style_name' => 'oa_medium_thumbnail',
'#path' => $file->uri,
),
);
$icon = drupal_render($content);
}
}
}
}
$space_menu->content[$mlid]['#title'] = $icon . $space_menu->content[$mlid]['#title'];
$space_menu->content[$mlid]['#localized_options']['html'] = TRUE;
if (isset($parent_section_id)) {
if (isset($item_node) && $item_node->nid == $parent_section_id) {
$space_menu->content[$mlid]['#attributes']['class'][] = 'active';
}
}
}
}
if (!empty($space_menu->content)) {
foreach ($space_menu->content as $key => $value) {
if (!empty($value['#original_link']['menu_name'])) {
$space_menu->content[$key]['#original_link']['menu_name'] = 'oa-space-menu';
}
}
}
$vars['menu'] = !empty($space_menu->content) ? $space_menu->content : '';
if (!$show_space_banner && variable_get('oa_space_menu_home_' . $space_id, TRUE) && !empty($space_menu->content) && $space_id) {
$title = t('Space home');
$field = field_get_items('node', $space, 'field_oa_space_type');
if (!empty($field[0]['tid'])) {
$space_type = $field[0]['tid'];
$term = taxonomy_term_load($space_type);
$title = $term->name != 'Default' ? $term->name . ' ' . t('home') : $title;
}
$class = $node == $space ? 'active' : '';
$home_link = array(
'#theme' => 'menu_link__oa_navigation',
'#title' => '<i class="fa fa-home"></i>' . $title,
'#href' => 'node/' . $space_id,
'#localized_options' => array(
'html' => true,
),
'#below' => array(),
'#attributes' => array(
'class' => array(
$class,
),
),
);
array_unshift($vars['menu'], $home_link);
}
$block = new stdClass();
$block->module = 'oa_toolbar';
$block->content = theme('oa_space_menu', $vars);
return $block;
}
function oa_toolbar_oa_space_menu_content_type_edit_form($form, &$form_state) {
return $form;
}