Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
API page: https://api.drupal.org/api/drupal/core!includes!common.inc/function/drup...
The drupal_render documentation has instances of setting class to a string like:
'#attributes' => array('class' => 'foo'),
which should really be:
'#attributes' => array('class' => array( 'foo')),
Setting the class attribute to a string will work for some render arrays, but not for any that have pre_render functions that expect class to be an array. Any similar instances of this error in other Drupal 8 docs should also be corrected.
Comment | File | Size | Author |
---|---|---|---|
#15 | drupal8-class-attribute-2304399-15.patch | 5.59 KB | undertext |
#12 | drupal8-class-attribute-2304399-12.patch | 5.72 KB | undertext |
#6 | drupal8-class-attribute-2304399-6.patch | 928 bytes | er.pushpinderrana |
#6 | interdiff-2304399-2-6.txt | 505 bytes | er.pushpinderrana |
Comments
Comment #1
jhodgdonThanks, good idea to fix this! If you find other cases of documentation doing that, please file new issues. Let's get drupal_render() fixed on this issue.
By the way, the Drupal 7 version of the function doesn't have this example in it.
Comment #2
er.pushpinderrana CreditAttribution: er.pushpinderrana commentedPlease review.
Comment #3
jhodgdonPerfect! Thanks!
Comment #4
alexpottThe thing is that it does not have to be an array - should we be documenting this here?
Comment #5
jhodgdonIt doesn't *have* to be an array, but it usually is an array. I don't think it's a bad idea to have the examples changed to use arrays? We're not changing the documentation that talks about the class attribute, just some code samples that have to do with using the #theme_wrappers property anyway.
Of course, if we're doing that, I just noticed that one of the examples, just below where this patch ends, is still not an array:
Comment #6
er.pushpinderrana CreditAttribution: er.pushpinderrana commentedDid changes as mentioned in #5, please review updated patch.
Comment #7
jhodgdonI think this is OK... alexpott: see #5 for why I think this should probably be done, but I'll let you make the decision.
Comment #8
webchickComment #9
samuel.mortensonIf it helps, the functions in form.inc that expect class to be an array are:
I'm not sure if we should ever suggest that people set class to a string given the amount of functions that rely on it being an array.
Comment #10
alexpottSo let's also remove all instances where we don't set class to an array...
are the only places I can find where we do this.
Comment #11
alexpottComment #12
undertext CreditAttribution: undertext commentedComment #13
undertext CreditAttribution: undertext commentedComment #15
undertext CreditAttribution: undertext commentedArgh, unix-style line endings. Trying one more time
Comment #16
undertext CreditAttribution: undertext commentedComment #17
jhodgdonThe patch looks good to me, and fixes all locations identified by alexpott in#10. Plus, testbot agrees that the tests still pass. Should be good to go, thanks!
Comment #18
alexpottCommitted 0d99a0c and pushed to 8.x. Thanks!
Comment #21
m1r1k CreditAttribution: m1r1k commented