Adding fields to the "Authoring information" area on a standard Drupal node add/edit page

Published May 27, 2023

New field in Authoring information area in node add/edit sidebar.Have you been in the situation where you've added a new field to a Drupal content type and you want that field to appear somewhere in the sidebar of the node add/edit page for that content type (instead of in the main column along with all the other fields)?

If so, the following snippet of code, added to a custom module on your site is exactly what you're looking for. In this example, a user reference field with the machine name of field_additional_authors  was added to a Blog content type. This code places the field in the Authoring information accordion item in the sidebar:

/**
 * Implements hook_form_alter().
 */
function my_module_form_alter(array &$form, FormStateInterface $form_state, string $form_id): void {
  // Move the "Additional authors" field to the "Authoring information"
  // accordion.
  if (in_array($form_id, ['node_blog_edit_form', 'node_blog_form'])) {
    $form['field_additional_authors']['#group'] = 'author';
  }
}

Note that the add and edit forms have slightly different $form_id values.

Add new comment

The content of this field is kept private and will not be shown publicly.

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!

Name
CAPTCHA