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?
1 Answer
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.