Last active
December 21, 2015 10:19
-
-
Save DuaelFr/6291504 to your computer and use it in GitHub Desktop.
Static block example in Drupal 7
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
<a href="<?php echo $link_url; ?>" class="<?php echo $link_class; ?>"><?php echo $link_title; ?></a> |
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
name = My Module | |
core = 7.x |
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 | |
* My module main file. | |
*/ | |
/** | |
* Implements hook_block_info(). | |
*/ | |
function mymodule_block_info() { | |
$blocks = array(); | |
$blocks['tip_denounce'] = array( | |
'info' => 'ISE Tip "Pourquoi dénoncer vos contacts ?"', | |
'cache' => DRUPAL_CACHE_GLOBAL, | |
); | |
return $blocks; | |
} | |
/** | |
* Implements hook_block_view(). | |
*/ | |
function mymodule_block_view($delta = '') { | |
$block = array( | |
'subject' => NULL, | |
'content' => array( | |
'#prefix' => '<div class="block-content">', | |
'#markup' => '', | |
'#suffix' => '</div>', | |
), | |
); | |
switch ($delta) { | |
case 'tip_denounce': | |
$block['content']['#markup'] = theme('mymodule_tip', array( | |
'link_url' => '/pourquoi-denoncer-vos-contacts', | |
'link_title' => '<h4>Vendez en sécurité</h4><p>Pourquoi dénoncer vos contacts ?</p>', | |
'link_class' => strtr($delta, '_', '-'), | |
)); | |
break; | |
default: | |
$block['content']['#markup'] = theme('mymodule_' . $delta); | |
break; | |
} | |
return $block; | |
} | |
/** | |
* Implements hook_theme(). | |
*/ | |
function mymodule_theme($existing, $type, $theme, $path) { | |
$themes = array(); | |
$base = array( | |
'variables' => array('img_path' => drupal_get_path('module', 'mymodule') . '/images'), | |
); | |
$themes['mymodule_tip'] = $base + array( | |
'template' => 'mymodule-tip', | |
'variables' => array('link_url' => '/', 'link_title' => 'Home', 'link_class' => 'tip-home'), | |
); | |
return $themes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment