You are here

function hook_blockreference_blocks_pre_alter in Block reference 7.2

Alter referenceable blocks, BEFORE the autocomplete match.

These are always block objects, not options. You can change the option label by changing $block->info.

For autocomplete fields, this alter happens AFTER the search, before slicing the results (ACDB does that).

$context contains:

  • instance
  • type ("autocomplete" or "options_list", depending on where this list is

requested)

  • entity
  • entity_type
1 invocation of hook_blockreference_blocks_pre_alter()
_blockreference_find_blocks in ./blockreference.module
Helper to find blocks that potentially match a search string, in the right order, altered by custom modules.

File

./blockreference.api.php, line 19

Code

function hook_blockreference_blocks_pre_alter(&$blocks, $context) {

  // These are all the blocks that match the field instance's referenceable module option. If you were to change
  // a block's label now, that's the label the autocomplete will try to match.
  foreach ($blocks as $id => $block) {

    // Add module & delta to pretty label.
    $block->info .= ' (' . $block->module . '/' . $block->delta . ')';

    // Remove all Views blocks, except 'public_stuff'.
    if ($block->module == 'views' && strpos($block->delta, 'public_stuff-') !== 0) {
      unset($blocks[$id]);
    }
  }
}