Closed (fixed)
Project:
XML sitemap
Version:
8.x-1.x-dev
Component:
xmlsitemap.module
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Dec 2011 at 12:09 UTC
Updated:
10 Oct 2018 at 15:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
carinadigital commentedHere's a patch and an an example module adding in some static video information for video sitemaps.
Comment #2
jon nunan commentedComing back to this, because the job I'm working on needed to make the sitemap like this because of our SEO team (grumbles):
https://support.google.com/webmasters/answer/2620865?hl=en
Having our sites for every region talk to each other is well outside the scope of this module, so I created my own custom solution to do it. Problem being though I was unable to output it as the method writeSitemapElement doesn't allow for attributes.
This patch adds the hook and allows writeSitemapElement to print out XML tags with attributes.
An example usage of
I clipped some of the example for space, mainly taking out the for loop that does it multiple times for each locale, but the result means I get an output like:
Again I know the locale stuff is out of scope, this is just an example of what this hook and method rewrite allows.
Comment #3
udhaya kumar commentedAttached Xmlsitemap.patch shoud work for version 7.x-2.0-rc2
An example usage of hook_xmlsitemap_item_extend()
Comment #4
chadedge commentedAdding a base drupal_alter hook with minimal impact.
Our company need was to alter the URL's saved by the XMLwriter only, without adding extra data like "video" to the elements.
Altered the initial query (including extra columns), and added the element_alter to the drupal_alter() call.
Comment #5
chadedge commentedUpdated the patch to better comply with standards (added documentation to the API). Functionally the same patch, just a notation update from my previous submission.
This patch replaces my previous.
Comment #6
eojthebraveHere's my version of the patch started here. This patch adds two hooks,
hook_xmlsitemap_root_attributes_alter()andhook_xmlsitemap_element_alter()which allow you to alter the XML that's about to be generated an add additional information.This doesn't necessarily solve #451234: Support for extended sitemap formats (e.g. video, news, image, mobile) but it does make it pretty easy to write your own custom module that implements a couple of hooks and includes the required data. With this patch I had no problem adding the elements to my sitemap.
The code here is mostly the same as the patches above, but it adds documentation and better adherence to the Drupal coding standards. Thanks for the ideas about how to make this work everyone.
Comment #7
dave reidWe should probably be passing in $this->sitemap as an argument here, or possibly just $this. This way modules that want to add attributes can do so if they only apply to a specific sitemap context.
Same here.
Comment #8
dave reidRevised patch that ensure the sitemap object is passed through everywhere.
Comment #10
dave reidCommitted #8 to 7.x-2.x.
Comment #11
udhaya kumar commentedAttached Xmlsitemap.patch shoud work for version 7.x-2.0-rc2. Added hook xmlsitemap_item_element_alter and xmlsitemap_more_attributes. By implementing the hooks mentioned above in custom module, we should be able to extend xmlsitemap for image and video.
To extend image sitemap.
Comment #12
pobster commentedJust providing a little extra here ... We required the ability to "drop" the element from the sitemap if its not aliased.
Comment #13
pobster commentedI then simply used;
Comment #14
Martin. commented#8
// @todo Should this be moved to XMLSitemapWritier::writeSitemapElement()?
Yes, because I want to alter the operation when this element is added on xmlsitemap.xmlsitemap.inc file line 210. I would create a bacth but $link and $sitemap varaibles are not available inside writeSitemapElement() and changing the hook arguments would be an API change and this is probably not what we want.
So maybe creating a new hook inside writeSitemapElement() would help ? Or making the hook dependant on the $name argument which is sent to writeSitemapElement as first parameter.
The reason behind this is that I need to change the new "chunk", "page" (call it whatever you want) element creation. Atm this is not possible cause the alter hook is not initialized.
EDIT:
It would also help if the hook is moved there and the default implementation is like this:
Instead of
This way it is still backward compatible but for those of us who want to alter other elements, it is then possible to use this hook every time an element is actually processed. (The $sitemap variable is also in $this actually, so it can be sent in the hook if needed.)
Comment #15
Martin. commentedForgot to mention earlier that this is for drupal 7
I created new patch which invokes the
hook_xmlsitemap_elementwhen generateXML is executed and before the element is sent towriteSitemapElement()It sends in empty link array on sitemap object from $thisComment #16
evanjenkins commentedNeeded to add
hook_xmlsitemap_element_alterfor D8.Comment #17
WidgetsBurritos commentedBased on @evanjenkins's patch in #16, I've also added in the change made by @pobster in #13.
Comment #18
WidgetsBurritos commentedOne more patch here. The D7 patch exposed `type` and `subtype` to the hook, so I've added that here as well.
Comment #19
m4oliveiThanks for the patch! Just one note, the D8 patch is missing
hook_xmlsitemap_root_attributes_alter.Comment #20
dave reidWe need to move the discussion about supporting hook_element_alter() being able to skip the current link to a new feature request, this issue should be focused on ensuring that the Drupal 8 version supports the same functionality as the Drupal 7 version.
Revised patch which adds the missing hook_xmlsitemap_root_attributes_alter(), hook documentation, and small fixes.
Comment #21
dave reid@pobster: I think you still might be able to accomplish what you need just by using hook_xmlsitemap_link_alter(), and that way you avoid that link getting selected by the sitemap generation entirely, which would be better for performance. I don't see a need to support this additional feature in this patch.
Comment #22
dave reidFixing some coding standards.
Comment #24
dave reidTested and committed #22 to 8.x-1.x.