Skip to content

Instantly share code, notes, and snippets.

@jonhattan
Created April 30, 2014 10:54
Show Gist options
  • Save jonhattan/c6a5e3d187f5e96df03d to your computer and use it in GitHub Desktop.
Save jonhattan/c6a5e3d187f5e96df03d to your computer and use it in GitHub Desktop.
Example of a block with custom theme.
<?php
/**
* Implements hook_theme().
*/
function EXAMPLE_theme() {
$path = drupal_get_path('module', 'EXAMPLE');
$hooks = array(
'iu_license' => array(
'template' => 'iu-license',
'path' => $path,
'variables' => array(
'copyright' => NULL,
'license_text' => NULL,
'license_link' => NULL,
'license_image' => NULL
),
),
);
return $hooks;
}
/**
* Implements hook_block_info().
*/
function EXAMPLE_block_info() {
$blocks['copyright'] = array(
'info' => t('Copyright'),
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function EXAMPLE_block_view($delta) {
$block = array();
switch ($delta) {
case 'copyright':
$block['content'] = array(
'#theme' => 'iu_license',
'#copyright' => variable_get('site_name') . ' - ' . date('Y'),
'#license_text' => 'licencia de Creative Commons Reconocimiento-NoComercial-CompartirIgual 4.0 Internacional',
'#license_link' => 'http://creativecommons.org/licenses/by-nc-sa/4.0/deed.es_ES',
'#license_image' => 'http://i.creativecommons.org/l/by-nc-sa/4.0/es/88x31.png',
);
break;
}
return $block;
}
<div class="copyright"><?php print $copyright; ?></div>
<div class="license">
<?php
$options = array('attributes' => array('rel' => 'license'));
$image = theme('image', array(
'path' => $license_image,
'alt' => 'Licencia de Creative Commons',
)
);
print l($image, $license_link, $options + array('html' => TRUE));
?>
<br/>
<?php print 'Esta obra está bajo una ' . l($license_text, $license_link, $options); ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment