2

I am trying to alter some data that is being passed from the Language Switcher module.

Here is a code snippet from the module.

if (isset($links->links)) {
  $build = array(
    '#theme' => 'links__language_block',
    '#links' => $links->links,
    '#attributes' => array(
      'class' => array(
        "language-switcher-{$links->method_id}",
      ),
    ),
    '#set_active_class' => TRUE,
  );
}

So '#theme' => 'links__language_block', as I could guess means that I have to create the function called

function mytheme_links__language_block(&$variables) {
    var_dump("HELLO");
    exit;
}

But it is not called. I have no idea what is the problem ?

The only hook is called - function mytheme_preprocess_page(&$variables)

Please suggest what can be wrong and why my hook function is not called.

  • 1
    There appears to be a typo in your function. The theme hook uses language_block but your function name is using locale_block. – jhedstrom Mar 3 '17 at 22:18
  • thanks for pointing out the error, but this is not a problem, just typo in the question – HelloMufecayo Mar 3 '17 at 22:21
  • 1
    Have to ask the obvious - did you clear cache after adding this code? – Kevin Mar 3 '17 at 22:24
  • @Kevin , I have just cleared it before reading your comment and it works, but I have enabled development mode !! Why it is still caching this files ? Could you please explain how to disable this cache. Thanks – HelloMufecayo Mar 3 '17 at 22:29
3

I think this style of theme hook is deprecated in Drupal 8. From the API docs:

Theme functions are deprecated in Drupal 8.0.x and will be removed before Drupal 9.0.x. Use Twig templates instead.

So since there doesn't exist a theme function theme_links(), the functions MYTHEME_links and MYTHEME_links__language_block would not be called.

You can still customize this output by adding a links--language-block.html.twig file to your theme.

You can also utilize preprocess functions (MYTHEME_preprocess_links()).

1

Anytime you add functions and template files to your theme, you should clear the cache so the functions and templates are picked up by Drupal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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