Compatibility with version 4.x of the Simple XML sitemap module

Created on 29 August 2024, 5 months ago

Problem/Motivation

When creating a new micro site with menu and the Simple XML sitemap module (simple_sitemap) in version 4.x, the following error occurs:

Error: Call to undefined method Drupal\simple_sitemap\Manager\Generator::setBundleSettings() in _micro_menu_generate_simple_sitemap_settings() (line 116 of modules/contrib/micro_menu/micro_menu.module).
micro_menu_site_insert(Object)
call_user_func_array(Object, Array) (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'micro_menu') (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('site_insert', Object) (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll('site_insert', Array) (Line: 215)
Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object) (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object) (Line: 564)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, ) (Line: 781)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, ) (Line: 489)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 293)
Drupal\Core\Entity\EntityForm->save(Array, Object) (Line: 349)
Drupal\micro_site\Form\SiteForm->save(Array, Object)
...

Steps to reproduce

  1. Install the modules: "Micro Site", "Micro Menu" and "Simple XML sitemap" (4.x).
  2. Create a new site type with the "Menu" option enabled.
  3. Create a new site with the previously created type.
  4. Saving the new micro site will result in a WSOD with the error described previously.

Proposed resolution

This problem occurs due to changes in the simple_sitemap API in version 4.x.
To solve this, we should change the simple_sitemap.generator service to simple_sitemap.entity_manager to get the expected behaviour.

function _micro_menu_generate_simple_sitemap_settings(MenuInterface $menu) {
  ...
  /** @var \Drupal\simple_sitemap\Manager\EntityManager $entity_manager */
  $entity_manager = \Drupal::service('simple_sitemap.entity_manager');
  $entity_manager->setBundleSettings('menu_link_content', $menu->id(), $settings);
}

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇵🇹Portugal lolgm

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024