-1

I've got several node edit forms that, in most themes, display the 'advanced' group in a sidebar. I have other plans for the sidebar, though, so I don't want that behavior. I edited some twig and css to make the advanced group appear below the main form, but this is still pretty messy. In particular, we often have to adjust the author field, and I'd like it at the top all by its lovely self... not buried in a special section.

All of that to say, I see here how to add items to the 'advanced' group, but how can I remove author (and pretty much everything else) from it and just use the field group module to put fields where I want them? (Field group module currently doesn't let you take fields out of advanced)

I've done some things in MYTHEME.THEME with THEME_node_form_alter (changing submit button label for example), but I can't seem to get it to move author out of the advanced group.

The module way would be fine, too, but is beyond my expertise without some help. (Seems like there would be a market for a "liberate the node form" module or "all fields moveable" module, etc.)

Added because code requested...

function MYTHEME_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    $form['author']['#group'] = 'SOMETHING HERE?';
}

That isn't complete, so of course can't work. Looking at the api here, I see the author field is assigned to 'advanced' but I don't know how to assign it to something else. The relevant portion

$form['author'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Authoring information'),
    '#group' => 'advanced',
    '#attributes' => [
      'class' => [
        'node-form-author',
      ],
    ],
    '#attached' => [
      'library' => [
        'node/drupal.node',
      ],
    ],
    '#weight' => 90,
    '#optional' => TRUE,
  ];
2
  • Since this is a question about code, and you wrote code, we need to see that code. Otherwise, the question is too broad to be acceptable. We do not explain how to write a module, but if you do not understand a specific documentation page about writing a module, we could answer that, as long as the question is very specific (and it is not about the meaning of a single word used in that documentation page.)
    – apaderno
    Feb 24, 2023 at 8:21
  • I really thought the code I linked to was clear enough, but have added some here. As the question says, I don't how to properly assign author to a different #group. I know how to make a module, but ... I don't know how to assign author to a different #group. If there's a reference document that lists all the possible #group values, that would be helpful. I tried 'footer' but I think my code is probably more fundamentally flawed because that got me a wsod.
    – aharown07
    Feb 24, 2023 at 23:54

1 Answer 1

0

This works... though it doesn't look quite right to me.

function MYTHEME_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
        $form['author']=['#group' => 'footer'];
    }

This sort of works, but is probably not a good idea. It removes author from 'advanced' but it doesn't seem to heed positioning in the "Manage form display" interface. And I get the impression fields are not supposed to be without a #group value.

function MYTHEME_form_node_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
    unset($form['author']['#group']);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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