I have a view and in the header of the view, I am rendering a custom block. The block is showing up just fine, however, I need to alter it and I cannot seem to figure this out. I have tried hook_preprocess_block, hook_block_view_alter and a couple others. I know the ID of my block but it isn't helping.

If I am embedding the block in the view and I want to alter the block, do I need to first alter the view and tell it to rerender the block? I am using drupal 8. Any help would be appreciated.

1 Answer 1


I assume you're displaying a block_content entity.

That is not actually rendered through the block system, it's an entity, so you need to implement hook_block_content_view() (see hook_ENTITY_TYPE_view() for documentation)

  • Yes and specifically Global: Rendered entity - Custom block (Global: Rendered entity - Custom block). I added function avanir_block_content_view(...){ kint($build); } to my theme file and nothing is outputting on the screen. I also figured out the twig name and changing the twig template didn't actually change what was rendered in the view (which I think is what you meant in your answer).
    – Ronnie
    Commented Sep 22, 2016 at 19:33
  • I meant to say no kint messages are outputting on my screen
    – Ronnie
    Commented Sep 22, 2016 at 19:40
  • 1
    that's because you need a module to implement a hook, not a theme. themes can only implement a few specific alter hooks. And custom blocks have no template on their own, so there's no preprocess either.
    – Berdir
    Commented Sep 22, 2016 at 21:45
  • ah, well that is a huge diff between 7 and 8 that I am just figuring out. Thank you
    – Ronnie
    Commented Sep 22, 2016 at 23:14
  • This really helped and I got it working. Thank you very much.
    – Ronnie
    Commented Sep 23, 2016 at 0:07

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.