0

I had created a new region to my theme "buynow" and my theme.info contains the following line

regions[buynow] = Buynow

In my custom module i had created a custom block in which i assigned the block to the region buynow

function buynow_block_info() {
  $blocks = array();
  $blocks['buynow'] = array(
    'info' => t('Shoretel Buynow'),
    'status' => 1,
    'region' => 'buynow',
  );
  return $blocks;
}

When i try to enable the module, Iam getting The block was assigned to the invalid region and the block was disabled

How can i set my block to the new region.

0

You can use this code:

function formalter_block_info() {

 $blocks = array();

 $blocks['buynow'] = array(

 'info' => t('Shoretel Buynow'),

 'status' => 1, // This will enable your block by default, and set it to region given in 'region' option

 'region' => 'buynow', // put <machine-name of your region> in place of footer
 'visibility' => BLOCK_VISIBILITY_NOTLISTED,

 'weight' => 2,

 );
return $blocks;
}
  • Its not working – John Melchior Jan 20 '16 at 13:00
  • I tried this code, and it is working, what issue you are facing? – Dev Jan 21 '16 at 10:16
  • The block Buynow was assigned to the invalid region buynow_btn and has been disabled this is the error am getting. – John Melchior Jan 21 '16 at 13:14
  • I hope you are entering right region here: 'region' => 'buynow', – Dev Jan 22 '16 at 10:01
  • Yes my new region is buynow – John Melchior Jan 22 '16 at 10:08
0

In Drupal 7, you should also create a representation to the region in page.tpl.php:

See here for more data.

In a similar manner, in Drupal 8 yous should add regions via the Twig syntax (after your have created a reference in the info file as you already did).

0

Even though its an old issue I am pointing it to Drupal Discussion so others can benifit from it.

Here is the discussion regarding this in Drupal.org .

The problem occurs when the assigned region is not present in default themes.When we assign a region to a block through custom module it is assigned to all the available themes not just current active theme.

For example Seven is the administator theme in Drupal 7 , it has only 4 regions but default theme Bartik has more then 4 regions so if if you assign a region which is present in Bartik theme to block through custom module it cant get assigned to the same region in Seven theme as it is not present, hence the Warning will be thrown.

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.