I want to lightly alter the language switcher block's markup by adding additional classes, among others "clearfix" to clear the floats. I cannot however pin down where the markup is created.

This link http://drupal.org/node/1369090 (last post) suggests using template.php but again, I cannot see how I would alter the wrapper div's markup.

Is there any way to achieve this?

up vote 7 down vote accepted

In D7, the language switcher block is created in locale_block_view():

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;
    }
  }
}

You can use hook_block_view_alter() to modify the markup of the block.

If you want modify the output of the links, you can override the theme_links() function in your theme using THEME_links__locale_block() in the template.php file.

  • 1
    Could you expand on the "you can use hook_block_view_alter" part? I've tried implementing this a few ways and its now working. – shanabus Apr 7 '14 at 3:05

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.