6

How do I write a module that provides a content type in Drupal 8?

0

2 Answers 2

8

For a module name my_module and a content type called awesome_page, the directory structure would look like:

  • my_module/
    • my_module.info.yml
    • config/install/
      • node.type.awesome_page.yml

And the file contents would be:

my_module.info.yml:

name: Awesome page content
type: module
description: 'Add awesome content type.'
core: 8.x
dependencies:
  - node

node.type.awesome_page.yml:

type: awesome_page
name: 'Awesome page'
description: '<em>Awesome</em> pages are a little better than other pages.'
help: ''
new_revision: false
display_submitted: true
preview_mode: 1
status: true
langcode: en

For several other examples, find all modules in core that provide new content types: find . -iname "node.type*"

2

You can use Drupal Console, this will automatic ask you for couple question an generate the content type (entity type) for you on a module.

Here is the command that you need to generate:entity:bundle [options]

1
  • 1
    Drupal Console just blew my mind - reminds me of all the PHP Cake Bake stuff.
    – Felix Eve
    Oct 27, 2015 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.