2

I may have a disconnect and I'm just not sure if what I'm asking is possible. I'd like to tell Drupal where to place a block. So far I'm using a Context with a path condition to user/* and stream.

enter image description here

Can't I accomplish the similar thing with the following?

function hook_block($op = 'list', $delta = 0, $edit = array()) {

  if ($op == 'list') 
  {
    $blocks[0] = array(
      'info'      => t('Social Login Block'),
      'region'    => 'sidebar_last',
      'pages'     => 'stream\nusers/*',
      );

Is this possible or is it better form to just let the maintainer set the block manually? Or a larger question, how might I translate this context rule into code?

1 Answer 1

1

You should use hook_block_info_alter() instead of hook_block(). For example:

function YOURMODULE_block_info_alter(&$blocks, $theme, $code_blocks) {
  $blocks['MODULE']['BLOCK']['visibility'] = BLOCK_VISIBILITY_LISTED;
  $blocks['MODULE']['BLOCK']['pages'] = 'user/* \n stream';
}

Where YOURMODULE is the name of your module, MODULE is the module generating the block, and BLOCK is the name of the block. You should list all paths where the block should be visible separated by \n, \r or \n\r.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.