0

I'm building a module with several blocks. But only one is showing up in blocks list. Calendar shows up in block list but could you see why I cant see my 'frontdoor' block ?

function businesshours_block_info() {
    $blocks['calendar'] = array (
        'info' => t('Little calendar'),
        'status' => true,
        'visibility' => 1,
        );
    $blocks['frontdoor'] = array (
        'info' => t('The Front Door'),
        'status' => FALSE,
        'visibility' => 0,
        );
    return $blocks;
}
function businesshours_block_view($delta) {
    $block = array();
    switch ($delta) {
        case 'calendar':
            $block['content'] = businesshours_block_contents($delta);
            $block['subject'] = t('toto');
            return $block;
            break;
        case 'frontdoor':
            $block['content'] = businesshours_block_contents($delta);
            $block['subject'] = t('front');
            break;
    }
    return $block;

}
function businesshours_block_contents($delta) {
    switch ($delta) {
        case 'calendar':
            return array('#markup' => '<div style="width:8.2em;margin:auto;">' . _build_calendar() . '</div>');
            break;
        case 'frontdoor':
            return array('#markup' => '<div style="width:8.2em;margin:auto;">' . _build_frontdoor() . '</div>');
            break;
    }
}

Thx in advance.

0

3 Answers 3

0

Remove the return $block in case 'calendar'

function businesshours_block_view($delta) {
$block = array();
switch ($delta) {
    case 'calendar':
        $block['content'] = businesshours_block_contents($delta);
        $block['subject'] = t('toto');
        break;
    case 'frontdoor':
        $block['content'] = businesshours_block_contents($delta);
        $block['subject'] = t('front');
        break;
}
return $block;
}

NOTE: Also check your visibility

Possible values are:

BLOCK_VISIBILITY_NOTLISTED: Show on all pages except listed pages. 'pages' lists the paths where the block should not be shown.

BLOCK_VISIBILITY_LISTED: Show only on listed pages. 'pages' lists the paths where the block should be shown.

BLOCK_VISIBILITY_PHP: Use custom PHP code to determine visibility. 'pages' gives the PHP code to use. Most modules do not provide an initial value for 'visibility' or 'pages', and any value provided can be modified by a user on the block configuration screen.

3
  • Right...that shouldn't be in there. Jun 6, 2013 at 8:26
  • It was only a typo. Anyway it couldnt prevent it working. Anyway I did the edit and it still doesnt show up...
    – arta
    Jun 6, 2013 at 8:45
  • In fact I understood that block_info is fired only once at module setup. If you edit the code after, no new block will be added. Uninstall required. Also if status is set to True you'll want to assign a it a region... So false is better : it leaves you choose your region in the admin (theme have different regions)
    – arta
    Jun 6, 2013 at 9:25
0

Their is no hook for content in blocks.U cant use $delta in content of block type. U have to use different functions for each of the block type.

Eg:

function businesshours_block_view($delta) {
$block = array();
switch ($delta) {
    case 'calendar':
        $block['content'] = businesshours_block_content1();
        $block['subject'] = t('toto');
        return $block;
        break;
    case 'frontdoor':
        $block['content'] = businesshours_block_content2();
        $block['subject'] = t('front');
        break;
}
return $block;
}

function businesshours_block_content1(){


  return array('#markup' => '<div style="width:8.2em;margin:auto;">' . _build_calendar() . '</div>');  

}
function businesshours_block_content2(){

  return array('#markup' => '<div style="width:8.2em;margin:auto;">' . _build_frontdoor() . '</div>');

 }
1
  • In fact I understood that block_info is fired only once at module setup. If you edit the code after, no new block will be added. Uninstall required. Also if status is set to True you'll want to assign a it a region... So false is better : it leaves you choose your region in the admin (theme have different regions). Thx for your help...
    – arta
    Jun 6, 2013 at 9:46
0

It is not clear if you cannot see the block in the region on your page or in the Manage Blocks administration page. I am assuming you can't see it on your site pages (not the Manage Blocks page).

The reason you would not see frontdoors block on your site is that you have set status to FALSE. Unless you move the block to one of the theme's regions, you will not see this block.

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.