0

I have followed the instruction to create a new block here which is basically the same as here on SE. My block is indeed created but the region is wrongly set to "none" instead of "Content Post".

In my module events.module file:

function events_block_info () {
    return [
        'events_list' => [
            'info'       => "Events list",
            'region'     => 'content_post',
            'visibility' => BLOCK_VISIBILITY_NOTLISTED
        ]
    ];
}

function events_block_view ($delta = '') {
    $result = false;
    if ($delta == 'events_list') {
        /* ... do my stuff .... */
    }

    return $result;
}

This creates a block but the region is set to "none". The drawback is I have to go on each environment and change the region manually back to "Content Post". It is inefficient.

I also find it extremely weird that the creation of a block is done this way. I would expect instead that the creation takes place in the module.install file in the hook_install() function. Maybe there is way?

4
  • You have a pluralisation bug (module is called event, but you're implementing hooks for a module called events). Other than that your method is correct, there's no way to provide blocks through an install file (it's not how Drupal's architecture works yet, in Drupal 8 you don't use the block hooks). region is per-theme by the way, and has some extra constraints, the variable desc in the function docs themselves should let you know if those apply to you
    – Clive
    May 6, 2015 at 15:48
  • Oops, typo I corrected the events.module in my post here. In my code it was already ok. May 6, 2015 at 17:08
  • @Clive About "regions", when the hook_block_info() is executed, it will add a block for each enabled theme. But in my case all of them are set to the "none" region... May 6, 2015 at 17:29
  • are you sure the machine name for the region is correct?
    – Geoff
    May 6, 2015 at 19:23

1 Answer 1

3

I think you need to set 'status'.
eg.

function events_block_info () {
    return [
        'events_list' => [
            'info'       => "Events list",
            'status'     => TRUE,
            'region'     => 'content_post',
            'visibility' => BLOCK_VISIBILITY_NOTLISTED
        ]
    ];
}
1
  • Is there any way in drupal 8 ?
    – Leopathu
    Jun 23, 2016 at 9:52

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.