Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP warning about missing langcode property on $link['language'] #136

Open
jenlampton opened this issue Dec 31, 2024 · 2 comments · May be fixed by #137
Open

PHP warning about missing langcode property on $link['language'] #136

jenlampton opened this issue Dec 31, 2024 · 2 comments · May be fixed by #137
Assignees

Comments

@jenlampton
Copy link
Member

I don't still have a copy of the error message, but the below fixes it for me:

change

$link['loc'] = xmlsitemap_get_path_alias($link['loc'], $link['language']->langcode);

to

$link['loc'] = xmlsitemap_get_path_alias($link['loc'], $link['language']->language);
@indigoxela
Copy link
Member

indigoxela commented Dec 31, 2024

This looks wrong and probably is. (And all functional tests fail, BTW.)

The global language object has no "language" property - it is langcode.

So the question is, which other code calls this function like that, so the "language" property exists instead of the "langcode" property.

jenlampton added a commit to jenlampton/backdrop-xml-sitemap that referenced this issue Jan 16, 2025
@jenlampton
Copy link
Member Author

That's a good question, and the answer is I have no idea. This error pops up on cron.
It looks like there is no property language on $link['language'].

If you look in the database query above, these are the fields being retrieved:

  $query->fields('x', array(
    'id',
    'type',
    'subtype',
    'loc',
    'lastmod',
    'changefreq',
    'changecount',
    'priority',
    'language',
    'access',
    'status',
  ));

Here it's definitely language and not langcode so at least we know $link['language'] is correct.

But xmlsitemap_language_load() just pulls a language from language_list(), and languages in that core list definitely use $language->langcode and not $language->language ... so yes, I'm pretty sure this should be $link['language']->langcode. So why then, is it causing such problems...

I've switched to using

     $langcode = LANGUAGE_NONE;
      if (isset($link['language']) && property_exists($link['language'], 'langcode')) {
        $langcode = $link['language']->langcode;
      }
      $link['loc'] = xmlsitemap_get_path_alias($link['loc'], $langcode);

I'll throw in some debug code in an else{} to see if I can catch when it's not there.

@jenlampton jenlampton self-assigned this Jan 16, 2025
@jenlampton jenlampton changed the title PHP warning about langcode property, object may still use language in this module. PHP warning about missing langcode property on $link['language'] Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants