Skip to content
Snippets Groups Projects
Commit e5aaf31f authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

update to unl_blocks to include leftcollinks, optionalfooter, footercontent, contactinfo

git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x@125 20a16fea-79d4-4915-8869-1ea9d5ebf173
parent ac64b6f2
No related branches found
No related tags found
No related merge requests found
......@@ -3,9 +3,7 @@
/**
* @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.
* Adds blocks for editable regions of the UNL template.
*/
/**
......@@ -17,12 +15,11 @@ 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,
......@@ -31,10 +28,6 @@ function unl_blocks_block_info() {
'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,
......@@ -43,6 +36,22 @@ function unl_blocks_block_info() {
'visibility' => 1,
'cache' => DRUPAL_CACHE_GLOBAL,
);
$blocks['optionalfooter'] = array(
'info' => t('Optional Footer'),
'status' => TRUE,
'region' => 'optionalfooter',
'weight' => 0,
'visibility' => 1,
'cache' => DRUPAL_CACHE_GLOBAL,
);
$blocks['footercontent'] = array(
'info' => t('Footer Content'),
'status' => TRUE,
'region' => 'footercontent',
'weight' => 0,
'visibility' => 1,
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
......@@ -67,9 +76,37 @@ function unl_blocks_block_configure($delta = '') {
'#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>')),
'#default_value' => variable_get('unl_blocks_leftcollinks', t('<ul><li><a href="http://wdn.unl.edu/">Web Developer Network</a></li></ul>')),
);
}
if ($delta == 'contactinfo') {
$form['unl_blocks_contactinfo'] = array(
'#type' => 'textarea',
'#title' => t('Block contents'),
'#size' => 60,
'#description' => t('For more info see http://www1.unl.edu/wdn/wiki/Contact_Info'),
'#default_value' => variable_get('unl_blocks_contactinfo'),
);
}
if ($delta == 'optionalfooter') {
$form['unl_blocks_optionalfooter'] = array(
'#type' => 'textarea',
'#title' => t('Block contents'),
'#size' => 60,
'#description' => t('Not currently used'),
'#default_value' => variable_get('unl_blocks_optionalfooter'),
);
}
if ($delta == 'footercontent') {
$form['unl_blocks_footercontent'] = array(
'#type' => 'textarea',
'#title' => t('Block contents'),
'#size' => 60,
'#description' => t('Leave this blank to get the standard/default UNL copyright line. For more info see http://www1.unl.edu/wdn/wiki/Base_Footer'),
'#default_value' => variable_get('unl_blocks_footercontent'),
);
}
return $form;
}
......@@ -86,6 +123,16 @@ function unl_blocks_block_save($delta = '', $edit = array()) {
// Have Drupal save the string to the database.
variable_set('unl_blocks_leftcollinks', $edit['unl_blocks_leftcollinks']);
}
if ($delta == 'contactinfo') {
variable_set('unl_blocks_contactinfo', $edit['unl_blocks_contactinfo']);
}
if ($delta == 'optionalfooter') {
variable_set('unl_blocks_optionalfooter', $edit['unl_blocks_optionalfooter']);
}
if ($delta == 'footercontent') {
variable_set('unl_blocks_footercontent', $edit['unl_blocks_footercontent']);
}
return;
}
......@@ -95,19 +142,26 @@ function unl_blocks_block_save($delta = '', $edit = array()) {
* This hook generates the contents of the blocks themselves.
*/
function unl_blocks_block_view($delta = '') {
$block = array();
//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)');
$block['subject'] = t('Related Links');
// 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)');
case 'contactinfo':
$block['subject'] = t('Contacting Us');
$block['content'] = unl_blocks_contents($delta);
break;
case 'optionalfooter':
$block['content'] = unl_blocks_contents($delta);
break;
case 'footercontent':
$block['content'] = unl_blocks_contents($delta);
break;
}
......@@ -124,73 +178,11 @@ function unl_blocks_contents($which_block) {
// 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']) : '';
case 'contactinfo':
return variable_get('unl_blocks_contactinfo');
case 'optionalfooter':
return variable_get('unl_blocks_optionalfooter');
case 'footercontent':
return variable_get('unl_blocks_footercontent');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment