Skip to content

Instantly share code, notes, and snippets.

@driesd
Created October 7, 2013 07:38
Show Gist options
  • Save driesd/6863900 to your computer and use it in GitHub Desktop.
Save driesd/6863900 to your computer and use it in GitHub Desktop.
Provides a custom 'Back to overview' button - Block
<?php
/**
* Implementation of hook_block_info().
*/
function custom_block_back_to_overview_block_info() {
$blocks = array();
$blocks['back-to-overview'] = array(
'info' => t('CB - Back to overview'),
);
return $blocks;
}
/**
* Implementation of hook_block_view().
*/
function custom_block_back_to_overview_block_view($delta='') {
$block = array();
global $language;
switch ($delta) {
case 'back-to-overview':
// get url
$path = array_filter(explode('/', $_SERVER['REQUEST_URI']));
// remove the last item (news detail)
array_pop($path);
// if language is fr remove the first item
if($language->language != 'nl') {
array_shift($path);
}
// get source url
$source = implode('/', $path);
// get the node id for the url
$nodeid = drupal_lookup_path('source', urldecode($source), $language->language);
// make link
$content = l(t('Back to overview'), $nodeid, array('attributes' => array('title' => t('Back to overview'))));
// assign block content
$block['content'] = $content;
break;
}
return $block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment