$form['#attributes']['class'] is currently implemented as a string, but multiple classes are allowed, and that's currently solved by cat'ing onto the end of it ($form['#attributes']['class'] .= ' classname'), but this is bad. Since class in this context is actually a list of classes, we need to convert this element into an array.
I'm by no means familiar with 99.9% of the internal workings of Drupal 'cause I haven't looked at it yet. DamZ mentioned that we could do this in a backwards-compatible manner, using is_array(), and I'm down for that... but personally with something like this, I'd prefer to have a patch that would convert them all at once. Is this kosher? It would most likely be a huge patch. I just don't like the idea of adding cruft to the code.
Also, tests will have to be updated (...or written?) to test the class element working as it should.
Comment | File | Size | Author |
---|---|---|---|
#42 | drupal.class-array.42.patch | 106.03 KB | sun |
#40 | drupal.class-array.40.patch | 105.45 KB | sun |
#37 | drupal-class-326539.patch | 97.67 KB | RobLoach |
#36 | drupal.class-array.35.patch | 105.64 KB | sun |
#34 | drupal.class-array.patch | 101.16 KB | sun |
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedHere is a started patch.
Comment #2
chx CreditAttribution: chx commentedI do not like this patch, it affects an important function in a rather arbitrary manner. Why implode with a space...?
Comment #3
cha0s CreditAttribution: cha0s commentedHere's a patch that leaves backwards compatibility in the dust... also I created a _drupal_attribute function to handle rendering individual attributes. That takes out the generalized "if array then implode with spaces" and targets that behavior to only the 'class' case.
Comment #4
RobLoachWhoa, this is huge... Could you make it use both a string or an array to save on making changes everywhere?
Comment #5
RobLoachCha0s, what are your thoughts on something like this....
Comment #6
cha0s CreditAttribution: cha0s commentedWhile I'm somewhat a supporter of backwards compatibility personally, as far as I know, the philosophy in Drupal is to change something and no leave cruft around to handle old behavior. Based on that impression I get, I don't think we should be supporting strings as classes.
For one thing, how could someone interfacing with your code add to/remove from your classes without string manipulation? That's extremely dirty; the reason I propose the change to begin with.
EDIT: The best solution I can think of to reconcile that behavior would be to add some rule to the Coder module to check for this, but from my experience of actually making the changes, that's probably going to raise a fair amount of false positives.
Comment #7
chx CreditAttribution: chx commentedwell, theme table comes to my mind as something that supports different data types. but then it's obviously obscenely complex.,, so I am on the fence alas whether i like or not this. It should be noted despite noone said in the isseu the patch actually reacts to my earlier comment and only suppprts arrays for classes so other attributes wont be imploded by a space (or anythign else).
Comment #8
cha0s CreditAttribution: cha0s commentedGot a new patch rolled.
Comment #9
cha0s CreditAttribution: cha0s commented... Rolled again to remove the function call.
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedThe last submitted patch failed testing.
Comment #11
ultimateboy CreditAttribution: ultimateboy commentedWell.. the above patch is not even close to applying and now that #493746: Enhance drupal_attributes() for multiple valued values went in, I think it's time to bring this back onto the table. I kinda started from scratch with this patch.
Comment #13
ultimateboy CreditAttribution: ultimateboy commentedAfter talking with JohnAlbin in IRC and seeing his post http://drupal.org/node/493746#comment-1858392 I think everything covered by this patch will be consumed by the forthcoming patch that JohnAlbin is working on. There's really no need for this issue any more.
Comment #14
JohnAlbinHeh. Actually, I think it might be quicker to do this issue as a follow up to #493746: Enhance drupal_attributes() for multiple valued values. But let me paste my previous comment here:
Regarding the already-committed change to drupal_attributes() in #493746, it isn't going to help much unless we actually go through all of Drupal’s code and make all 'class' implementations into arrays.
Otherwise, at any given point, we won't know if 'class' is an array or a string. And we will just end up changing this awkward code:
with this awkward code:
Which, you may notice, is actually longer then the previous awkward code.
Here's my half-implemented patch merged with ultimateboy's patch. Its still not yet complete. I searched through D7's code base for 'class' and only got as far as changing stuff through profile.admin.inc. So there's more work to do.
Comment #15
JohnAlbinI finished converting all the 'class' bits I could see. Let's see what the testbot has to say.
[edit: 38 fails, 22956 exceptions. Woot! ;-) ]
Comment #17
JohnAlbinAnother try.
[edit: 3 fails, 110 exceptions. Getting closer.]
Comment #19
JohnAlbinAnother try. Also re-rolled after the comment rendering patch went in.
Comment #20
JohnAlbinWhoops. parse error after re-roll from missing ).
Comment #21
JohnAlbinSuccess! Ok, who wants to review the 100k patch? :-D
It’s 90% wrapping strings in
array()
Comment #22
ultimateboy CreditAttribution: ultimateboy commentedDont have time to wrap these changes into a patch.. but a quick review gives me the following. After reading every line of this patch, all I've got are a few code comment issues.. fantastic.
Given how large this patch is, its probably best to get a few more eyes on it, but from my point of view, it is good to go.
[edit] I simply read the patch, didnt actually test it out. I have no idea if every instance of "class" was covered, but everything that is changed by this patch is good.
Comment #23
JohnAlbinRe-rolled with ultimateboy's comment change.
Comment #25
JohnAlbinRe-rolled.
Comment #27
ultimateboy CreditAttribution: ultimateboy commentedRe-roll
Comment #29
JohnAlbinPlease review while its still fresh! :-D
Comment #30
ultimateboy CreditAttribution: ultimateboy commentedI re-looked over this and am happy.. but I really want another pair of eyes on this many changes.
Comment #32
Zarabadoo CreditAttribution: Zarabadoo commentedI am subscribing to this.
Comment #33
RobLoachWent through and found one...............
Should that be
$element['#attributes']['class'][] = 'form-' . $element['#button_type'];
?Beer-o-mania starts in 12 days! Don't drink and patch.
Comment #34
sunAll I ever wanted.
Some hunks failed. Incorporated RobLoach's finding.
Comment #35
yched CreditAttribution: yched commentedI'm afraid Field UI just added a couple more...
Comment #36
sunAdditionally accounting for new code, especially the new code that has no tests yet (field_ui).
Comment #37
RobLoachThere was an extra end parameter in field_ui.admin.inc..........
Errr, here!
Comment #38
webchickI think this is a good change, and would like to commit it. Is it possible to get one more review/sanity check?
Comment #40
sunRe-rolled for new code.
And did another sanity check.
Comment #41
webchickNeeds another re-roll. :(
Comment #42
sunRe-rolled for new code + additional sanity check.
Comment #43
webchickOk! Testing bot comes back green. This is a great improvement for themers. Committed to HEAD.
Please document this in the theme upgrade guide http://drupal.org/update/theme/6/7
Comment #44
ultimateboy CreditAttribution: ultimateboy commentedThis is really module update and not theme. Themes cannot really take too much advantage of this at this time. This is more of a coding standards change in modules, so I updated: http://drupal.org/update/modules/6/7#class_attribute_array
Comment #45
ultimateboy CreditAttribution: ultimateboy commentedTag
Comment #46
webchickOops, my mistake. Thanks, ultimateboy!