hook to alter custom blocks? I am having a problem with my custom blocks rendering, and I want to programmatically manipulate the blocks to troubleshoot the issue. 

I used this question to add this hook to my module:

function mymodule_block_view_alter(array &amp;$build, Drupal\Core\Block\BlockPluginInterface $block) {
  drupal_set_message($block-&gt;getBaseId());
}


However, when I navigate to my site, I see only the base ids of system blocks:

- page_title_block
- system_main_block
- help_block
- local_tasks_block


My site's header and footer are made of custom blocks, so I should be seeing their ids. 

How can I programmatically access my custom blocks?

Edit this is my actual code:

$ cat my_block_hooks.module
&lt;?php

function my_block_hooks_block_view_alter(array &amp;$build, Drupal\Core\Block\BlockPluginInterface $block) {
  drupal_set_message(__FUNCTION__ . "() id: " . $block-&gt;getBaseId() );
}


And here's a screenshot:



You can see that all the system blocks show up, but my custom block does not. 

This is the custom block as I have it set up:



And here I have it placed in the layout:



And of course, I've cleared the cache many times to get to this point. 

What am I doing wrong?
The type of entity you are dealing with defines the hook you need to implement; in this case it is NOT block but rather block_content, as provided by the "Custom Block" core module.

N.B.: It is generally good practice to use more specific hooks when possible, as it will have a general effect on your code's performance, i.e. your hook implementation will be called less times if it is more specific. In your case, instead of going through all blocks available on any page during page loading, you are going through only custom blocks (block_content entities).

In order to get your hook_ENTITY_TYPE_view()/hook_ENTITY_TYPE_view_alter() implementation to work, you need to replace ENTITY_TYPE with block_content. That should give you the following code (which I tested and works):

use Drupal\block_content\Entity\BlockContent;
...
function my_block_hooks_block_content_view_alter(array &amp;$build, BlockContent $custom_block) {
  drupal_set_message(__FUNCTION__ . "() id: " . $custom_block-&gt;id() );
}


And the visual result:



Good luck!