Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comments
Comment #2
bkhandruk CreditAttribution: bkhandruk commentedReplaced undefined variable $context with $sitemap->getContext() method.
Comment #3
ytsurkWorks fine for me.
Comment #4
G42 CreditAttribution: G42 commentedI can not replicate this problem, have you tried the latest version?
Comment #5
alexandre.todorov CreditAttribution: alexandre.todorov commentedAs 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();
Comment #6
Dave ReidI didn't see this issue earlier, this has been fixed with #3002353: PHP Notice: Undefined variable $context. I've credited you in that issue.