1

I have tried this code but it is not working.

$form['field_test'] = [
  '#title' => t('test'),
  '#type' => 'radios',
  '#options' => [t('A'), t('B'), t('C')],
 ];
$form['#group_children']['field_test'] = 'group_1';

I also tried with

$form['#fieldgroups']['group_1']->children[] = 'field_test';

But nothing is working. It works in Drupal 7. Is it changed in Drupal 8?

I have written this code in hook_form_alter and I'm altering a node form.

0

You’re missing '#group' => $group_id, add that and it should work.

Like this:

$group_id = 'group_1';
$field_name = 'field_test';

$form[$group_id][$field_name] = [
  '#title' => t('test'),
  '#type' => 'radios',
  '#options' => [t('A'), t('B'), t('C')],
  '#group' => $group_id,
];
0

You have to put both.

$form['#group_children']['field_test'] = 'group_1';
$form['#fieldgroups']['group_1']->children[] = 'field_test';
  • I tried with both but not working. – Ahmad Nov 29 at 4:11

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.