I'm using the Drupal 8 #table element to populate a table on my form, and it's working great for displaying static data.
foreach ($entries = getData() as $entry) {
$row = array_map('Drupal\Component\Utility\SafeMarkup::checkPlain', $entry);
$rows[] = $row;
}
$form['table'] = array(
'#type' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#attributes' => array('id' => 'my-module-list'),
'#empty' => t('No entries available.'),
);
However, I would like to embed a control in each row of the table, for example:
foreach ($entries = getData() as $entry) {
$row = array_map('Drupal\Component\Utility\SafeMarkup::checkPlain', $entry);
$row["field_name"] = array(
'#type' => 'textbox',
);
$rows[] = $row;
}
//dpm($rows);
$form['table'] = array(
'#type' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#attributes' => array('id' => 'my-module-list'),
'#empty' => t('No entries available.'),
);
However, the #textbox field is currently being ignored, and an empty cell is shown in its place.
Is there a way I can embed fields in a Drupal generated table, or do I need to build my own table from scratch?
#rows
element gets converted into a table of plain text cells when the table is rendered. To put controls in the table, put the rows as direct elements of the#table
array. Everything in the table then gets treated as a control, so plain text cells have to have a#markup
entry.