Skip to content

Instantly share code, notes, and snippets.

@DuaelFr
Last active December 21, 2015 10:19
Show Gist options
  • Save DuaelFr/6291504 to your computer and use it in GitHub Desktop.
Save DuaelFr/6291504 to your computer and use it in GitHub Desktop.
Static block example in Drupal 7
<a href="<?php echo $link_url; ?>" class="<?php echo $link_class; ?>"><?php echo $link_title; ?></a>
name = My Module
core = 7.x
<?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