Instantly share code, notes, and snippets.
Created
September 9, 2013 07:20
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save vdchristelle/6492411 to your computer and use it in GitHub Desktop.
Menu items with images (menu blocks)
This file contains 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
$view = new view(); | |
$view->name = 'navigation'; | |
$view->description = ''; | |
$view->tag = 'default'; | |
$view->base_table = 'node'; | |
$view->human_name = 'Navigation'; | |
$view->core = 7; | |
$view->api_version = '3.0'; | |
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ | |
/* Display: Master */ | |
$handler = $view->new_display('default', 'Master', 'default'); | |
$handler->display->display_options['title'] = 'Navigation subpages'; | |
$handler->display->display_options['use_more_always'] = FALSE; | |
$handler->display->display_options['use_more_text'] = 'meer'; | |
$handler->display->display_options['access']['type'] = 'perm'; | |
$handler->display->display_options['cache']['type'] = 'none'; | |
$handler->display->display_options['query']['type'] = 'views_query'; | |
$handler->display->display_options['exposed_form']['type'] = 'basic'; | |
$handler->display->display_options['exposed_form']['options']['submit_button'] = 'Toepassen'; | |
$handler->display->display_options['exposed_form']['options']['reset_button_label'] = 'Opnieuw instellen'; | |
$handler->display->display_options['exposed_form']['options']['exposed_sorts_label'] = 'Sorteren op'; | |
$handler->display->display_options['exposed_form']['options']['sort_asc_label'] = 'Oplopend'; | |
$handler->display->display_options['exposed_form']['options']['sort_desc_label'] = 'Aflopend'; | |
$handler->display->display_options['pager']['type'] = 'none'; | |
$handler->display->display_options['style_plugin'] = 'list'; | |
$handler->display->display_options['style_options']['class'] = 'grid-2 list counter'; | |
$handler->display->display_options['style_options']['wrapper_class'] = 'subpages'; | |
$handler->display->display_options['row_plugin'] = 'node'; | |
$handler->display->display_options['row_options']['view_mode'] = 'navigation_item'; | |
$handler->display->display_options['row_options']['links'] = FALSE; | |
/* Veld: Inhoud: Titel */ | |
$handler->display->display_options['fields']['title']['id'] = 'title'; | |
$handler->display->display_options['fields']['title']['table'] = 'node'; | |
$handler->display->display_options['fields']['title']['field'] = 'title'; | |
$handler->display->display_options['fields']['title']['label'] = ''; | |
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE; | |
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE; | |
/* Contextueel filter: Inhoud: Nid */ | |
$handler->display->display_options['arguments']['nid']['id'] = 'nid'; | |
$handler->display->display_options['arguments']['nid']['table'] = 'node'; | |
$handler->display->display_options['arguments']['nid']['field'] = 'nid'; | |
$handler->display->display_options['arguments']['nid']['default_action'] = 'default'; | |
$handler->display->display_options['arguments']['nid']['exception']['title'] = 'Alle'; | |
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node'; | |
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0'; | |
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary'; | |
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25'; | |
$handler->display->display_options['arguments']['nid']['specify_validation'] = TRUE; | |
$handler->display->display_options['arguments']['nid']['break_phrase'] = TRUE; | |
/* Filtercriterium: Inhoud: Gepubliceerd */ | |
$handler->display->display_options['filters']['status']['id'] = 'status'; | |
$handler->display->display_options['filters']['status']['table'] = 'node'; | |
$handler->display->display_options['filters']['status']['field'] = 'status'; | |
$handler->display->display_options['filters']['status']['value'] = 1; | |
$handler->display->display_options['filters']['status']['group'] = 1; | |
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE; | |
/* Filtercriterium: Inhoud: Type */ | |
$handler->display->display_options['filters']['type']['id'] = 'type'; | |
$handler->display->display_options['filters']['type']['table'] = 'node'; | |
$handler->display->display_options['filters']['type']['field'] = 'type'; | |
$handler->display->display_options['filters']['type']['value'] = array( | |
'page' => 'page', | |
'detailpagina_dienst' => 'detailpagina_dienst', | |
); | |
/* Display: Navigation subitems */ | |
$handler = $view->new_display('block', 'Navigation subitems', 'navigation_subitems'); | |
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE; | |
$handler->display->display_options['defaults']['sorts'] = FALSE; | |
$handler->display->display_options['block_description'] = 'View - Navigation subitems'; | |
$translatables['navigation'] = array( | |
t('Master'), | |
t('Navigation subpages'), | |
t('meer'), | |
t('Toepassen'), | |
t('Opnieuw instellen'), | |
t('Sorteren op'), | |
t('Oplopend'), | |
t('Aflopend'), | |
t('Alle'), | |
t('Navigation subitems'), | |
t('View - Navigation subitems'), | |
); |
This file contains 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 | |
/* | |
* Menu block with images example | |
* Array of node id's will be passed on to a view that outputs the html ul | |
* | |
*** Drupal to do: | |
* Create DS display 'Navigation item' (fields: title & image) | |
* Import view | |
* Add this code to your template.php of the active theme | |
* | |
*** Adjust code below: | |
* Customize the region too | |
* Check your block's id and change the cdelta values as needed | |
* Adjust the view where you pass onto the array of id's | |
*/ | |
/* | |
* Implements template_preprocess_block | |
* Needed modules: views, menu block | |
*/ | |
function the_aim_theme_preprocess_block(&$variables) { | |
// add boolean to remove outer wrapper | |
if (in_array('no-wrapper', $variables['classes_array'])) { | |
$variables['no_wrapper'] = TRUE; | |
} | |
//preprocess the output of the menu block | |
if($variables['elements']['#block']->module == 'menu_block' && $variables['elements']['#block']->region == 'content_under'){ | |
// theme subpage block - check the bid | |
if( isset($variables['elements']['#config']['delta']) ) { | |
//only for specific block id's | |
if ($variables['elements']['#config']['delta'] == 3 || $variables['elements']['#config']['delta'] == 4 ) { | |
$arrayofnodes = array(); | |
foreach($variables['elements']['#content'] as $key => $menuitem) { | |
if(is_numeric($key)) { | |
//get node id from href menuitem | |
$node = explode("/", $menuitem['#href']); | |
//add to array | |
$arrayofnodes[] = $node[1]; | |
} | |
} | |
//convert array to comma separated string | |
$arrayofnodes = implode(",", $arrayofnodes); | |
//pass the string of node id's to the view and embed it in the block content | |
$blockcontent = views_embed_view('navigation', 'navigation_subitems', $arrayofnodes); | |
$variables['content'] = $blockcontent; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment