altering an altered form
Hi, For the new drupal.hu, I am trying to force the path and node options form groups to be always opened on some node types, and path removed on others. Since the path stuff is added with form_alter, my only way if I understand it correctly is to name my module something post "p", so that it is called after the path module, or manually tinker with the weight of modules in the system table. Am I right, or are there better options? Gabor
On Wed, 07 Jun 2006 19:51:13 +0200, Gabor Hojtsy <gabor@hojtsy.hu> wrote:
understand it correctly is to name my module something post "p", so that it is called after the path module, or manually tinker with the weight of modules in the system table. Am I right, or are there better options?
system.weight has been added specifically for this purpose: altering altered forms. Use hook_install to set your system.weight accordingly. Regards NK
Does the system.weight affect nodeapi as well? I need a module to load after another so this would be a perfect solution. On 6/7/06, Karoly Negyesi <karoly@negyesi.net> wrote:
On Wed, 07 Jun 2006 19:51:13 +0200, Gabor Hojtsy <gabor@hojtsy.hu> wrote:
understand it correctly is to name my module something post "p", so that it is called after the path module, or manually tinker with the weight of modules in the system table. Am I right, or are there better options?
system.weight has been added specifically for this purpose: altering altered forms. Use hook_install to set your system.weight accordingly.
Regards
NK
On Thu, 08 Jun 2006 00:36:23 +0200, James Gilliland <neclimdul@gmail.com> wrote:
Does the system.weight affect nodeapi as well? I need a module to load after another so this would be a perfect solution.
Yes. system.weight defines calling order always.
Op donderdag 8 juni 2006 05:19, schreef Karoly Negyesi:
Yes. system.weight defines calling order always.
weights aer nothing more then another layer. What if you alter an altered form, where the other one has a weight set? weights don't really solve any issue, they just move the issue of conflicts one level away. I beleive we should get rid of the weights in favour of something like: * roundtrips. A hook not only returns a value, but also a flag whether the current hook call should be * Stopped right now, and reran from start, but then containing the current data. * Continued and stopped after a complete roundtrip, just like Drupal does now. * Continued and reran after a complete roundtrip, but then containing the current data. This is particularly hard because you need to build in measures to not end in endless loops. * Hook registration. Instead of looking around if a hook exists on each pageload, all modules register their hooks. A central API *and* a UI can then allow us to reorder, switch on/off, ignore etc hooks. Yes, both are a lot of work. And no, I am not volunteering :) And yes,I feel I am alowed to speak about this, without actually coding it. -- | Bèr Kessels | webschuur.com | website development | | Jabber & Google Talk: ber@jabber.webschuur.com | http://bler.webschuur.com | http://www.webschuur.com | Drupal upgrade repareert kritiek beveiligingslek: http://help.sympal.nl/drupal_upgrade_repareert_kritiek_beveiligingslek
weights aer nothing more then another layer. What if you alter an altered form, where the other one has a weight set? weights don't really solve any issue, they just move the issue of conflicts one level away. That is very true.
* roundtrips. A hook not only returns a value, but also a flag whether the current hook call should be
* Hook registration. Instead of looking around if a hook exists on each pageload, all modules .... Both are doable but they won't solve a major problem - non-deterministic behaviour of the updates. There is a need for very strict discipline what alters in what order, otherwise the results might not be what you expect.
It is solvable, but is the added complexity going to be worth it?
Yes. Messing around with weights is a stopgap solution for 4.7, but indeed we need something better. And order of operations is only getting more needed rather with less, as we work more with extending existing behaviours through form_alter, db_rewrite_sql, etc. A concrete example: I'm working with a module that wants to come after user.module but before node.module. Yes, I can reset the weights of one or both of those core modules, but it's an obvious hack that will fail as soon as someone else tries to do the same. An limited and trouble-prone alternative right now is to explicitly call another module's method. If, e.g., my form_alter needs to come before node.module's, I can call node_form_alter() at the end of my example_form_alter() call. The issue and both of Ber's suggestions seem worth some more attention. * roundtrips. * Hook registration. Key to this is that it isn't absolute order of modules that's the issue; it's the order of particular calls. It's quite feasible, for example, that example_form_alter needs to come before node_form_alter, but example_menu after node_menu. Maybe a simple (?) solution would be to register not all hooks but only their dependencies. function example_hook_dependencies() { return array( 'form_alter' => array( '#before' => array('node'), '#after' => array('user') ), 'menu' => array( '#before' => array('node') ) ); } (Or, alternately, I suppose, these data could be coded into an install metadata file.) Then module_invoke_all evaluates these dependencies and orders its calls accordingly.
Op vrijdag 9 juni 2006 16:08, schreef Nedjo Rogers:
Maybe a simple (?) solution would be to register not all hooks but only their dependencies.
Sounds like this will fix Vladimirs problem (complexity not worth the gain, valid point!) and the current issue of our hooks not being flexible. If you add this in a .install, or some other run-once file, you can still change this, maybe even trough some exotic (as in: advanced users only) UI afterwards. Only a few modules, and the various distros (install profiles) need to care about this one-time registration of hooks. And when they do not register anything, nothing is lost either. Then the default Drupal way (run them alphabetically) will work as it always did. Bèr -- | Bèr Kessels | webschuur.com | website development | | Jabber & Google Talk: ber@jabber.webschuur.com | http://bler.webschuur.com | http://www.webschuur.com | Drupal upgrade repareert kritiek beveiligingslek: http://help.sympal.nl/drupal_upgrade_repareert_kritiek_beveiligingslek
On 6/10/06, Nedjo Rogers <nedjo@islandnet.com> wrote:
Maybe a simple (?) solution would be to register not all hooks but only their dependencies.
function example_hook_dependencies() { return array( 'form_alter' => array( '#before' => array('node'), '#after' => array('user') ), 'menu' => array( '#before' => array('node') ) ); }
This would be an extremely useful mechanism, and I think that for the vast majority of cases, it would work very well. However, there would be some cases where dependency conflicts could occur, and I envision that if/when these happen, they could potentially get very messy. E.g. let's say 3 modules in core (A, B, and C), have no dependencies defined for hook_form_alter(). Then the contrib modules D and E come along, and each define their own dependencies. How would this case be handled: - Module D's hook must be called after module A, and before modules B and C. - Module E's hook must be called after module C, and before module A. I can think of no clean solution to the problem above. But then again, I was never much good at those maths problem-solving puzzlers. Maybe the more outside-square-thinking among us can see a way around cases such as this. :p Cheers, Jaza.
On 09 Jun 2006, at 4:08 PM, Nedjo Rogers wrote:
(Or, alternately, I suppose, these data could be coded into an install metadata file.) My solution to the problem involves separating out the menu system, and it's actual nature.. the callback system.
Thus allowing you to register multiple callbacks, of different types. It should be able to pick up what hooks a module implements when it is enabled, and then keep a pre-sorted callback order. (in the fapi callback format, preferably). When it comes down to it, a hook is just an automatically registered callback. and the big problem with using a hook over a registered callback, is you have no way to give extra information about it. -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
Adrian Rossouw wrote:
On 09 Jun 2006, at 4:08 PM, Nedjo Rogers wrote:
(Or, alternately, I suppose, these data could be coded into an install metadata file.) My solution to the problem involves separating out the menu system, and it's actual nature.. the callback system.
Thus allowing you to register multiple callbacks, of different types.
It should be able to pick up what hooks a module implements when it is enabled, and then keep a pre-sorted callback order. (in the fapi callback format, preferably).
When it comes down to it, a hook is just an automatically registered callback. and the big problem with using a hook over a registered callback, is you have no way to give extra information about it.
Adrian - are you planning to work on this. Would be very very useful. Even if you wrote a design doc for it and left the coding to others. @Boris - Perhaps you can free up Adrian to work on this doc. Is a prerequisite for fapi 2.0.
On 10 Jun 2006, at 4:00 PM, Moshe Weitzman wrote:
Adrian - are you planning to work on this. Would be very very useful. Even if you wrote a design doc for it and left the coding to others.
@Boris - Perhaps you can free up Adrian to work on this doc. Is a prerequisite for fapi 2.0.
Core wise i've just been a touch busy with the code for the split templates (err.. phptemplate 2.0 essentially) I will get to it very soon (seeing as how it is getting close to the date). -- Adrian Rossouw Drupal developer and Bryght Guy http://drupal.org | http://bryght.com
participants (9)
-
Adrian Rossouw -
Bèr Kessels -
Gabor Hojtsy -
James Gilliland -
Jeremy Epstein -
Karoly Negyesi -
Moshe Weitzman -
Nedjo Rogers -
Vladimir Zlatanov