Change default settings for new content types

When creating a new content type, there are a few things to configure.

I often deselect promoted to front page, create new revision, display author and date, and available menu.

Image
Drupal new content type form defaults

To do this, I added a form alter in mantratheme.profile.

Set the default values we want in #default_value.

The tricky part is knowing what format to use. The multivalue options are in an array, but the display submitted is just a boolean. Use a debugger to see what values are currently in use.

/**
 * Default settings for new content types.
 * 
 * Implements hook_form_FORM_ID_alter().
 */
function mantraprofile_form_node_type_add_form_alter(
  &$form, Drupal\Core\Form\FormStateInterface $form_state)
{
  // Unset publish to front, create revision.
  $form['workflow']['options']['#default_value'] = ['status'];
  // Unset display author and date.
  $form['display']['display_submitted']['#default_value'] = 0;
  // Unset main menu.
  $form['menu']['menu_options']['#default_value'] = [0];
}


 

Project