Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By marknewlyn on
Hi
I didn't really want to post to the core forum but I am 99% sure that Drupal isn't doing what its supposed to. I modified block_example by
removing all the comments and adding a call to _user. I tried to add something to $user so I can use it later. The wording in the API leads me to believe this is possible. I try to display the thing I add in the block but it doesn't show up. All the code is here:
<?php
function block_example_help($section) {
switch ($section) {
case 'admin/modules#description':
// This description is shown in the listing at admin/modules.
return t('An example module showing how to define a block.');
}
}
function block_example_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Example: configurable text string');
$blocks[1]['info'] = t('Example: empty block');
return $blocks;
case 'configure':
$form = array();
if ($delta == 0) {
$form['block_example_string'] = array(
'#type' => 'textfield',
'#title' => t('Block contents'),
'#size' => 60,
'#description' => t('This string will appear in the example block.'),
'#default_value' =>
variable_get('block_example_string', t('Some example content.')),
);
}
return $form;
case 'save':
if ($delta == 0) {
variable_set('block_example_string', $edit['block_example_string']);
}
return;
case 'view': default:
switch ($delta) {
case 0:
$block['subject'] = t('Title of block #1');
$block['content'] = block_example_contents(1);
break;
case 1:
$block['subject'] = t('Title of block #2');
$block['content'] = block_example_contents(2);
break;
}
return $block;
}
}
function block_example_contents($which_block) {
global $user;
if ($which_block == 1) {
$output = variable_get('block_example_string', t('A default value.'));
$output .="<br />user name is : $user->name";
$output .="<br />user special string is : $user->specialstring";
return $output;
}
if ($which_block == 2) {
return;
}
}
function block_example_user($op, &$edit, &$user, $category = NULL) {
switch ($op) {
case 'load':
$user->specialstring = "Hello World";
break;
}
}
?>
Is this a bug or a misunderstanding on my part?
Any advice or pointers would be greatly appreciated!
Thanks,
Mark