2

I've created an installation profile for Drupal 8, which creates content types, taxonomies, blocks and stuff I need for new projects via yml files. Now I also want to create some default nodes.

I could use hook_install() or the module "default content" to create some nodes, but I'd like to know, if there is a better way for it.

Since we can create content types, taxonomies, blocks, etc. with yml files, I was wondering if it is possible to also create nodes with it.

So my questions are:

  • Is there a way to create nodes via yml files?
  • What would be the best practice for it?
1

That's exactly what the Default content module was built for:

Default content gives your module and install profile a way to ship default content as well as configuration.

I'm not sure it supports YAML, but definitely JSON and others, so it's basically the same thing.

The docs can be found here.

  • Thanks for your fast response! Of course I know this module and it obviously does what I need, but thought it maybe would be possible, to just create a yml file (like for example node.type.page.yml) in profile/config/install and it already does the work for me. – Markus Jun 26 '18 at 10:53
  • Config and content are separate things, even if you could find a way to jam content into the config folders, you really shouldn't, it will confuse things and it's just conceptually wrong. I doubt you'll find anything in the contrib world that help you shoot yourself like that :) – Clive Jun 26 '18 at 11:07
  • Yes, you're right. I'll go with the default content module since it does what I need. Thanks for your advice! :) – Markus Jun 26 '18 at 11:31
0

I think this info's correct:

  1. YAML Encoder with Content Serialization: uses Drupal/Symfony serialization framework
  2. YAML Content: doesn't use serialization framework, doesn't support export
  3. Demo Content: doesn't use serialization framework, doesn't support export

Regarding best practice it might be worth pointing out that after doing a core or contrib update, my understanding is you should update all exported entities, both config and content.

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.