I have a block like this:

<section id="block-locale-language" class="block block-locale clearfix" data-thmr="thmr_23">
  <h2 class="block-title">Languages</h2>
  <ul class="language-switcher-locale-url" data-thmr="thmr_8"><li class="nl first"><a href="/nl/user/1" class="language-link" lang="nl" data-thmr="thmr_9">Nederlands</a></li>
      <li class="en active"><a href="/user/1" class="language-link active" lang="en" data-thmr="thmr_10">English</a></li>
      <li class="fr last"><a href="/fr/user/1" class="language-link" lang="fr" data-thmr="thmr_11">Français</a></li>

But what I want is this:

<div class="btn-group">
  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
    Action <span class="caret"></span>
  <ul class="dropdown-menu" role="menu">
    <li><a href="#">Action</a></li>
    <li><a href="#">Another action</a></li>
    <li><a href="#">Something else here</a></li>
    <li class="divider"></li>
    <li><a href="#">Separated link</a></li>

I've overwritten the locale block like this: (block--locale.tpl.php)

<div class="btn-group languageswitch">
    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
        LANGUAGE <span class="caret"></span>
    <?php print $content; ?>

But I need to change the structure in the $content variable, how can I do this?


In my locale module (in /modules) I've found this:

function locale_block_view($type) {
  if (drupal_multilingual()) {
    $path = drupal_is_front_page() ? '<front>' : $_GET['q'];
    $links = language_negotiation_get_switch_links($type, $path);

    if (isset($links->links)) {
      drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css');
      $class = "language-switcher-{$links->provider}";
      $variables = array('links' => $links->links, 'attributes' => array('class' => array($class)));
      $block['content'] = theme('links__locale_block', $variables);
      $block['subject'] = t('Languages');
      return $block;

As you can see they add a class language-switcher-{$links->provider}. Now I would like to add some more classes to that.

How can I do this now in my subtheme template.php? It's like my function locale_block_view_alter isn't called for some reason. I already tried with a var_dump but no result in my browser ...

  • You function name is wrong. Lets say your theme is called "foobar". Your block alter function needs to be named foobar_block_view_alter().
    – Felix Eve
    Apr 17, 2014 at 12:40
  • Then it's gonne be applied on all the blocks, isn't it? I want it for one specific block
    – nielsv
    Apr 17, 2014 at 12:46
  • Yes, read my answer. Specifically the bit titled "To target a specific block..."
    – Felix Eve
    Apr 17, 2014 at 13:03
  • Ok, I now have the module and delta, but how do I need to shape this in the $block?
    – nielsv
    Apr 17, 2014 at 13:23
  • 1
    Take a look at the examples module, specifically the one called block_example. Also Google for examples and tutorials. It sounds like you need someone to guide you though every step of the way and that is not what Drupal Answers is for. If you do have any more questions about a specific topic then please do ask them. Also see the FAQ for more information about what kinds if questions can be asked here.
    – Felix Eve
    Apr 17, 2014 at 13:35

2 Answers 2


If you are not in control of the initial building of the content then hook_block_view_alter() can alter the content of any block before it is rendered.

From the API page:

Perform alterations to the content of a block.

This hook allows you to modify any data returned by hook_block_view().

To target a specific block...

In hook_block_info(), each block your module provides is given a unique identifier referred to as "delta" (the array key in the return value). Delta values only need to be unique within your module.

The variable $block is passed into hook_block_view_alter(). This variable is defined as:

$block: The block object, as loaded from the database, having the main properties:

  • module: The name of the module that defined the block.
  • delta: The unique identifier for the block within that module, as defined in hook_block_info().

So you can check what the module and delta of the block to target specific blocks.

  • And how can I change one specific block? hook_block_locale_view_alter didn't do the trick
    – nielsv
    Apr 17, 2014 at 10:20
  • What is hook_block_locale_view_alter? That is not a hook. I've updated my answer and also maybe read Understanding the hook system for Drupal modules or Drupal Hooks Explained
    – Felix Eve
    Apr 17, 2014 at 10:28
  • Sorry - just worked out your the same user and I've already recommended those links to you!
    – Felix Eve
    Apr 17, 2014 at 10:34
  • Updated my question.
    – nielsv
    Apr 17, 2014 at 12:14

You might want to look at targetting the THEME_item_list instead of the locale module. I had the exact problem but since my issue was targetting a menu I could use hook_menu_tree to add the classes.

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.