r/programming • • Jan 05 '11

Drupal 7 released.

http://drupal.org/drupal-7.0
222 Upvotes

259 comments sorted by

View all comments

Show parent comments

5

u/mikey_p5151 Jan 06 '11 edited Jan 06 '11

While this does perfectly describe the problems with previous versions of Drupal, I think quite a bit has changed since you have been around and committing. Any entity that properly implements field_attach_* hooks has a consistent data structure that can be loaded, modified in place, and saved without concern over whether the $form fields match the structure that the saving function (and ultimately field_attach_insert and field_attach_update) expect. It just works. Seamlessly.

As to mapping form field to entity fields, of course that will never match and any system that claims to integrate those items ends up being what Drupal was, not what it is now. field_attach_form and field_attach_form_submit are what glues these two items in a default way, but keeps the data structure of the object 100% separate from the values of the form itself. I'd suggest anyone that has fought this code in the past, write their own entity module that is fieldable, and use these functions to understand how they actually work and how the data structures work.

But where it gets really problematic is that many contrib modules (out of ignorance) don't even bother translating back from $form to $node, and hardcore their node_save() callbacks to accept only the $form values.

This is just silly. We aren't talking about 4.7 and 5.x contrib modules. We're talking about Drupal core, and it's changed alot. Not to mention nothing prevented users from writing Drupal 5.x or 6.x modules that DID NOT have this problem. Project module (for all it's cruft) actually does an awesome job of putting it's metadata in consistent, repeatable, and sane places that work whether it's getting a form value or a $node object.

Nothing is stopping (other than lack of time and motivation) fixing the node preview issue once and for all, the object I get back from field_attach_form_submit() has all the fields in the exact same place they are when they are returned by entity_load() and field_attach_load().

6

u/UnConeD Jan 06 '11

I've actually dug through quite a lot of D7 code. And noticed all the "Fix this in D8" comments that show the issues I've raised are still there.

Besides, you're focusing on the minor complaints and ignoring the big ones I started out with. But since you insist, take a look at node.pages.inc:90-99 ($node being stateful, in direct contradiction with how Form API is designed) and session.inc:106-127 (global $user is a fake) and tell me these are the hallmarks of a well-designed system. None of these things matter for vanilla stuff, it only comes out when you try to push the system into more advanced ways of interaction. You know, doing experimental development, pushing the edge, what Drupal used to pride itself on?

As for core vs contrib...as the rest of this thread shows, you can't look at Drupal core in isolation. In practice, the vast majority of people do rely on contrib modules, and Drupal.org does not make any effort to suggest doing otherwise. It is dishonest to pretend that the ultra strict principles of Drupal core, which only arise as a result of a strict vetting process, will spontaneously radiate outward to contrib modules and the sites that use them. It has never happened, and it won't change any time soon.

As for your accusations about "poor taste"... I'm posting technical arguments in response to a direct challenge about Drupal weaknesses, on a site that isn't Drupal.org. If that somehow offends you, tough luck.

1

u/mikey_p5151 Jan 06 '11

I should back up a bit and acknowledge that Node module is mess with it's revision handling and the fake 'hooks' of hook_insert, etc, that are really just named callbacks. And beyond that user.module is even worse with the fake user global, the abomination that is users.data and so on. Comment.module is even worse, and has led to some of the worse "WTF" moments I've ever seen in Drupal code.

Despite this, I do feel that serious changes are being made that facilitate good, clean separation between in new code (I've been working on new modules that define their own entities, and it's about at least 100x cleaner than node.module so far). This is the type of change that shows that Drupal is (slowly) moving in the right direction. While I didn't work personally on any of the issues you mentioned for Drupal 7, I can see that there is the possibility and groundwork laid for fixing them in a proper way in the future.

As far as core vs. contrib, I guess on some level I understand that frustration with crappy contrib, and there sure is plenty of it, but I don't see that Drupal core itself is responsible for it. In some ways with the node hooks sure, but if I want to define my own objects, write my HTML and form, and write my own SQL, nothing is stopping me. For a long time Views has been an excellent example of this, (the editing and saving of a view, not the function of views itself) separating CRUD from forms very well, and introducing exportables to the mix as well.