On regenerating the sitemap, sometimes a warning occurs:

Warning: Illegal string offset 'path' in Drupal\simple_sitemap\SitemapGenerator->getCustomUrlsData() (line 102 of modules\contrib\simple_sitemap\src\SitemapGenerator.php).

Comments

BryanDeNijs created an issue. See original summary.

bryandenijs’s picture

Status: Active » Needs review
StatusFileSize
new1.17 KB

I created a simple fix that first checks for the $custom_path['path'] to be set.

gbyte’s picture

Status: Needs review » Postponed (maintainer needs more info)

I have not encountered this yet and I cannot see why 'path' would be empty, as it is required when providing custom paths through the interface. The service method addCustomLink actually doesn't allow an empty path. Could you please describe how to reproduce this?

bryandenijs’s picture

StatusFileSize
new83.12 KB

I did a bit of debugging and I figured this out:

At the moment when the warning occurs, the key ($i) in the foreach loop is: 'langcode'
The value ($custom_path) is 'nl'.

I have a multilingual website and it seems this entry comes from the configuration.

You can either fix this from the root (inside the getCurtomLinks() method or deeper), or just place a 'if isset' statement here to also prevent future errors. Or do both, maybe that's even better to be sure.

gbyte’s picture

Thanks, but debugging is not the problem. I too have a multilingual site and the links are saved and retrieved correctly to and from configuration. What I am trying to ask you is for you to find out how I could reproduce this error on my installation. This error should never happen, as data input into simple_sitemap.custom should be an array of paths: $i should be just an index and $custom_path['path'] should be the path.

Could you please paste the contents of your admin/config/search/simplesitemap/custom here?
If this seems correct, can you also paste the content of your exported simple_sitemap.custom.yml here?
If possible, please try to reproduce this error on a fresh Drupal install, or after reinstalling the module on your site.
I can only debug this if I know how erroneous data came into your configuration. Did you maybe mess with the configuration? Have you run update.php after updating the module?

Thanks!

bryandenijs’s picture

I will try to do that!

kevinvb’s picture

I have the same issue on a multilingual project.
This is my configuration
simple_sitemap.settings.yml

max_links: 2000
cron_generate: true
remove_duplicates: true
skip_untranslated: false
batch_process_limit: 1500
enabled_entity_types:
  - node
  - taxonomy_term
  - menu_link_content
langcode: nl

And simple_sitemap.custom.yml

0:
  path: /
  priority: !!float 1
langcode: nl

This happens whenever I regenerate the xml sitemap.
Note: I use the api because the project has multiple links for one node. Maybe adding extra links to the sitemap through the api is the cause of this warning.

The warning is fixed after I applied the patch.

gbyte’s picture

Version: 8.x-2.7 » 8.x-2.x-dev
Assigned: bryandenijs » gbyte
Status: Postponed (maintainer needs more info) » Closed (outdated)

Apparently the 'langcode' key is a key added by core and is being erroneously processed by the link generator as another custom link. This has been already fixed with #2826556: Schema issues introduced, so please use the dev version.

kevinvb’s picture

When will there be a new version of the module?
Because it's not recommended to use dev versions for production sites.

gbyte’s picture

There will be a new version of the module as soon as there are enough fixes and added functionality to justify one. Until then using the dev version is perfectly OK, especially because the only change in dev ATM is the fix for this issue. Just grab the dev now and do not update it until the next stable is available.

As a side note, the community not using the dev version of modules leads to a poorly tested dev versions which in turn leads to buggier stable releases.

sachariew’s picture

Had the same problem, switched to dev-version, problem is fixed. Thanks!

flocondetoile’s picture

Same issue. Dev version fix it too.