Seen in a few elements such as core/lib/Drupal/Core/Render/Element/Radios.php, core/lib/Drupal/Core/Render/Element/RenderElement.php, core/lib/Drupal/Core/Render/Element/ImageButton.php, but doesn't seem to be documented anywhere.

Update:
- Since #has_garbage_value is only of use on form elements, it should be documented on the FormElement class (even though the code using it is in RenderElement).
- The docs for this property need to reference the #value property, which is also missing from the documentation, so it should also be added to FormElement. You can get some docs for #value from the Drupal 7 Form API reference on api.drupal.org (at least to look at for reference about what it should say):
https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

jhodgdon’s picture

Issue tags: +Novice

Thanks for the report! This should be documented on https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Re...
which lists all of the generic properties.

It seems like the documentation should say that it indicates that the #value property of an element should not be used or processed.

drnikki’s picture

I'm rolling a patch for this.

drnikki’s picture

drnikki’s picture

Status: Active » Needs review
jhodgdon’s picture

Version: 8.2.x-dev » 8.1.x-dev
Status: Needs review » Reviewed & tested by the community

Looks good to me, thanks!

Wim Leers’s picture

Component: documentation » forms system
Status: Reviewed & tested by the community » Needs review
Issue tags: -Novice +Documentation

I'm not sure it's correct to document this as being a public API. It's something that's internal to Form API.

        // If the element is a (non-image) button, its name may not identify it
        // uniquely, in which case a match on value is also needed.
        // @see _form_button_was_clicked()
        if (!empty($element['#is_button']) && empty($element['#has_garbage_value'])) {
          $settings['submit']['_triggering_element_value'] = $element['#value'];
        }

+

        // Final catch. If we haven't set a value yet, use the explicit default
        // value. Avoid image buttons (which come with garbage value), so we
        // only get value for the button actually clicked.
        if (!isset($element['#value']) && empty($element['#has_garbage_value'])) {
          $element['#value'] = isset($element['#default_value']) ? $element['#default_value'] : '';
        }
jhodgdon’s picture

Status: Needs review » Needs work

It is being used by at least one or two elements in Core (being set in their form array defaults) -- so not really strictly internal, I think?

Also we are documenting both internal and public properties in the RenderElement and FormElement class. That said, I think you are right that we should add a note to this documentation to say it's internal.

See
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!Element!Re...

The way we are doing this on other properties is changing (bool) to (bool, internal) at the start of the docs line.

Wim Leers’s picture

so not really strictly internal, I think?

Well, Drupal has internal APIs to work around problems in the API design, I think this is an example of that.

That said, I think you are right that we should add a note to this documentation to say it's internal.

Cool :)

drnikki’s picture

Status: Needs work » Needs review
FileSize
827 bytes

Based on my understanding of the convo above, I updated the description to (bool, internal) and fixed resulting line wrap.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

Wim Leers’s picture

+1

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2717921-garbage-value-10.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

Stupid Migrate random test failures. I think/hope there is an issue about them.

effulgentsia’s picture

Assigned: Unassigned » effulgentsia
Status: Reviewed & tested by the community » Needs review
+++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php
@@ -66,6 +66,8 @@
+ * - #has_garbage_value: (bool, internal) Set to TRUE to indicate that the
+ *   #value property of an element should not be used or processed.

This refers to #value, which is not documented. Also, #value should definitely not be documented on RenderElement, but on FormElement, which makes me think that #has_garbage_value should also be on FormElement, despite RenderElement having code that checks for FAPI-specific properties, which is kind of a shame. I don't want to scope creep this issue too much though, so I'd like to open another issue to delve into these concerns in more detail. Assigning this to myself until I do that.

effulgentsia’s picture

Status: Needs review » Postponed

More accurate status per #15.

jhodgdon’s picture

Doh! #value should definitely be documented too. It seems to me that #has_garbage_value and #value should both be on FormElement, as I think you are suggesting? Independent of where the code is, that is where they logically should be documented for developers to learn about.

