Derivative sitemap types cannot be used

Created on 28 July 2021, over 3 years ago
Updated 4 December 2024, 18 days ago

Problem/Motivation

Derived sitemap type plugins cannot be used. Drupal derived plugins contain colon in the plugin names. For example if you have plugin custom_sitemap_type and you create a derivative some_derivative the derivative plugin id is custom_sitemap_type:some_derivative. Such a plugin cannot be used for sitemap variants because the module creates separate config per variant. However config names cannot contain colons in their names and using such plugin would result into erro:

Drupal\Core\Config\ConfigNameException: Invalid character in Config object name simple_sitemap.variants.frontend_hreflang:site_one. in Drupal\Core\Config\ConfigBase::validateName() (line 107 of core/lib/Drupal/Core/Config/ConfigBase.php).

Motivation for us is that we have a site with 100+ frontends. This is a decoupled site and we need to have a sitemap per frontend. We have introduced a custom sitemap type called frontend_hreflang. This type derives the sitemap types per frontend, so we don't need to create them manually. It will produce sitemap types like frontend_hreflang:site_one, frontend_hreflang:site_two, etc. But we cannot use this due to problem mentioned above.

Steps to reproduce

Create sitemap type derivative, eg:

/**
 * Extension of default href lang sitemap type to cover the frontend sitemaps.
 *
 * @SitemapType(
 *   id = "frontend_hreflang",
 *   label = @Translation("Frontend hreflang"),
 *   description = @Translation("The hreflang sitemap type to cover the frontend sitemaps."),
 *   deriver = "Drupal\your_module\Plugin\Derivative\FrontendHreflangSitemapType",
 *   sitemapGenerator = "default",
 *   urlGenerators = {
 *     "custom",
 *     "entity",
 *     "entity_menu_link_content",
 *     "arbitrary",
 *   },
 * )
 */
class FrontendHreflangSitemapType extends DefaultHreflangSitemapType {
}

Introduce deriver and create couple of sitemap type plugins. Then try to use deriver sitemap type plugin in your variants under /admin/config/search/simplesitemap/variants. Eg:
site_one | frontend_hreflang:site_one | site_one.com

Saving the form will result into an error mentioned above.

Proposed resolution

Would be nice if derived plugins could be used in sitemap variants.

πŸ“Œ Task
Status

Closed: outdated

Version

4.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia hideaway

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024