It would be nice if 'Custom links' in the XML sitemap could be on a domain basis.
An example of such, I'm working on a site that has a few custom dynamic pages in code and each domain may have different URLs based on certain domain based conditions, and as these pages aren't nodes or in a menu, I have opted to have them injected as 'Custom links' but there is no domain or access checking being done from that point onwards so all links are showing up in all domain sitemaps regardless to whether or not they should be.
To get around this I've just chosen to use a query alter, but it would be preferable to have the ability to set the links context.
Comments
Comment #1
ravencoder commentedHi Deciphered,
I also trying to find a way to add 'custom links' based on domain.
Perhaps you can share your work around, to have this working?
Comment #2
decipheredYou're lucky I'm nice, while it probably would have been helpful had I shared the information straight away, finding the specifics from so long ago, especially when the project is long completed and the only copy I have is in a Time Machine backup of an old computer, was quite tricky... but find it I did.
This is only conceptual code, as I won't share a clients code without there permission, nor would some of the code even be of any use to you.
First thing I did was inside hook_cron() I would check if the custom links where already in the xmlsitemap table, as it was an ever growing list it was more than likely that there would be new items to build, in that case I would build up the link object and trigger it to be saved with code like the following:
Then comes the tricky bit, the query alter. It's tricky to really walk you through this one as it was done so long ago and I have no desire to get my head to deep in to it as I have no need to do so, so I'll just dump the slightly modified code and let you work it out for yourself:
Hope it helps
Comment #3
ravencoder commentedHi Deciphered,
I really appreciate this. Thanks!
Comment #4
pdendis commentedI managed to create a sandbox module https://www.drupal.org/sandbox/pdendis/2344791. Below is the related code
Comment #5
oleksiyAdded a patch based on the code above where it's allowed to choose several domains per custom link.