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.
When installing a site using drush site-install, the simple sitemap module generates the following warning message:
Invalid argument supplied for foreach() SitemapGenerator.php:103
Comments
Comment #2
bkhandruk CreditAttribution: bkhandruk commentedLooks like Drupal\simple_sitemap\Simplesitemap::getCustomLinks() method somehow gets called when generator doesn't exist yet.
Comment #3
myLies CreditAttribution: myLies as a volunteer commentedI think it's need review status
Comment #4
sgalindo2388 CreditAttribution: sgalindo2388 commentedTried the patch but I still get the same error but on line 104
Comment #5
caxy4 CreditAttribution: caxy4 at ThinkShout commentedThe issue isn't that the generator doesn't exist by the time
getCustomLinks()
is called on it, but thatgetCustomLinks()
can return non-array values, which aren't suitable forforeach()
.More specifically,
ConfigBase::get()
returns array|mixed|NULL. The storage for custom links makes it such that we'll never get a "mixed" value so we only need to account for NULL ingetCustomLinks()
. This is necessary because everywheregetCustomLinks()
is used in this module, it's assumed an array will be returned.Attached is a patch that ensures
Simplesitemap::getCustomLinks()
will return an array.Side note: you'll only run into this bug if you don't have
simple_sitemap.custom
config, which gets generated when you save "custom links" from the tab of the same name in the module's admin interface.Comment #6
gbyte CreditAttribution: gbyte as a volunteer and commentedI'm positive what caxy4 is saying is the case, however I don't see where
getCustomLinks()
(so in fact simple_sitemap.custom) could return something other than an array, as the module creates a 'links' array inside simple_sitemap.custom on install and this array should never go away.I thought maybe the problem was
update_simple_sitemap_update_8206()
which took\Drupal::config('simple_sitemap.custom')
and moved its insides into the 'links' key without ever checking if the config returned an array. But I tested this and this doesn't seem to cause a problem either.So why is your config returning null?
@rocket.man Please always open up bug reports against the dev version of the module.
Comment #7
bkhandruk CreditAttribution: bkhandruk commentedThanks for advice, @gbyte.co. But am I a reporter of this issue?
Comment #8
gbyte CreditAttribution: gbyte as a volunteer and commented@rocket.man My bad mate, the advice was meant for shawn_smiley.
Comment #9
shawn_smiley CreditAttribution: shawn_smiley at Achieve Internet commentedComment #11
gbyte CreditAttribution: gbyte as a volunteer and commentedEven though this issue seems not reproducible on a clean install, I've added the null check as it certainly will do no harm. Thanks guys.