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. ;)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eaton’s picture

Title: Differentiate internal from user-settable form properties » FormAPI: Differentiate internal from user-settable form properties

This 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.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

nice patch ... i tested and nothing broke. i rendered and submitted a whole bunch of forms.

chx’s picture

Very nicely done. BTW. I learned my lesson and the menu patch uses _mid, _pid and such in the building process.

Owen Barton’s picture

Just 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 :)

webchick’s picture

Definitely, 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.

Frando’s picture

Status: Reviewed & tested by the community » Needs work
Pancho’s picture

Version: 6.x-dev » 7.x-dev

This 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.

eaton’s picture

This 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.

Pancho’s picture

Version: 7.x-dev » 6.x-dev

This doesn't break the API

should not have been used by developers in the first place

Okay, 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.

Owen Barton’s picture

Version: 6.x-dev » 7.x-dev

There is absolutely no way this will get into Drupal 6, even though it is not an API change (really!) ;)

eaton’s picture

I agree -- apologies if my post confused matters. I agree wholeheartedly that it shouldn't go in for D6.

Jaza’s picture

Version: 7.x-dev » 8.x-dev

Bump. (And +1).

valthebald’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
23.09 KB

I hope it's not too late to add this to D8

thedavidmeister’s picture

Title: FormAPI: Differentiate internal from user-settable form properties » Render API: Differentiate internal from user-settable renderable array attributes
Issue summary: View changes
Status: Needs review » Needs work

FWIW - I disagree that #sorted is "internal". I've used it a few times in the past and the docs say this:

The child elements of this element are sorted by weight using uasort() in \Drupal\Core\Render\Element::children(). Since this is expensive, when passing already sorted elements to drupal_render(), for example from a database query, set $elements['#sorted'] = TRUE to avoid sorting them a second time.

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():

#_defaults_loaded
#_printed

_theme():

#_directory

Somewhat related issue #2024743: Document "reserved variables" for renderables to avoid conflicts with drupal_render(), the FAPI, and _theme().

Patch needs a reroll:

tdm:d8 thedavidmeister$ git apply 111079-13.patch 
error: patch failed: core/includes/common.inc:3741
error: core/includes/common.inc: patch does not apply
error: patch failed: core/includes/form.inc:2931
error: core/includes/form.inc: patch does not apply
error: patch failed: core/includes/menu.inc:1154
error: core/includes/menu.inc: patch does not apply
error: patch failed: core/lib/Drupal/Core/Entity/EntityViewBuilder.php:230
error: core/lib/Drupal/Core/Entity/EntityViewBuilder.php: patch does not apply
error: patch failed: core/lib/Drupal/Core/Form/FormBuilder.php:326
error: core/lib/Drupal/Core/Form/FormBuilder.php: patch does not apply
error: core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php: No such file or directory
error: core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php: No such file or directory
error: core/modules/system/lib/Drupal/system/Controller/FormAjaxController.php: No such file or directory
error: core/modules/system/lib/Drupal/system/Tests/Common/RenderTest.php: No such file or directory
error: patch failed: core/modules/system/system.admin.inc:139
error: core/modules/system/system.admin.inc: patch does not apply
error: patch failed: core/modules/tracker/tracker.pages.inc:154
error: core/modules/tracker/tracker.pages.inc: patch does not apply
error: patch failed: core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php:427
error: core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php: patch does not apply
thedavidmeister’s picture

Issue tags: +Needs reroll
lahoosascoots’s picture

I'm going to reroll patch from #13.

lahoosascoots’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
24.61 KB

I'm Matt, a new contributor in the Sprint at Austin DrupalCon. I've attached the reroll from #13. Fingers crossed.

Status: Needs review » Needs work

The last submitted patch, 17: 111079-17.patch, failed testing.

lahoosascoots’s picture

FileSize
14.38 KB

Removing changes to default.settings.php that likely caused the failures.

lahoosascoots’s picture

Status: Needs work » Needs review

Switching to needs review.

The last submitted patch, form.inc_35.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 19: 111079-19.patch, failed testing.

lahoosascoots’s picture

FileSize
22.8 KB

Adding in some new (or moved) uses of #sorted that I found.

lahoosascoots’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 23: 1111079-23.patch, failed testing.

lahoosascoots’s picture

Status: Needs work » Needs review
FileSize
35.12 KB

Found a few more usages. One last try.

thedavidmeister’s picture

I 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).

lahoosascoots’s picture

Assigned: Unassigned » lahoosascoots

I 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.

thedavidmeister’s picture

OK 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!

chx’s picture

#sorted and #weight is not internal.

lahoosascoots’s picture

FileSize
26.2 KB

Removed any changes to #sorted.

lahoosascoots queued 31: 111079-31.patch for re-testing.

Status: Needs review » Needs work

The last submitted patch, 31: 111079-31.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.