Programmically create a content type with publishing options I've been able to successfully create a content type on the install of my module by following Creating a custom content type in Drupal 8 in the drupal.org documentation, but I can't find a way to add the publishing options.


  


How should I add the publishing options when creating a content type?
You have to add a base field override to change the default value of status, promote and sticky for newly created nodes. For the first and second option the default value is predefined as TRUE and for the third option as FALSE in the base field definition of the entity type. See this example for promote:

Drupal\node\Entity\Node::baseFieldDefinitions

$fields['promote'] = BaseFieldDefinition::create('boolean')
  -&gt;setLabel(t('Promoted to front page'))
  -&gt;setRevisionable(TRUE)
  -&gt;setTranslatable(TRUE)
  -&gt;setDefaultValue(TRUE)
  -&gt;setDisplayOptions('form', [
    'type' =&gt; 'boolean_checkbox',
    'settings' =&gt; [
      'display_label' =&gt; TRUE,
    ],
    'weight' =&gt; 15,
  ])
  -&gt;setDisplayConfigurable('form', TRUE);


The base field override needs only to be present if you want to change this preset for a specific content type.

Example for the status field:

foobar/config/install/core.base_field_override.node.car_brand.status.yml

# core.base_field_override.node.car_brand.status.yml
langcode: en
status: true
dependencies:
  config:
    - node.type.car_brand
id: node.car_brand.status
field_name: status
entity_type: node
bundle: car_brand
label: 'Publishing status'
description: 'A boolean indicating the published state.'
required: false
translatable: true
default_value:
  -
    value: 0
default_value_callback: ''
settings:
  on_label: 'On'
  off_label: 'Off'
field_type: boolean


You can override the fields promote and sticky the same way.



The same task in PHP:

$fields = \Drupal::service('entity_field.manager')-&gt;getFieldDefinitions('node', 'car_brand');
$fields['status']-&gt;getConfig('car_brand')
  -&gt;setDefaultValue(FALSE)
  -&gt;save();


The method BaseFieldDefinition::getConfig loads an existing base field override or creates one if none exists from the base field definition in the entity type.

Using the PHP code in an install hook is IMHO the better solution, because you only need to change the default value and don't need to repeat all other values.