Drupal and non-determinism

tags:

I was just working on a client site and had an epiphany as to why working with Drupal continues to be a frustrating experience for me.

As flexible and powerful as Drupal truly is, there is still an unacceptable level of non-determinism involved in working with Drupal whether it be in working with existing modules, theming or doing custom development.

I have been working with a moderately complex content (CCK) type and trying to get the form for this content type to display in a certain way. Most of the elements of this form are managed by CCK. Others are part of core Drupal. And a few (location and rating data) are parts of other contrib modules. One of my goals was to order the form elements in a particular way, which Drupal is supposed to make possible via the FormAPI's '#weight' property. Simple enough, right? Form elements will be ordered with the lowest weighted elements displaying towards the top of the form.

As it turns out, it's nearly impossible to order form elements precisely because the ordering of the elements has as much to do with the order in which modules are called as the weights of the form elements themselves.

While the CCK field properties can be ordered relative to each other using the pleasant CCK interface, there's no assurance that other modules won't intersperse their fields irregularly throughout your otherwise nicely sorted form. To account for this, you might write your own module and implement a hook_form_alter() in order to change the weights of form elements. This may or may not work.

In my case, I had to go into the database directly and alter the weights of the CCK fields manually to get the desired order. But the next time someone uses CCK's interface to manage these fields, the weights will likely be reset, breaking the order once more.

Drupal advertises a means to do exactly what I want (ordering form elements precisely), but never really delivers. This leads to frustration and compromise.

Contrib modules can be another fine source of undesired randomness. After enabling the "vertical tabs" module on a client site, I discovered I could no longer visit the CCK management page for a certain node type. Apparently "vertical tabs" performs a drupal_render() on the form of the content type in question when rendering the CCK management page. One of the modules involved with this node type performs a drupal_goto() redirect if a certain condition isn't met, which just happens to be the case when rendering the CCK management page. So going to the CCK management page results in a redirect to an unrelated page. I would probably consider this the fault of the module doing the redirect, however, who would ever suspect that a Drupal form would be fully rendered on any other page but the form itself? This type of unpredictability makes working with Drupal an often painful experience.

There is certainly a lot more right with Drupal than wrong. But that doesn't make its quirks and shortcomings any easier to deal with.

A language can be recognised by a deterministic pushdown automata iff there exists some LR(1) grammar for that language. As there are context free languages that do not have any LR(1) grammar describing them, NPDA != DPDA. As these results are very well known and will usually get treated in a course on compilers, I'm not sure if that answers your question: are you perhaps looking for intuition behind this fact?