Created
September 18, 2013 07:01
-
-
Save fieke/6605506 to your computer and use it in GitHub Desktop.
Add back to overview block
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
/** | |
* Implementation of hook_block_info(). | |
*/ | |
function custom_block_info() { | |
$blocks = array(); | |
// back to overview | |
$blocks['back-to-overview'] = array( | |
'info' => t('Back to overview'), | |
); | |
return $blocks; | |
} | |
/** | |
* Implementation of hook_block_view(). | |
*/ | |
function custom_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', $source); | |
// 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