In form_process_table() and form_process_tableselect():
foreach (element_children($element) as $key) {
// Do not overwrite manually created children.
if (!isset($element[$key]['select'])) {
This is the opposite of the behaviour of checboxes and radios elements.
With those, it's established and desired behaviour that the #process callback for the element merges in any existing child elements. This allows you to do things like add description to single radio buttons or checkboxes, or mark them disabled:
$form['checkboxes'] = array(
'#type' => 'checkboxes',
'#options' => $options,
);
// Make the foobar option disabled for some reason.
$form['checkboxes']['foobar']['#disabled'] = TRUE;
// The bizbax checkbox needs further description.
$form['checkboxes']['foobar']['#description'] = t('More details here');
This is not possible with tableselect / table, because they specifically skip existing child elements.
Comment | File | Size | Author |
---|---|---|---|
#4 | interdiff-2101357-2-4.txt | 17.44 KB | kerby70 |
#4 | table_and-2101357-4.patch | 9.77 KB | kerby70 |
#2 | 2101357.drupal.form-table-tableselect-merge-child-elements.patch | 8.07 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedThis behaviour for checkboxes and radios is already included in the test module:
and tested in ElementTest::testOptions().
Comment #2
joachim CreditAttribution: joachim commentedHere's a patch.
It's a lot more dramatic than it looks, due to the removal of if() statements and the change in indentation of their contents.
Comment #3
jhedstromComment #4
kerby70 CreditAttribution: kerby70 commentedReroll attached.
In the original $elemen[$key]['select'] exists but in the current code $row['select'] is used. Below is to illistrate the change.
Original
Previous change
Current
New change
Comment #5
mgiffordNo longer applies.
Comment #19
quietone CreditAttribution: quietone at PreviousNext commentedThere hasn't been any work here for 9 years. I think it is time to check in and find out if this is still relevant to Drupal 10.
Since we need more information to move forward with this issue, I am setting the status to Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!