I'm trying to modify the output of the language switcher block to make the output more inline with other menu styles on my site. However, I can't figure out how to modify the output.

I'm attempting to use the following:

function my_module_preprocess_block(&$variables) {

This gets every block on the page except for the language switcher.

How can I preprocess or modify this?

  • 1
    What do you need to change exactly? Markup or classes (or both)?
    – Clive
    Jun 8, 2018 at 15:56

1 Answer 1


We added a filter to drop the languages that did not have translations from the language switcher. Here's the code from that:

 * Implements hook_block_view_BASE_BLOCK_ID_alter().
function mymodule_block_view_language_block_alter(array &$build, BlockPluginInterface $block) {
  $build['#pre_render'][] = '_mymodule_language_block_prerender';

FYI - Used pre_render because I was removing links from the [content][[#links] element.

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.