Create a content type programatically Drupal 8

​Basic creation of a content type in Drupal 8. Content type is created in code in a custom module called dribbit_create_content_type.


As seen on the left, an install directory located in the config directory is needed to store the content types yaml file. Human readable data is used to preconfigure the content types settings.

In Drupal 7, most of these settings were stored in the variables table.

name: Node example
type: module
description: 'Create node tpes.'
package: Dribbit examples
core: 8.x
  - node


 * @file
 * Nothing to see here, 
 * in fact Drupal doesn't need this file so you can safely delete it.


name: 'Test content type'
type: test_type
description: 'Test content type is a simple test content type.'
langcode: en
status: true
      - node_example
help: ''
new_revision: false
display_submitted: true
preview_mode: 1
third_party_settings: {  }



As of D8 Beta3 this is outdated. New config syntax looks like this:

type: book
name: 'Book page'
description: 'Use for handbooks or tutorials.'
help: ''
new_revision: false
display_submitted: true
preview_mode: 1
status: true
langcode: en


Thank you Rainer, I've upated my code.

Could be that this will change again before Drupal is production ready.

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.