0

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'),
);
3
  • 2
    It looks like you've forgotten to post the code which generates the table
    – Clive
    Feb 10 at 16:12
  • Have you seen this example api.drupal.org/api/drupal/… Try with [$i] on each item like the example Feb 10 at 16:45
  • Thank you so much for the help guys! The [$i] did the trick. Works like a charm! THANKS! Feb 10 at 17:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.