I have been working on a D8 project and been wondering what the best course of action would be in order to produce a complete project package that can be easily set up in a new drupal installation. The theme part is pretty straightforward but what about all the specific content types that accompany a project with a specific theme? Is there a way I can have those being created on theme installation?
The best practice for is to use Configuration import/export.
Exporting and importing configuration changes between a Drupal installation in different environments, such as Development, Staging, and Production, allows you to make and verify your changes with a comfortable distance from your site's live environment.
You can add the needed configuration files of the content types and fields needed for the site in a folder named config/install in your theme directory. These configuration gets imported when we install it.
for eg: if you want to create a content type test when your theme is installed
Create a file node.type.test.yml in your_theme/config/install folder paste the code in it
langcode: en status: true dependencies: module: - menu_ui third_party_settings: menu_ui: available_menus: - main parent: 'main:' name: test type: test description: '' help: '' new_revision: true preview_mode: 1 display_submitted: true
Easy method is to
- create the content types and fields form backend
- export the configuration
- Take the newly created files from it and remove the line uuid from it
- paste it in your theme folder