Problem/Motivation
Tableselect element sets title to empty string and doesn't read from $element['#options'] the title as it does for checkboxes tableselect style. It impacts accessibility for radio buttons printed using tableselect and is inconsistent with how tableselect renders checkboxes.
Code from Tableselect::processTableselect
foreach ($element['#options'] as $key => $choice) {
// Do not overwrite manually created children.
if (!isset($element[$key])) {
if ($element['#multiple']) {
$title = '';
if (isset($element['#options'][$key]['title']) && is_array($element['#options'][$key]['title'])) {
if (!empty($element['#options'][$key]['title']['data']['#title'])) {
$title = new TranslatableMarkup('Update @title', array(
'@title' => $element['#options'][$key]['title']['data']['#title'],
));
}
}
$element[$key] = array(
'#type' => 'checkbox',
'#title' => $title,
'#title_display' => 'invisible',
'#return_value' => $key,
'#default_value' => isset($value[$key]) ? $key : NULL,
'#attributes' => $element['#attributes'],
);
}
else {
// Generate the parents as the autogenerator does, so we will have a
// unique id for each radio button.
$parents_for_id = array_merge($element['#parents'], array($key));
$element[$key] = array(
'#type' => 'radio',
'#title' => '',
'#return_value' => $key,
'#default_value' => ($element['#default_value'] == $key) ? $key : NULL,
'#attributes' => $element['#attributes'],
'#parents' => $element['#parents'],
'#id' => HtmlUtility::getUniqueId('edit-' . implode('-', $parents_for_id)),
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);
}
if (isset($element['#options'][$key]['#weight'])) {
$element[$key]['#weight'] = $element['#options'][$key]['#weight'];
}
}
}
Title is considered and set only for $element['#multiple'] == TRUE cases:
$title = '';
if (isset($element['#options'][$key]['title']) && is_array($element['#options'][$key]['title'])) {
if (!empty($element['#options'][$key]['title']['data']['#title'])) {
$title = new TranslatableMarkup('Update @title', array(
'@title' => $element['#options'][$key]['title']['data']['#title'],
));
}
}
You can see that $title is not used and is set to empty in radio button element:
$element[$key] = array(
'#type' => 'radio',
'#title' => '',
...
);
Proposed resolution
Add support for #title attribute to be specified in the tableselect element options.
Remaining tasks
Provide patch
User interface changes
None, I guess, as title will still be hidden with '#title_display' => 'invisible'
API changes
None
Data model changes
None