Block

Export all user mail addresses to CSV



/**
 * Implements hook_menu().
 */
function export_mails_menu() {
  return array(
    'export_mails.csv' => array(
      'page callback' => '_export_mails',
      'access callback' => 'user_is_logged_in',
    ),
  );
}

/**
 * Implements hook_block_info().
 */
function export_mails_block_info() {

  $blocks['export_mails'] = array(
    'info' => t('Export mails'),
  );

  return $blocks;

}

/**
 * Implements hook_block_view().
 */
function export_mails_block_view($delta) {
  switch ($delta) {
    case 'export_mails' :
      return array(

Create a block

Basically all we need is hook_block_info() and hook_block_view() to create a block. 
By using hook_block_info() we declare which blocks are avaialable in our module. As seen on admin/structure/block. 
Hook_block_view() handles the rendering part of the block.

Create a lightweight commerce cart block

We build a custom block and use hook_theme to render the cart data. Usually a view is made to create a custom shopping cart block. However, a custom block to render number of items and the total price of an order is more exciting to make and more performant than a view.

Create a block with a form


/**
 * Implements hook_block_info().
 */
function MY_CUSTOM_MODULE_block_info() {
   
  $blocks['MY_CUSTOM_BLOCK'] = array(
    'info' => t('My custom block title as shown on admin/structure/block'),
  );

  return $blocks;

}

/**
 * Implements hook_block_view().
 */
function MY_CUSTOM_MODULE_block_view($delta) {

  switch ($delta) {
    case 'MY_CUSTOM_BLOCK' :
      return array(
      'subject' => t('MY_CUSTOM_BLOCK title.'),
      'content' => drupal_get_form('MY_CUSTOM_FORM'),
      );
      break;
  }
   
}

/**
 * Implements hook_form().
 */
Subscribe to RSS - Block