I am new to drupal 8, I have been using drupal 7 for quite some time and I used to write the code that creates content types and fields in hook_install / hook_update.

Now I am creating a module that creates a new content type with a few fields. I tried to do it with YAML config files but it does not create my fields. The code I have so far:


name: My Module
description: Applies customizations for my website.
package: Custom

type: module
core: 8.x

    - breakpoint # toolbar dependency
    - image
    - link
    - taxonomy
    - toolbar


type: article
name: Article
description: 'Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.'
help: ''
has_title: true
title_label: Title

            status: true
            promote: true
            sticky: false
            revision: true
        preview: true
        submitted: true

status: true
langcode: en

new_revision: true
preview_mode: 1
display_submitted: true

dependencies: {  }

And one of my fields: /module/custom/mymodule/config/install/field.field.node.article.image.yml

langcode: en
status: true
    - node.type.article
    - image
id: node.article.image
field_name: image
entity_type: node
bundle: mymodule
label: Image
description: 'A representative <em>image</em> for the current article.'
required: false
translatable: false
default_value: {  }
default_value_callback: ''
  file_directory: '[date:custom:Y]-[date:custom:m]'
  file_extensions: png
  max_filesize: ''
  max_resolution: ''
  min_resolution: ''
  alt_field: true
  alt_field_required: true
  title_field: true
  title_field_required: true
  handler: 'default:file'
  handler_settings: {  }
field_type: image

What am I missing? Why don't the fields get created at install time?

  • did you also setup the routes ? **.routing.yml ? otherwise you wont get the desired links ..
    – rémy
    May 30, 2016 at 16:24
  • no, I have not... what should a *.routing.yml contain?
    – dasj19
    May 30, 2016 at 16:27

1 Answer 1


For a node type + fields + formatter/widget settings, you need:

  • The node type, you already have that
  • The field.storage.node.* config entities for your fields. If they are shared with other node types/modules then it gets a bit complicated. You can't define the same default config as another module. You could make it optional config, but then all your config needs to be optional
  • The fields themself, like the example the one that you already have.
  • The core.entity_form_display.node.article.* config entities for the different form displays, for node, probably just default.
  • The core.entity_view_display.node.article.* config entities for all the view modes you want. default, teaser, ...

Also, note that tis is install configuration. It will only get created when you install the module. There is no standard mechanism to update configuration when you change the files and the module is already installed. There are modules for that, like config_update, features possibly also contains that.

If this is a custom module that you just need on a single site and want to use it for dev -> staging -> production (or whatever you call your environments) deployments, it's easier to use the global config folder for that. Create your config, export it, commit it, and then import again. That also does updates and deletions.

  • 1
    thanks a lot for your input, do you know any documentation refference for the field.storage.node.* config entities?
    – dasj19
    May 30, 2016 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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