function example_block in Coder 7
Same name and namespace in other branches
- 7.2 coder_upgrade/tests/old/samples/example.module \example_block()
Implementation of hook_block().
http://drupal.org/node/224333#remove_op
File
- coder_upgrade/
tests/ old/ samples/ example.module, line 650
Code
function example_block($op, $delta, $edit) {
if ($op == 'configure') {
// Configuration form for the block.
if ($delta == 'exciting') {
$form['items'] = array(
'#type' => 'select',
'#title' => t('Number of items'),
'#default_value' => variable_get('mymodule_block_items', 0),
'#options' => array(
'1',
'2',
'3',
),
);
return $form;
}
}
elseif ($op == 'list') {
// A list of all blocks defined by the module.
$blocks['exciting'] = array(
'info' => t('An exciting block provided by Mymodule.'),
'weight' => 0,
'status' => 1,
'region' => 'sidebar_first',
);
$blocks['amazing'] = array(
'info' => t('An amazing block provided by Mymodule.'),
'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE,
);
return $blocks;
}
elseif ($op == 'save') {
// Save the configuration options.
if ($delta == 'exciting') {
variable_set('mymodule_block_items', $edit['items']);
}
}
elseif ($op == 'view') {
// Process the block when enabled in a region in order to view its contents.
switch ($delta) {
case 'exciting':
$block = array(
'subject' => t('Default title of the exciting block'),
'content' => mymodule_display_block_exciting(),
);
break;
case 'amazing':
$block = array(
'subject' => t('Default title of the amazing block'),
'content' => mymodule_display_block_amazing(),
);
break;
}
return $block;
}
switch ($op) {
case 'configure':
// Configuration form for the block.
if ($delta == 'exciting') {
$form['items'] = array(
'#type' => 'select',
'#title' => t('Number of items'),
'#default_value' => variable_get('mymodule_block_items', 0),
'#options' => array(
'1',
'2',
'3',
),
);
return $form;
}
break;
case 'list':
// A list of all blocks defined by the module.
$blocks['exciting'] = array(
'info' => t('An exciting block provided by Mymodule.'),
'weight' => 0,
'status' => 1,
'region' => 'sidebar_first',
);
$blocks['amazing'] = array(
'info' => t('An amazing block provided by Mymodule.'),
'cache' => DRUPAL_CACHE_PER_ROLE | DRUPAL_CACHE_PER_PAGE,
);
return $blocks;
break;
case 'save':
// Save the configuration options.
if ($delta == 'exciting') {
variable_set('mymodule_block_items', $edit['items']);
}
break;
case 'view':
// Process the block when enabled in a region in order to view its contents.
switch ($delta) {
case 'exciting':
$block = array(
'subject' => t('Default title of the exciting block'),
'content' => mymodule_display_block_exciting(),
);
break;
case 'amazing':
$block = array(
'subject' => t('Default title of the amazing block'),
'content' => mymodule_display_block_amazing(),
);
break;
}
return $block;
break;
}
foreach (array(
'configure',
'list',
'view',
) as $op) {
// Do something.
}
}