diff --git a/sites/all/modules/unl_blocks/unl_blocks.info b/sites/all/modules/unl_blocks/unl_blocks.info new file mode 100644 index 0000000000000000000000000000000000000000..d7811655cc25e36353d2dd91de9dc8fdba816253 --- /dev/null +++ b/sites/all/modules/unl_blocks/unl_blocks.info @@ -0,0 +1,6 @@ +; $Id$ +name = UNL blocks +description = Adds blocks needed by the UNL WDN template. +core = 7.x +dependencies[] = unl +files[] = unl_blocks.module diff --git a/sites/all/modules/unl_blocks/unl_blocks.module b/sites/all/modules/unl_blocks/unl_blocks.module new file mode 100644 index 0000000000000000000000000000000000000000..20a156e79ba2b3694f27ee513ee1ad93094d22fa --- /dev/null +++ b/sites/all/modules/unl_blocks/unl_blocks.module @@ -0,0 +1,196 @@ +<?php +// $Id$ + +/** + * @file + * This is an example outlining how a module can define blocks that can be + * displayed on various pages of a site, or how to alter blocks provided by + * other modules. + */ + +/** + * Implements hook_block_info(). + * + * This hook declares to Drupal what blocks are provided by the module. + */ +function unl_blocks_block_info() { + // This hook returns an array, each component of which is an array of block + // information. The array keys are the 'delta' values used in other block + // hooks. + + // The required block information is a block description, which is shown + // to the site administrator in the list of possible blocks. You can also + // provide initial settings for block weight, status, etc. + + // This sample only provides a description string. + $blocks['leftcollinks'] = array( + 'info' => t('Related Links'), + 'status' => TRUE, + 'region' => 'leftcollinks', + 'weight' => 0, + 'visibility' => 1, + 'cache' => DRUPAL_CACHE_GLOBAL, + ); + + // This sample shows how to provide default settings. In this case we'll + // enable the block in the first sidebar and make it visible only on + // 'node/*' pages. + $blocks['contactinfo'] = array( + 'info' => t('Contact Info'), + 'status' => TRUE, + 'region' => 'contactinfo', + 'weight' => 0, + 'visibility' => 1, + 'cache' => DRUPAL_CACHE_GLOBAL, + ); + + return $blocks; +} + +/** + * Implements hook_block_configure(). + * + * This hook declares configuration options for blocks provided by this module. + */ +function unl_blocks_block_configure($delta = '') { + // The $delta parameter tells us which block is being configured. + // In this example, we'll allow the administrator to customize + // the text of the 'configurable text string' block defined in this module. + + $form = array(); + if ($delta == 'leftcollinks') { + // All we need to provide is the specific configuration options for our + // block. Drupal will take care of the standard block configuration options + // (block title, page visibility, etc.) and the save button. + $form['unl_blocks_leftcollinks'] = array( + '#type' => 'textarea', + '#title' => t('Block contents'), + '#size' => 60, + '#description' => t('For more info see http://www1.unl.edu/wdn/wiki/Related_Links'), + '#default_value' => variable_get('unl_blocks_leftcollinks', t('<ul><li><a href="http://wdn.unl.edu/">WDN</a></li></ul>')), + ); + } + return $form; +} + +/** + * Implements hook_block_save(). + * + * This hook declares how the configured options for a block + * provided by this module are saved. + */ +function unl_blocks_block_save($delta = '', $edit = array()) { + // We need to save settings from the configuration form. + // We need to check $delta to make sure we are saving the right block. + if ($delta == 'leftcollinks') { + // Have Drupal save the string to the database. + variable_set('unl_blocks_leftcollinks', $edit['unl_blocks_leftcollinks']); + } + return; +} + +/** + * Implements hook_block_view(). + * + * This hook generates the contents of the blocks themselves. + */ +function unl_blocks_block_view($delta = '') { + //The $delta parameter tells us which block is being requested. + switch ($delta) { + case 'leftcollinks': + // 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 Drupal UI superseeds this one. + $block['subject'] = t('Title of first block (leftcollinks)'); + // The content of the block is typically generated by calling a custom + // function. + $block['content'] = unl_blocks_contents($delta); + break; + case 'example_empty': + $block['subject'] = t('Title of second block (example_empty)'); + $block['content'] = unl_blocks_contents($delta); + break; + } + return $block; +} + +/** + * A module-defined block content function. + */ +function unl_blocks_contents($which_block) { + switch ($which_block) { + case 'leftcollinks': + // 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. + return variable_get('unl_blocks_leftcollinks'); + + 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; + } +} + +/* + * The following hooks can be used to alter blocks + * provided by your own or other modules. + */ + +/** + * Implements hook_block_list_alter(). + * + * This hook allows you to add, remove or modify blocks in the block list. The + * block list contains the block definitions. This example requires + * search module and the search block enabled + * to see how this hook implementation works. + * + * You may also be interested in hook_block_info_alter(), which allows changes + * to the behavior of blocks. + */ +function unl_blocks_block_list_alter(&$blocks) { + // We are going to make the search block sticky on bottom of regions. For + // this example, we will modify the block list and append the search block at + // the end of the list, so even if the administrator configures the block to + // be on the top of the region, it will demote to bottom again. + foreach ($blocks as $bid => $block) { + if (($block->module == 'search') && ($block->delta == 'form')) { + // Remove the block from the list and append to the end. + unset($blocks[$bid]); + $blocks[$bid] = $block; + break; + } + } +} + +/** + * 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. + * + * We are going to uppercase the title of any block if the string "magic string" + * is encountered in the content. If we were changing only our block using + * hook_block_view_MODULE_DELTA_alter to do this, we would have used the + * function: + * unl_blocks_block_view_unl_blocks_leftcollinks_alter() + * + * To demonstrate the effect of this hook, you can use the + * 'configurable_text_string' block created by this module and add the + * text 'magic string' into the configuration. + */ +function unl_blocks_block_view_alter(&$data, $block) { + // Verify the we have raw text content + if (!isset($data['content']) || !is_string($data['content'])) { + return; + } + + // If the content contains the string: 'magic string', uppercase the title. + if (strstr($data['content'], 'magic string')) { + $data['subject'] = isset($data['subject']) ? drupal_strtoupper($data['subject']) : ''; + } +}