Is it possible to set the sitemap option programmatically using the module Simple XML Sitemap?

drupal.stackexchange https://drupal.stackexchange.com/questions/239728

  •  01-01-2021
  •  | 
  •  

Вопрос

On my drupal instance I have enabled the module called Simple XML Sitemap. The problem now is I want to toggle the option to index certain pages programmatically. I can't find out how. Can this be done?

Это было полезно?

Решение

There are API methods to alter stored inclusion settings and generate the sitemap programmatically. There is no documentation other than the documentation page and code documentation which is pretty complete. Here are the service methods which can be used to accomplish what you need:

getSetting()
saveSetting()
getSitemap()
generateSitemap()
getGeneratedAgo()
enableEntityType()
disableEntityType()
setBundleSettings()
getBundleSettings()
setEntityInstanceSettings()
getEntityInstanceSettings()
removeEntityInstanceSettings()
bundleIsIndexed()
entityTypeIsEnabled()
addCustomLink()
getCustomLinks()
getCustomLink()
removeCustomLink()
removeCustomLinks()

You can chain these methods like so:

\Drupal::service('simple_sitemap.generator')
  ->saveSetting('remove_duplicates', TRUE)
  ->enableEntityType('node')
  ->setBundleSettings('node', 'page', ['index' => TRUE, 'priority' = 0.5])
  ->removeCustomLinks()
  ->addCustomLink('/some/view/page', ['priority' = 0.5])
  ->generateSitemap();

I have just added the above information to the documentation page, we would appreciate anyone further contributing to it.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с drupal.stackexchange
scroll top