1 block_example.module block_example_block_view($delta = '', $settings = array(), $contexts = array())

Implements hook_block_view().

This hook generates the contents of the blocks themselves.

Related topics

File

modules/examples/block_example/block_example.module, line 151
Hook implementations for the Block Example module.

Code

function block_example_block_view($delta = '', $settings = array(), $contexts = array()) {
  // The $delta parameter tells us which block is being requested.
  switch ($delta) {
    case 'example_configurable_text':
      // The subject is displayed at the top of the block. Note that it
      // should be passed through t() for translation. The title configured
      // for the block using Backdrop UI supersedes this one.
      $block['subject'] = t('Title of first block (example_configurable_text)');
      // The content of the block is typically generated by calling a custom
      // function.
      $block['content'] = block_example_contents($settings);
      break;

    case 'example_uppercase':
      $block['subject'] = t("uppercase this please");
      $block['content'] = t("This block's title will be changed to uppercase. Any other block with 'uppercase' in the subject or title will also be altered. If you change this block's title through the UI to omit the word 'uppercase', it will still be altered to uppercase as the subject key has not been changed.");
      break;

    case 'example_node_context':
      // Pull out the contextual information (a node in this case) from the
      // contexts array.
      $node = $contexts['node'];
      $author = user_load($node->uid);
      $block['subject'] = t('Block with node context');
      $block['content'] = t('The title of the node on this page is "@title" and was created by !author.', array('@title' => $node->title, '!author' => theme('username', array('account' => $author))));
  }
  return $block;
}