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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shawn_smiley created an issue. See original summary.

bkhandruk’s picture

Looks like Drupal\simple_sitemap\Simplesitemap::getCustomLinks() method somehow gets called when generator doesn't exist yet.

myLies’s picture

Status: Active » Needs review

I think it's need review status

sgalindo2388’s picture

Tried the patch but I still get the same error but on line 104

caxy4’s picture

The issue isn't that the generator doesn't exist by the time getCustomLinks() is called on it, but that getCustomLinks() can return non-array values, which aren't suitable for foreach().

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 in getCustomLinks(). This is necessary because everywhere getCustomLinks() 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.

gbyte’s picture

Status: Needs review » Needs work

I'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.

bkhandruk’s picture

Thanks for advice, @gbyte.co. But am I a reporter of this issue?

gbyte’s picture

@rocket.man My bad mate, the advice was meant for shawn_smiley.

shawn_smiley’s picture

Version: 8.x-2.8 » 8.x-2.x-dev

  • gbyte.co committed 23d7d72 on 8.x-2.x
    Issue #2846875 by caxy4, shawn_smiley: Invalid argument supplied for...
gbyte’s picture

Status: Needs work » Fixed

Even 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.