In one of my custom Drupal modules I'm trying to crate a form that also contains a table. One of the table sections looks like the following:
$form['consumption_' . $week]['mood']['title'] = array(
'#markup' => $this->t('Mood'),
);
for ($i = 0; $i <= 6; $i++) {
$options = array(
'1' => t('choice 1'),
'2' => t('choice 2'),
'3' => t('choice 3'),
'4' => t('choice 4'),
);
$form['consumption_' . $week]['mood']['entry_dropdown_' . $i] = array(
'#type' => 'select',
'#options' => $options,
);
$form['consumption_' . $week]['mood']['entry_toggle_' . $i] = array(
'#type' => 'radios',
'#options' => array(
1 => $this->t('Yes'),
0 => $this->t('No'),
),
'#default_value' => 0,
);
}
Everything works fine so far. What I would like to do now is to combine the dropdown and the radio elements so that these elements are in one cell. With the code above, they are in the same row but not in the same cell.
I've tried to work with
'#prefix' => '<td>'
and
'#suffix' => '</td>'
but I can't seem to get it to work correctly.
Any ideas on how to combine those two elements in one cell will be highly appreciated. Thanks very much!
Edit:
The code that generates the table looks like the following:
$form['consumption_' . $week] = array(
'#type' => 'table',
'#title' => 'XYZ',
'#header' => array(' ', 'Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6', 'Day 7'),
);