In certain conditions, the following error occurs while generating the sitemap at /sitemap.xml

Message	Notice: Undefined variable: context in Drupal\xmlsitemap\Controller\XmlSitemapController->renderSitemapXml() (line 76 of /var/www/project/web/modules/contrib/xmlsitemap/src/Controller/XmlSitemapController.php) 

This happens when I have the Enable developer mode to expose additional settings. Button checked. This button can be found in the Setting Tab -> Under Advanced Settings.

When I Uncheck the box and use the sitemap, it works fine.

Any ideas?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jonnyeom created an issue. See original summary.

bkhandruk’s picture

Replaced undefined variable $context with $sitemap->getContext() method.

ytsurk’s picture

Works fine for me.

G42’s picture

I can not replicate this problem, have you tried the latest version?

alexandre.todorov’s picture

As the meaning of "current_context" is to get the current context, I think it is better to use xmlsitemap_get_current_context() which returns the currently active context and not the sitemap one. In fact it is intended to be the same than $sitemap->context because of $sitemap = XmlSitemap::loadByContext();

Dave Reid’s picture

Status: Needs review » Closed (duplicate)

I didn't see this issue earlier, this has been fixed with #3002353: PHP Notice: Undefined variable $context. I've credited you in that issue.