foreach (array_keys($links) as $langcode) {
      if (!isset($links[$langcode]['language'])) {
        $lang_obj['language'] = $langcode;
        $links[$langcode]['language'] = (object) $lang_obj;
      }
...

You shouldn't add that language property to the links that hasn't it. When language negotiation is configured as session the language links has not that language property and seems to be for good reason. Adding that property yourself you are breaking the output returned by url function for those links so anywhere url is used with those links wrong values are received -in core language switcher block for example-.

It is not always the same:

url('node/1',  array('query' => array('language' => 'fr')));

than

url('node/1', array('query' => array('language' => 'fr'), 'language' => (object) array('language' => 'fr')));

If you need an object like that and you want to carry it within links array, add your own property. Something like:

    foreach (array_keys($links) as $langcode) {
      if (!isset($links[$langcode]['language'])) {
        $lang_obj['language'] = $langcode;
        $links[$langcode]['languageicons_language'] = (object) $lang_obj;
      }
...

where you create your own languageicons_language property in each link. Anyway I don't know why you even need that. Just send the langcode as a parameter to your function languageicons_link_add and is enough:

  languageicons_link_add($links[$langcode], $langcode);
...
function languageicons_link_add(&$link, $langcode, $title = NULL) {
...
  $icon = theme('languageicons_icon', array(
    'language' => (object) array('language' => $langcode),
    'title' => check_plain($title),
  ));

Even It would be possible to use only langcode instead of that object though maybe changing that now is not a good idea as that could break any other module using that languageicons_icon theme function.

If for some reason you think that the links should always have that language property you should fill an issue against core.

I understand that for what this module does you need to hack the title property but is not good idea hacking the language property.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

manfer’s picture

Title: hooking language links breaks core language handling » hacking language links breaks core language handling
manfer’s picture

manfer’s picture

Status: Active » Needs review
manfer’s picture

Issue summary: View changes

typo