0

Is it possible in Drupal 7 to load block visibility settings programatically in module? I'm rendering block programatically and I want to include checking those settings, so it still will be possible to hide block from UI. Property of "status" and "visibility" are not enough, since it's possible that the block won't be placed in any region at all.

0

Sure, block_load gives you the contents of the whole row from the block table:

$block = block_load('module', 'delta');

$region = $block->region;
$weight = $block->weight;
$custom = $block->custom;
$visibility = $block->visibility;
$pages = $block->pages;
$title = $block->title;

And so on.

  • This is the only thing this object contains: bid -> 187, module -> block, delta -> 20, theme -> galeco, status -> 0, weight -> 0, region -> , custom -> 0, visibility -> 0, pages -> , title -> <none>, cache -> -1, i18n_mode -> 1 Visibility and Status values are already computed, so if the block is turned off they will give me 0, even if the rest of visibility settings state that the block should be displayed. That's why I neeed granural acess to settings. I stated that status and visibility properties are not enough in my initial post. – Dominika Jan 11 '18 at 8:28
  • What are the rest of the visibility settings? Do you mean "Roles" and "Content type"? Those are in the block_role and block_node_type tables respectively – Clive Jan 11 '18 at 8:39
  • By visibility settings I mean visibility settings as shown here prntscr.com/hzdjku The actual settings, not computed value whether block should be displayed or not. In this case I'm mostly interested in block_roles if that's what stores data from Roles tab in Visibility settings. Is there a function to load it per block, or should I just get it from database by query? – Dominika Jan 12 '18 at 9:43
  • Just get it from the DB, there’s no helper in the api – Clive Jan 12 '18 at 10:02

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.