The title says it all really. My views exposed form block has no title but I want to add one through code. I have been looking through the api for hours and am totally lost. I have tried tons of things but my drupal and php chops are limited.

1 Answer 1

function hook_block_view_alter(&$data, $block) {
  if ($block->bid == $id) {
    $block->title = $title;

Where hook is the name of your module, $id is the numeric ID of the block and $title is the desired title.

You can find the ID with the Devel module by putting dpm($block); inside the hook_block_view_alter() function and then looking at the output for each block to see which one matches. It'll have a delta attribute on the $block object something like -exp-your_view_name-display where your_view_name is obviously the name of the view, and display is the type of display, e.g. page or block. Or you can just pattern-match the delta value instead of selecting by ID, up to you.

  • So I placed the block as a display suite "block field", and am not seeing it as a block in the dpm output. Would this type of block need special handling?
    – Colin
    Commented Jul 19, 2013 at 18:08
  • Do you see the structure of any blocks from the dpm() at all?
    – beth
    Commented Jul 22, 2013 at 17:54
  • There are two dozen blocks in the dpm() output, but not the one I created through display suite. I played with your code for a bit but ended up just adding the the title through the ui.
    – Colin
    Commented Jul 22, 2013 at 21:43
  • I don't have a lot of Display Suite experience but I think it's very different than core blocks.
    – beth
    Commented Jul 22, 2013 at 21:55

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.