- <?php
- * @file
- * Hook implementations for the Block Example module.
- */
-
- * @defgroup block_example Example: Block
- * @ingroup examples
- * @{
- * This example demonstrates how blocks are created.
- *
- * This is an example outlining how a module can define blocks that can be
- * displayed on various pages and how modules can alter blocks provided by a
- * module.
- */
-
- * Implements hook_menu().
- *
- * Provides a default page to explain what this module does.
- */
- function block_example_menu() {
- $items['examples/block_example'] = array(
- 'page callback' => 'block_example_page',
- 'access callback' => TRUE,
- 'title' => 'Block Example',
- );
- return $items;
- }
-
- * Simple page function to explain what the block example is about.
- */
- function block_example_page() {
- $page = array(
- '#type' => 'markup',
- '#markup' => t('The Block Example provides three sample blocks which demonstrate the various block APIs. To experiment with the blocks, enable and configure them on <a href="@url">the layout admin page</a>.', array('@url' => url('/admin/structure/layouts/'))),
- );
- return $page;
- }
- * Implements hook_block_info().
- *
- * This hook declares what blocks are provided by the module.
- */
- function block_example_block_info() {
-
-
-
-
-
-
-
-
-
- $blocks['example_configurable_text'] = array(
-
- 'info' => t('Example: configurable text string'),
- 'description' => 'This block is configurable.',
- );
-
-
-
-
- $blocks['example_subclass'] = array(
- 'info' => t('Example: subclass block'),
- 'description' => 'This block is defined by extending Block class.',
- 'class' => 'BlockExample',
- );
-
- $blocks['example_uppercase'] = array(
-
- 'info' => t('Example: uppercase this please'),
- 'description' => 'This block\'s title will be uppercase.',
- );
-
-
-
-
-
- $blocks['example_node_context'] = array(
- 'info' => t('Example: Node Context'),
- 'description' => t('This block is only available when a node context is available. It will pull out information about the node and display it in the block.'),
-
-
-
- 'required contexts' => array('node' => 'node'),
- );
-
- return $blocks;
- }
-
- * Implements hook_block_configure().
- *
- * This hook declares configuration options for blocks provided by this module.
- */
- function block_example_block_configure($delta = '', $settings = array()) {
- $form = array();
-
-
-
- if ($delta == 'example_configurable_text') {
-
- $settings += array(
- 'example_string' => '',
- 'uppercase' => '',
- );
-
-
-
- $form['example_string'] = array(
- '#type' => 'textfield',
- '#title' => t('Block contents'),
- '#size' => 60,
- '#description' => t('This text will appear in the example block.'),
- '#default_value' => $settings['example_string'],
- );
- $form['uppercase'] = array(
- '#type' => 'checkbox',
- '#title' => t('Uppercase the block contents'),
- '#default_value' => $settings['uppercase'],
- );
- }
-
- return $form;
- }
-
- * Implements hook_block_save().
- *
- * This hook declares how the configured options for a block provided by this
- * module are saved. This hook is optional if we do not wish to modify the
- * way values are saved. Values are saved into the layout configuration file
- * that contains this block.
- */
- function block_example_block_save($delta = '', &$edit = array()) {
-
- if ($delta == 'example_configurable_text') {
-
- $edit['uppercase'] = (bool) $edit['uppercase'];
- }
- }
-
- * Implements hook_block_view().
- *
- * This hook generates the contents of the blocks themselves.
- */
- function block_example_block_view($delta = '', $settings = array(), $contexts = array()) {
-
- switch ($delta) {
- case 'example_configurable_text':
-
-
-
- $block['subject'] = t('Title of first block (example_configurable_text)');
-
-
- $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':
-
-
- $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;
- }
-
- * A module-defined block content function.
- */
- function block_example_contents($settings) {
-
-
-
-
-
-
- $string = $settings['example_string'];
- if ($settings['uppercase']) {
- $string = backdrop_strtoupper($string);
- }
- $result = array(
- '#markup' => check_plain($string),
- );
- return $result;
- }
-
-
- * Implements hook_block_view_alter().
- *
- * This hook allows you to modify the output of any block in the system.
- *
- * In addition, instead of hook_block_view_alter(), which is called for all
- * blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a
- * specific block. To change only our block using
- * hook_block_view_MODULE_DELTA_alter, we would use the function:
- * block_example_block_view_block_example_example_configurable_text_alter()
- *
- * We are going to uppercase the subject (the title of the block as shown to the
- * user) of any block if the string "uppercase" appears in the block title or
- * subject. Default block titles are set programmatically in the subject key;
- * titles created through the UI are saved in the title key. This module creates
- * an example block to demonstrate this effect (default title set
- * programmatically as subject). You can also demonstrate the effect of this
- * hook by creating a new block whose title has the string 'uppercase' in it
- * (set as title through the UI).
- */
- function block_example_block_view_alter(&$data, $block) {
-
- if ((!empty($block->title) && stristr($block->title, 'uppercase')) || (!empty($data['subject']) && stristr($data['subject'], 'uppercase'))) {
-
- $data['subject'] = isset($data['subject']) ? backdrop_strtoupper($data['subject']) : '';
-
- $block->title = isset($block->title) ? backdrop_strtoupper($block->title) : '';
- }
- }
-
- * Implements hook_autoload_info().
- */
- function block_example_autoload_info() {
- return array(
- 'BlockExample' => 'block_example.inc',
- );
- }
-
- * @} End of "defgroup block_example".
- */