You are here

function block_example_contents in Examples for Developers 7

Same name and namespace in other branches
  1. 6 block_example/block_example.module \block_example_contents()

A module-defined block content function.

Related topics

1 call to block_example_contents()
block_example_block_view in block_example/block_example.module
Implements hook_block_view().

File

block_example/block_example.module, line 160
Module file for block_example.

Code

function block_example_contents($which_block) {
  switch ($which_block) {
    case 'example_configurable_text':

      // Modules would typically perform some database queries to fetch the
      // content for their blocks. Here, we'll just use the variable set in the
      // block configuration or, if none has set, a default value.
      // Block content can be returned in two formats: renderable arrays
      // (as here) are preferred though a simple string will work as well.
      // Block content created through the UI defaults to a string.
      $result = array(
        '#markup' => variable_get('block_example_string', t('A default value. This block was created at %time', array(
          '%time' => date('c'),
        ))),
      );
      return $result;
    case 'example_empty':

      // It is possible that a block not have any content, since it is
      // probably dynamically constructed. In this case, Drupal will not display
      // the block at all. This block will not be displayed.
      return;
  }
}