Needs work
Project:
Drupal core
Version:
main
Component:
render system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Aug 2026 at 07:58 UTC
Updated:
8 Oct 2026 at 15:52 UTC
Jump to comment: Most recent
#states do not work on table cells, even though these can be render elements. This is the case with both #theme = table and #type = table.
Example:
$form['control'] = [
'#type' => 'checkbox',
'#title' => 'Ticky this box plx',
];
$rows[] = [
'name' => ['data' => ['#markup' => 'data 1']],
'age' => ['data' => ['#markup' => 'age']],
'email' => ['data' => ['#markup' => 'email']],
];
$rows[] = [
'name' => ['data' => ['#markup' => 'data 2']],
'age' => ['data' => ['#markup' => 'age']],
'email' => ['data' => [
'#markup' => 'should be only shown if ticky',
'#states' => [
'visible' => [
':input[name="control"]' => ['checked' => TRUE],
],
],
]],
];
$form['table'] = [
'#type' => 'table',
'#rows' => $rows,
];
$form['reacts'] = [
'#type' => 'textfield',
'#title' => 'shown if ticky',
'#states' => [
'visible' => [
':input[name="control"]' => ['checked' => TRUE],
],
],
];
As a workaround, you can add this to a table cell render element:
'#wrapper_attributes' => [
// Need this because states JS code looks for nearest parent with this
// class.
'class' => ['js-form-wrapper'],
// Have to add this by hand because this doesn't get states processed.
'data-drupal-states' => \Drupal\Component\Serialization\Json::encode($states),
],
For a header, or a cell made in the older method using a 'data' array key, this works:
[
'data' => 'my cell contents',
'class' => ['js-form-wrapper'],
'data-drupal-states' => \Drupal\Component\Serialization\Json::encode($states),
],
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
charlliequadros commentedI’ll work on this issue.
Comment #3
charlliequadros commentedComment #5
charlliequadros commentedHi @joachim
Implemented support for #states on table cells containing #markup or #plain_text.
This covers tables rendered using both #type => 'table' and #theme => 'table'. The state data, wrapper class, and core/drupal.states library are now applied to the table cell when required.
Render elements that define their own #type, #theme, or #theme_wrappers continue to use their existing state handling.
Comment #6
charlliequadros commentedComment #7
smustgrave commentedSummary is incomplete so moving back.
Comment #8
joachim commentedComment #9
joachim commented