07 August 2012

The node add/edit form shows the "XML Sitemap" fieldset for any node when the user has the "administer xmlsitemap". However, even administrative users deserve some level of usability tweaks. However, the module_list() function sorts by weight and then by name, and the module's "x..." name causes it to fire last even among modules with the same weight. This is a prime example of the shortcomings that can arise when there are within-hook prerequisites.

Given the infrequency of such problems, I decided to simply deal with it. To programmatically hide the xmlsitemap fieldset from certain nodes without any major code adjustments, you simply need to make xmlsitemap_node load before your module (the weight must be less than your module's weight):

UPDATE {system} SET weight = -1 WHERE name = 'xmlsitemap_node'

And then hide the fieldset using #access settings as you normally would within your module's form_alter.

In Drupal 7, there is a much (much much much) better solution when they added hook_module_implements_alter to module_implements. That function would allow you to enforce (and cache) within-hook prerequisites so that module X could ensure that module Y's hook_form_alter is called first.

Someone else has also looked into this, but I did not find any evidence that there was enough demand to justify new custom settings on the node type form.


blog comments powered by Disqus