Created
July 8, 2016 15:31
-
-
Save melissamcewen/a5011621ddf35819b5da0f7a02017a24 to your computer and use it in GitHub Desktop.
Custom Menu Pane
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$plugin = array( | |
'single' => TRUE, | |
'title' => t('Category Topic Pane'), | |
'description' => t('A Pane showing the current node\'s children under the main menu, their descriptions, and their children'), | |
'category' => t('Category Topic'), | |
'render callback' => 'category_topics_pane_custom_pane_render', | |
'admin info' => 'category_topics_pane_custom_pane_admin_info', | |
'hook theme' => 'category_topics', | |
); | |
/** | |
* Run-time rendering of the body of the block (content type) | |
* See ctools_plugin_examples for more advanced info | |
*/ | |
function category_topics_pane_custom_pane_render($subtype, $conf, $args, $contexts) { | |
$block = new stdClass(); | |
// initial content is blank | |
$block->content = array( | |
'#theme' => 'category_topics', | |
); | |
return $block; | |
} | |
/** | |
* Implements hook_theme(); | |
*/ | |
function category_topics_theme() { | |
$category_topics = array(); | |
$nodeid= ''; | |
//let's grab the node id | |
if (arg(0) == 'node' && is_numeric(arg(1))) $nodeid = arg(1); | |
// plug it into the menu system | |
$path = 'node/'. $nodeid; | |
$parent = menu_link_get_preferred($path, 'main-menu'); | |
//let's grab the first level | |
$parameters = array( | |
'active_trail' => array($parent['plid']), | |
'only_active_trail' => FALSE, | |
'min_depth' => $parent['depth']+1, | |
'max_depth' => $parent['depth']+1, | |
'conditions' => array('plid' => $parent['mlid']), | |
); | |
$children = menu_build_tree('main-menu', $parameters); | |
foreach ($children as $item) { | |
$second_level = array(); | |
//get the node ID | |
$node_path = explode('/', $item['link']['link_path']); | |
$nid = $node_path[1]; | |
$description = ''; | |
//get the description | |
$node_wrapper = entity_metadata_wrapper('node', $nid); | |
$description = $node_wrapper->field_short_desc->value(); | |
if($item['link']['has_children'] == 1) { | |
$child_path = 'node/'. $nid; | |
$child_parent = menu_link_get_preferred($child_path, 'main-menu'); | |
//let's grab the second level | |
$child_parameters = array( | |
'active_trail' => array($child_parent['plid']), | |
'only_active_trail' => FALSE, | |
'min_depth' => $child_parent['depth']+1, | |
'max_depth' => $child_parent['depth']+1, | |
'conditions' => array('plid' => $child_parent['mlid']), | |
); | |
$children_level_2 = menu_build_tree('main-menu', $child_parameters); | |
foreach ($children_level_2 as $child){ | |
array_push($second_level, array( | |
'name' => $child['link']['link_title'], | |
'menu_link' => $child['link']['link_path'], | |
)); | |
} | |
} | |
$second_level_number = count($second_level); | |
array_push($category_topics, array( | |
'name' => $item['link']['link_title'], | |
'menu_link' => $item['link']['link_path'], | |
'description' => $description, | |
'second-level-number' => $second_level_number, | |
'links' => $second_level, | |
)); | |
} | |
return array( | |
'category_topics' => array( | |
'template' => 'category-topics', | |
'path' => drupal_get_path('module', 'category_topics') . '/templates', | |
'variables' => array( | |
'category_topics' => $category_topics, | |
), | |
), | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file category-topics.tpl.php | |
* Custom Category Topics Pane | |
* | |
* Variables available: | |
* - $category_topics: an array of all menu items under the current node with a nested array of their menu items | |
*/ | |
?> | |
<div class="category-list"> | |
<?php foreach($category_topics as $category_topic): ?> | |
<div class="category-list__category category-list__category--layout "> | |
<div class="category-list__rule"> | |
</div> | |
<div class="category-list__category__title"> | |
<?php print l($category_topic['name'], $category_topic['menu_link'], array('attributes' => array('class' => 'category-list__title-link'))); ?> | |
</a> | |
</div> | |
<div class="category-list__description"> | |
<?php print t($category_topic['description']); ?> | |
<?php print l('Learn More', $category_topic['menu_link'], array('attributes' => array('class' => 'category-list__learn-more'))); ?> | |
</div> | |
<?php if ($category_topic['second-level-number'] > 0): ?> | |
<div class="category-list__links"> | |
<?php if ($category_topic['second-level-number'] < 5): ?> | |
<?php foreach($category_topic['links'] as $link): ?> | |
<?php print l($link['name'],$link['menu_link'], array('attributes' => array('class' => 'category-list__link')));?> | |
<?php endforeach; ?> | |
<?php else : ?> | |
<?php for ($i = 1; $i <= 3; $i++): ?> | |
<?php print l($category_topic['links'][$i]['name'],$category_topic['links'][$i]['menu_link'], array('attributes' => array('class' => 'category-list__link')));?> | |
<?php endfor; ?> | |
<?php print l('View All', $category_topic['menu_link'], array('attributes' => array('class' => 'category-list__link category-list__link--all'))); ?> | |
<?php endif; ?> <!--end if larger than 5 and else--> | |
</div> | |
<?php endif; ?> <!--end if category links exists--> | |
</div> | |
<?php endforeach; ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment