As the implementation of hook_xmlsitemap_links() is used differently than in the past, it should be better to rename the hook. Using the same name for the hook just causes problems to third-party modules that would implement the hook, and which don't have a way to understand which XML sitemap is installed, and which result it is expecting from the hook.
Drupal can change arguments passed to a hook function in a Drupal version, but Drupal version is the focal point.
Comments
Comment #1
avpadernoRather than referring to Drupal 6 1.x branch, I am referring to Drupal 5 branch.
Comment #2
dave reidI'm not in favor of renaming the hook. As I posted in #490518: Incompatibility with XML sitemap 2.x:
Comment #3
avpadernoThe problem is not the developers of third-party modules, but who installs XML sitemap. Usage statistics show there are a lot of people using 6.x-0.x-dev, even though that version is not listed in the project page.
If a hook is used differently from before, or it is required to return a different value, it should be renamed.
That is normally called consistent API; if a function has parameters of different type (or returns a different value) than before, it is renamed.
Comment #4
Anonymous (not verified) commentedDave when I first read Kiam's request I was nearly against it as well; but his argument is really a valid one. If we provide a hook for Drupal 6 that is different in two disparate versions of the same module then we must rename the API because of the user and not the developer.
Comment #5
dave reidI just have to respectfully disagree. I'll try to make my point a little clearer. hook_xmlsitemap_links() implies that the function just gets and returns all the link data. Whatever code that calls the hook can decide what to do with that data. For instance, when used in the batch rebuild process, we write those records to the database. At some point that same data could be used to write directly to a file in the calling code. But it's not the hook's job to do that and it would be very un-Drupal-like to do so. It's not hook_xmlsitemap_write_links_to_file(). If anything I believe the 6.x-1.x hook should be renamed to hook_xmlsitemap_write_links(), because frankly that's what it does. What if down the road we need to do something else with the same data? We have to add a different hook that fetches the *exact* same data, but does something different with it when we could just have one hook that returns the data. When the hook just provides the data, we retain a huge amount of flexibility down the road.
For example:
hook_blocks() - returns a list of blocks. It doesn't save them to the database. That's the responsibility of the block.module code that calls this hook.
hook_action_info() - same thing with a list of actions
hook_filter() - same thing with a list of filters
hook_menu() - same thing with a list of menu items.
There is only currently *one* module for Drupal 6 that implements hook_xmlsitemap_links() which is Gallery, which is broken for both 6.x-1.x and 6.x-2.x. We can choose the right path now for both our end users and developers.
Comment #6
avpadernoAs long as the problem is resolved, any solution is good.
Debating on what is the correct name of the hook does not take to any places. As a matter of fact, the hook name used is the same used in 5.x because the implementation is compatible (not passing 'xml' to a 5.x implementation of the hook causes it to act in the same way of the 6.1.x implementation).
The problem here is that the same hook is used in 6.2.x in a different way. As 6.2.x came after, I think that saying it is 6.1.x the branch that must use a different name is a little odd; in the same way, I can make a module that uses hook_user() differently from Drupal, and pretend that Drupal change name to the hook_user() hook it uses.
Comment #7
webchickCould someone post a before/after snippet of 1.x vs. 2.x hook_xmlsitemap_links() for comparison? That'd make it easier for people not as familiar with the code to chime in as requested at #448000-115: Big, Over-Arching Sitemap Architecture Discussion (tm).
Without having that in front of me though, I do agree with Dave at #5. Hooks that merely return data are more useful, because they allow for multiple uses of that data. For example, perhaps someone wants to write their own extension module which invokes hook_xmlsitemap_links() but doesn't store it in the database in any way. Someone could create a "status" page in their module which shows all of the possible links and which ones are being written to the sitemap. And so on.
I somewhat understand the concern for backwards compatibility, but not really. Drupal breaks APIs all the time between major versions, and developers are used to that. Here's hook_perm() in 6.x and below:
And in 7.x:
In contrib, a 1.x => 2.x version change implies that the same types of API changes may be present, and therefore it would not be unexpected for hook definitions to change. Just document it in CHANGELOG.txt or similar.
Dave also mentioned that only one module out there right now is actually implementing this hook and it's currently broken, so it seems like making this improvement has a negligible effect on any existing code.
Comment #8
dave reidHere's the current implementation from xmlsitemap_node.module:
Current 6.x-1.x (6.x-1.0-beta0) which saves the data to the database:
6.x-1.0-beta5 which wrote the data to a sitemap XML file:
6.x-2.x which just returns the data:
Comment #9
avpadernoEDIT: I forgot what the code I developed was like. Version beta5 code is not anymore in the development snapshot, and what it did is not actually something to worry about.
Comment #10
webchickYeah, I think as long as there's an API function like xmlsitemap_output_link() which writes a single link row to file/database/whatever, changing the return value of hook_xmlsitemap_links() as Dave describes makes sense. Someone who wanted to could still emulate the old behaviour by module_invoke_all()ing 'xmlsitemap_links' and then looping through the results to call said API function.
I don't see any reason to re-name the hook in either version; in both cases, you're grabbing the list of links defined by a given add-on module. The only difference is that the 2.x version de-couples the listing behaviour from the writing behaviour for a bit more added flexibility.
Comment #11
avpadernoThe difference is in which data type the module expect from the hook implementation.
Comment #12
Anonymous (not verified) commentedMarking as won't fix.