Problem/Motivation
There are many different #-prefixed attributes in the Render API - the more, the less merry. Some of these should be considered "internal", where only real edge-case situations would justify their usage outside the core functions processing the renderable arrays. The existence and visibility of internal attributes just increases the learning curve for working with the render API with no benefit.
The following attributes have been suggested as "internal":
#_after_build_done
#_build_id
#_executes_submit_callback
#_is_weight
#_needs_validation
#_processed
#_programmed
#_sorted (debatable)
#_spawned
#_token
#_validated
#_defaults_loaded
#_printed
#_directory
Proposed resolution
Mark internal attributes with an underscore prefix. #foo becomes #_foo. There is no real opposition to this proposal outside whether the change is classified as an "API Change".
Remaining tasks
Patch.
User interface changes
None.
API changes
Theoretically, "internal attributes" are not part of the API, but their names would change and are technically exposed to the end-developer so there's always a chance that this could mess somebody up.
Original report by @webchick
We're now up to ~60 form properties by my 2:00am regex's count. Here's an attempt to make these a little easier to grok:
This patch puts a _ prefix on the following form properties which generally seem to be only used internally to form.inc, or else only used for odd things like creating your own element.
#_after_build_done
#_build_id
#_executes_submit_callback
#_is_weight
#_needs_validation
#_processed
#_programmed
#_sorted
#_spawned
#_token
#_validated
Of course, contrib modules can still set these if they need to; it's just a way of setting apart the "you may need to set this stuff" from the "you probably won't need to set this stuff" stuff. ;)
Comment | File | Size | Author |
---|---|---|---|
#31 | 111079-31.patch | 26.2 KB | lahoosascoots |
#26 | 111079-26.patch | 35.12 KB | lahoosascoots |
#23 | 1111079-23.patch | 22.8 KB | lahoosascoots |
#19 | 111079-19.patch | 14.38 KB | lahoosascoots |
#17 | 111079-17.patch | 24.61 KB | lahoosascoots |
Comments
Comment #1
eaton CreditAttribution: eaton commentedThis gets a HUGE +1 from me. Nothing is lost, as all the properties in question are still accessible if someone ever really needs to hack them. Setting apart the internal 'flags' and so on that the API uses helps keep as much brain space as possible clear for the important things.
Comment #2
moshe weitzman CreditAttribution: moshe weitzman commentednice patch ... i tested and nothing broke. i rendered and submitted a whole bunch of forms.
Comment #3
chx CreditAttribution: chx commentedVery nicely done. BTW. I learned my lesson and the menu patch uses _mid, _pid and such in the building process.
Comment #4
Owen Barton CreditAttribution: Owen Barton commentedJust bumping this - I think this is a great idea, and much more consistent with our _internal naming system for functions.
I'll reroll if there is interest :)
Comment #5
webchickDefinitely, go for it! You might want to wait until the FAPI 3.0 patch is in though, as I imagine that'll change some of this.
Comment #6
Frando CreditAttribution: Frando commentedComment #7
PanchoThis indeed breaks the API, and while we can fix all instances in core, some early contrib modules would get broken.
I'd make this move early in D7.
Comment #8
eaton CreditAttribution: eaton commentedThis doesn't break the API, as all the properties being changed are in fact internal and should not have been used by developers in the first place. Again, though, it's bee months and the patch is out of date. something to kick around for D7.
Comment #9
PanchoOkay, for 99% of modules you are right.Still there are some use cases, where for example #processed or #spawned are needed on the outside. If developers used those properties, their modules will get broken.
So if this is not considered an API break, it's absolutely okay for me. I just didn't expect this to be commitable anymore, but am otherwise a strong supporter of "The drop is always moving"!
Bumping back to D6 for now - let others decide.
Comment #10
Owen Barton CreditAttribution: Owen Barton commentedThere is absolutely no way this will get into Drupal 6, even though it is not an API change (really!) ;)
Comment #11
eaton CreditAttribution: eaton commentedI agree -- apologies if my post confused matters. I agree wholeheartedly that it shouldn't go in for D6.
Comment #12
Jaza CreditAttribution: Jaza commentedBump. (And +1).
Comment #13
valthebaldI hope it's not too late to add this to D8
Comment #14
thedavidmeister CreditAttribution: thedavidmeister commentedFWIW - I disagree that #sorted is "internal". I've used it a few times in the past and the docs say this:
I haven't done much research to see what this would change, if anything, but the scope of this issue should be the Render API in general and not just the FAPI. It would just add to the confusion if some renderable arrays had "internal properties" and others did not. I presume we'd include:
drupal_render():
_theme():
Somewhat related issue #2024743: Document "reserved variables" for renderables to avoid conflicts with drupal_render(), the FAPI, and _theme().
Patch needs a reroll:
Comment #15
thedavidmeister CreditAttribution: thedavidmeister commentedComment #16
lahoosascoots CreditAttribution: lahoosascoots commentedI'm going to reroll patch from #13.
Comment #17
lahoosascoots CreditAttribution: lahoosascoots commentedI'm Matt, a new contributor in the Sprint at Austin DrupalCon. I've attached the reroll from #13. Fingers crossed.
Comment #19
lahoosascoots CreditAttribution: lahoosascoots commentedRemoving changes to default.settings.php that likely caused the failures.
Comment #20
lahoosascoots CreditAttribution: lahoosascoots commentedSwitching to needs review.
Comment #23
lahoosascoots CreditAttribution: lahoosascoots commentedAdding in some new (or moved) uses of #sorted that I found.
Comment #24
lahoosascoots CreditAttribution: lahoosascoots commentedComment #26
lahoosascoots CreditAttribution: lahoosascoots commentedFound a few more usages. One last try.
Comment #27
thedavidmeister CreditAttribution: thedavidmeister commentedI still really don't think #sorted is "internal". If #sorted is internal we should consider making #weight internal too as they both address similar use cases (from the perspective of the "external" developer).
Comment #28
lahoosascoots CreditAttribution: lahoosascoots commentedI could go either way with it, but I'm not really in the position to make the determination. If someone can give a definitive answer I'll fix the patch.
Comment #29
thedavidmeister CreditAttribution: thedavidmeister commentedOK sure. Well, for the next person who comes along, the summary of my take on #sorted is:
- The documentation for drupal_render() directly mentions using it for a common use-case (rendering anything pre-sorted by a db query)
- #sorted provides a clear and practical alternative for #weight, which is an attribute I don't think anyone would argue is "internal"
- Setting #sorted before calling drupal_render() improves site performance, and so should be encouraged
- I have personally used it multiple times, and advised other people to use it (especially when altering existing data structures), so there are definitely use-cases "in the wild"
The attributes we mark as "internal" with a _ will likely be considered "discouraged" or "scary" by developers who might be considering using them and will inevitably be treating them with a degree of suspicion (well *I* don't know what this attribute does or why it's marked internal, better leave it to The Core Guys and figure out some other way to fix my problem). #sorted is not scary or discouraged at all, in fact it's very easy to understand/use and definitely encouraged!
Comment #30
chx CreditAttribution: chx commented#sorted and #weight is not internal.
Comment #31
lahoosascoots CreditAttribution: lahoosascoots commentedRemoved any changes to #sorted.