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.
#414424: Introduce Form API #type 'text_format' makes a value callback necessary for elements that rely on processed children for their value. Unfortunately, tableselect wasn't updated. solotandem experienced that he could no longer unset elements in #default_value in current head.
Attached patch copies the value callback from checkboxes.
Comment | File | Size | Author |
---|---|---|---|
#26 | 831966-core-tableselect.patch | 2.3 KB | solotandem |
#25 | 831966-core-tableselect.patch | 2.3 KB | solotandem |
#23 | 831966-core-tableselect.patch | 2.13 KB | solotandem |
#21 | 831966-core-tableselect.patch | 2.64 KB | solotandem |
#16 | 831966-core-tableselect.patch | 3.2 KB | solotandem |
Comments
Comment #1
Heine CreditAttribution: Heine commentedPatch is offcourse completely broken when #multiple is FALSE, needs #multiple check, but that's work for another day.
Comment #2
Heine CreditAttribution: Heine commentedComment #3
Heine CreditAttribution: Heine commentedsolotandem remarked that this changes behaviour:
before
with patch:
I like the change better for it is inline with checkboxes, but that should be discussed separately.
Comment #4
Heine CreditAttribution: Heine commentedso the latest patch changes the behaviour back.
Comment #5
solotandem CreditAttribution: solotandem commentedI prefer the values in the default_values array over the keys in that array. This goes along with patch in #2. I was simply pointing out this is different from what it was doing and was not aware if it was intended to use the keys or the values. Seems more intuitive to use the values.
Comment #7
solotandem CreditAttribution: solotandem commentedAttached patch:
- incorporates multiple value check in form_type_tableselect_value()
- includes type = tableselect in processing done for checkboxes in drupal_process_form()
- modifies tests when not multiple value
Comment #8
solotandem CreditAttribution: solotandem commentedComment #9
solotandem CreditAttribution: solotandem commentedRevised patch:
- handles the form code defining default values and the user clearing the default values (and not checking any other values)
- defines the defaults in the same way as the checkboxes element (i.e. the array value not the key)
Comment #10
solotandem CreditAttribution: solotandem commentedHere is a simpler version of the previous patch that simply calls the form_type_checkboxes_value() function.
Comment #11
Heine CreditAttribution: Heine commentedI'm - in principle - in favor of changing the arguments to make them consistent with checkboxes, but this late in the release cycle? Also, shouldn't this need changes to tableselect usage in core?
Comment #12
solotandem CreditAttribution: solotandem commentedThe only change with using the checkboxes code is if the core code sets the #default_value property on a tableselect item. The only occurrence of this seems to be in node.admin.inc with '#default_value' => array(1 => 1, 2 => 2). Thus, whether keys or values are used to set the value, should it not work the same?
Interestingly, this issue highlights a missing facet to the test for the tableselect widget (and possibly others). None of the tableselect tests set a default value, tested for it, changed it and tested again, etc.
Comment #13
Heine CreditAttribution: Heine commentedHaving to use
instead of the checkboxes-like
was a really stupid decision (by me).
I'd love to get the change in as an API fix.
Apart from the API fix, patch restores the ability to uncheck boxes set with default_value. I was unable to send tampered values or keys with the patch from #10 applied.
I'd remove the noop else. Without that clause, I would mark this RTBC for a core committer to remark on the API change.
Comment #14
solotandem CreditAttribution: solotandem commentedRerolled with suggestions in IRC from Heine.
Comment #16
solotandem CreditAttribution: solotandem commentedComment #17
solotandem CreditAttribution: solotandem commentedComment #18
solotandem CreditAttribution: solotandem commentedMarking RTBC per Heine's comment in #13 as latest patch incorporates the conditions he stated for changing to RTBC.
Comment #19
Heine CreditAttribution: Heine commentedTo quote the branch maintainer:
So, that leaves us with the patch from #3; it works fine, except that the tests no longer properly test the behaviour. They could simply be removed.
Comment #20
solotandem CreditAttribution: solotandem commentedI downloaded and grepped all the D7 contributed modules on drupal.org for 'tableselect.' Only one other module (besides coder upgrade) sets a default value for this form element. Thus, to change the default value handling (or more accurately to conform it to checkboxes), does not appear to affect a significant base of existing code. We can inform the maintainer of the other module of this change. Also, as mentioned above, there is no instance in core of setting the default value for this form element.
This seems like a "no brainer" to commit.
Comment #21
solotandem CreditAttribution: solotandem commentedRerolled patch from #3 with a comment for D8 and one additional line change in _form_validate().
Comment #22
sunNot sure why we document the callback params and return values all over again. I'd be happy to not introduce them here.
(The phpDoc is the same for all form element value callbacks.)
Leaving that decision to you.
Please remove that code. It's nice that you think ahead of time, but D8 may turn out to be entirely different, so the entire commented out code might be moot.
I guess a #type tableselect cannot be non-multiple? Otherwise, we'd be dealing with a serious abuse of the element, and I'd make a call to not support that.
Hence, let's just drop this extra condition.
Powered by Dreditor.
Comment #23
solotandem CreditAttribution: solotandem commentedThanks for looking at this. Responding to your points:
I left the callback parameters as it seems odd to remove them only from one value callback. It would seem another issue should be created to modify all of the callbacks to remove the redundant parameters and add an @see reference to the documentation of the parameters.
Removed the D8 comment and code.
Retained the "$element['#multiple']" condition because this value can be FALSE. If it is, radio buttons are displayed and the default value handling is used.
Attached patch is against current HEAD.
Comment #24
sunPlease also add this important detail to the inline comment, slightly reworded.
Comment #25
solotandem CreditAttribution: solotandem commentedRevised as suggested above.
Comment #26
solotandem CreditAttribution: solotandem commentedRerolled against current HEAD.
Comment #27
boombatower CreditAttribution: boombatower commentedComment #28
solotandem CreditAttribution: solotandem commented#26: 831966-core-tableselect.patch queued for re-testing.
Comment #29
webchickCommitted to HEAD.