1

On block configuration page we can control the display of the block on three factors: 1. All pages except those listed 2. Only the listed pages 3. Pages on which this PHP code returns TRUE (experts only)

how can it be done programatically in my module file?

2

i solved it by giving configuration in hook_block_info function

function hook_block_info(){
    $blocks = array();
    $blocks['appendices_page_options'] = array(
        'info' => t('Appendices Page Options'),
        'status' => TRUE,
        'theme' => 'MY_THEME',
        'region' => 'MY_REGION',
        'weight' => 0,
        'visibility' => 1,
        'pages' => "aboutus/*",
        'custom' => FALSE
    );

    return $blocks;
}
1

Take a look at block_add_block_form_submit in modules/block/block.admin.inc. This is the regular block creation form; it appears to just insert the records directly rather than calling another function. Note that each record in the block table is linked to a single theme (you can just use the active one but it's safer to insert records for all themes). The block_custom table holds the content.

Note the 'visibility' value being set at line 569. This is where you would set the display settings you're inquiring about.

  • yeah but any idea on how to tweak it for a single block – Firdous Sep 20 '11 at 11:37
  • I'm afraid you're going to have to get your hands dirty on this one. I'd put some breakpoint / echo statements in the block_add_block_form_submit function around (before/after) the code: $query->values(array( 'visibility' => (int) $form_state['values']['visibility'], 'pages' => trim($form_state['values']['pages']), 'custom' => (int) $form_state['values']['custom'], ... and watch the $form_state['values']['visibility'] value when you create a block. Then copy the function into your custom module, change the $form_state references to your own values. – DeeZone Sep 21 '11 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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