effulgentsia’s picture

Status: Postponed » Needs work

+1 to #17. If you're ok with moving the #has_garbage_value docs to FormElement, despite RenderElement having code that uses it, that certainly works for me, and so this doesn't need to be postponed on moving that code.

Do we want to add #value docs in this issue, or postpone this issue on a separate #value docs issue?

jhodgdon’s picture

Issue summary: View changes

It seems if #has_garbage_value references #value, we should document it in this issue.

Updating summary.

effulgentsia’s picture

Assigned: effulgentsia » Unassigned

+1 to #19 and the updated IS. Unassigning from myself until it's RTBC again.

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.

subhashuyadav’s picture

- Added #value to above patch

subhashuyadav’s picture

Status: Needs work » Needs review
shashikant_chauhan’s picture

Status: Needs review » Needs work

@subhashuyadav, Kindly add full stop at the end of statement.
* - #value: (text or numbers) Sets values that cannot be edited by the user

subhashuyadav’s picture

Status: Needs work » Needs review
FileSize
906 bytes

Thanks @shashikant_chauhan. I have updated the patch. Please review.

shashikant_chauhan’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, Looks good now.

joachim’s picture

  1. +++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php
    @@ -66,6 +66,9 @@
    + * - #value: (text or numbers) Sets values that cannot be edited by the user.
    

    Does 'Sets' make sense here? It doesn't set anything, it *is* a value.

shashikant_chauhan’s picture

Status: Reviewed & tested by the community » Needs work

@joachim, I think below sentence makes more sense here. Let me know your thoughts on this.

+++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php
@@ -66,6 +66,9 @@
+ * - #value: (text or numbers) Values that cannot be edited by the user.
joachim’s picture

Looks better, though I'd tweak it to:

> + * - #value: (text or numbers) A value that cannot be edited by the user.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
908 bytes
814 bytes

Changed according to suggestions in #30.

shashikant_chauhan’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for picking this up! Does not seem like that #15 or #18 was considered though.

gaurav.kapoor’s picture

Status: Needs work » Needs review
FileSize
1.8 KB
807 bytes

Added documentation FormElement file as well.

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
larowlan’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Render/Element/FormElement.php
@@ -50,6 +50,9 @@
+ * - #value: (text or numbers) A value that cannot be edited by the user.

+++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php
@@ -66,6 +66,9 @@
+ * - #value: (text or numbers) A value that cannot be edited by the user.

Typically I think we would say 'mixed' instead of 'text or numbers'

_pratik_’s picture

Assigned: Unassigned » _pratik_

Will work on this.

_pratik_’s picture

Assigned: _pratik_ » Unassigned
Status: Needs work » Needs review
FileSize
1.8 KB
2.27 KB

Rerolled the patch in #34 and addressed the changes specified in #42 . Attached an diff file for reference.

joachim’s picture

Looks good, just one thing:

+++ b/core/lib/Drupal/Core/Render/Element/RenderElement.php
@@ -66,6 +66,9 @@
+ * - #has_garbage_value: (bool, internal) Set to TRUE to indicate that the

I don't think this way of specifying something is internal is done anywhere else in core.

I would put:

> (bool) Internal only. Set to TRUE [...]

hmendes’s picture

Adding a patch with the changes suggested in #45.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Looks great. Thanks!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed d909b20df7 to 10.0.x and 52fbb19786 to 9.4.x and 6937f0b4e0 to 9.3.x. Thanks!

  • alexpott committed b686177 on 10.0.x
    Issue #2717921 by gaurav.kapoor, drnikki, subhashuyadav, pratik_specbee...

  • alexpott committed 52fbb19 on 9.4.x
    Issue #2717921 by gaurav.kapoor, drnikki, subhashuyadav, pratik_specbee...

  • alexpott committed 6937f0b on 9.3.x
    Issue #2717921 by gaurav.kapoor, drnikki, subhashuyadav, pratik_specbee...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.