drupal place field in edit form sidebar
I was recently dealing with a seemingly simple task: Placing a field on an entity in the vertical tabs that show up on the entity add/edit form by default. I searched for the title of this blog post, and also tried "drupal node form add vertical tab" and found no clear answer.
The trick to making it work is as follows
First, alter the form either via hook_form_alter() or an equivelant hook or event subscriber.
Next up, add a new value to the form array as follows:
$form['PICK_A_NAME_HERE'] = [
'#title' => $this->t('ENTER YOUR TITLE HERE'),
'#group' => 'advanced',
'#type' => 'details',
];
Two details to keep in mind: #group must be advanced, and #type must be details.
Then, set whatever field you want to place into the vertical tab you just created as follows:
$form['field_foo_bar']['#group'] = 'SAME_NAME_AS_ARRAY_KEY_YOU_USED_ABOVE';