Can't access links in block_view_alter hook I have a two-language site with the standard language switcher block. I want to remove the link that points to the current page language (I only want the user to see one link to switch to the language they're not seeing).

I've tried this:

function mymodule_block_view_language_block_alter(&amp;$build, $block) {
  $build['links'] = []; //for now for debugging purposes, remove all links
}


It doesn't work (though it runs the code). The $build array doesn't have a links key, or anything it's supposed to according to the build method in core/modules/language/src/Plugin/Block/LanguageBlock.php. Why might this happen? How can I alter what I'm seeing there?

BTW I also tried the block_build_alter hook. Similar situation.
Those hooks are unfortunately not very useful; I don't really know why they work like that. The actual block view didn't happen yet; that's in a preprocess. You'd need to add another preprocess that runs later.

However, for your specific use case, why not use the hook that's designed exactly for this? hook_language_switch_links_alter()?