When I attempt to add a block reference field to node, I get hit with this notice:


# Notice: Undefined index: referenceable_modules in _blockreference_potential_references_standard() (line 434 of C:\WWW\smarsh\sites\all\modules\blockreference\blockreference.module).

# Notice: Undefined index: info in _blockreference_potential_references_standard() (line 471 of C:\WWW\smarsh\sites\all\modules\blockreference\blockreference.module).

This is in Drupal 7.. What I did was install the module, create some blocks, and then attempt to assign the field to a node.

After looking at it, probably just adding some "if !empty()" lines will fix..

I modified line 471 to be:

if(!empty($block_info[$block->delta]['info'])) {
			$block->info = $block_info[$block->delta]['info'];
		} else {
			$block->info = '';
		}

And line 434 to be:

if (!empty($field['referenceable_modules']) && is_array($field['referenceable_modules'])) {

Seems to have fixed. I have my PHP error reporting set to strict, that might have been a part of it.

This is a great idea for a module by the way - I was using node reference and thought "what I really need is a block reference", and what do you know - here it is!

Comments

wheelercreek’s picture

Sorry - the change to line 471 didn't quite work. I'm getting empty strings in my block drop down on the node edit.

I had to change it to be this:

if(!empty($block_info[$block->delta][$block->delta]['info'])) {
			$block->info = $block_info[$block->delta][$block->delta]['info'];
		} else {
			$block->info = '';
		}

After looking at the var_dump on the block_info, this was what I came up with. It's working for me..
Any idea why that would be the case?

danielb’s picture

I'll get those notices fixed up soon.

As for the double [$block->delta], I think the problem is with this:

    if (!isset($block_info[$block->delta])) {
      $block_info[$block->delta] = module_invoke($block->module, 'block_info');
    }

The result from module_invoke already has the [$block->delta] part.

It needs to be more like

    if (!isset($block_info[$block->module][$block->delta])) {
      $block_info[$block->module] = module_invoke($block->module, 'block_info');
    }

And then the rest of the code should be looking in $block_info[$block->module][$block->info]['info']
There's even one spot where the old variable $info is used by mistake :/

This might affect Drupal 6 too.

danielb’s picture

Status: Active » Fixed

I've made a new release with that change.

wheelercreek’s picture

Thanks daniel, I just updated - but now getting a line 106 notice?:

Notice: Undefined index: referenceable_modules in blockreference_field_settings_form() (line 106 of C:\WWW\smarsh\sites\all\modules\blockreference\blockreference.module).

wheelercreek’s picture

I modifed to that form element at line 106 to be this:

$refmodules = !empty($settings['referenceable_modules']) && is_array($settings['referenceable_modules']) 
			?	$settings['referenceable_modules']
      : array(); 	
	$form['referenceable_modules'] = array(
    '#type'          => 'checkboxes',
    '#title'         => t('Modules defining blocks that can be referenced'),
    '#multiple' => TRUE,
    '#default_value' => $refmodules,
    '#options'       => module_list(FALSE, TRUE, TRUE),
    '#disabled'      => $has_data,
  );

and works now.

danielb’s picture

Status: Fixed » Active

I knew that would come back to bite me

danielb’s picture

Status: Active » Fixed

Cheers, I've done it a bit differently.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.