How to create content type, fields and view while installing custom module in Drupal 9 using configuration manager.

Here we are going to discuss how to move your content type and view in to custom module so that it will create content types , fields and view swhile installing module.

Normally developers creates content types , fields , views and view configurations in Admin UI, SO while sharing same changes to other environment or publishing in drupal.org it will be difficult to manually creating these configurations and fields.

Assuming we have content type Job application, this content type has below fields.

Now go to extend page, in module listing page you can see configuration manager, click on configure.

So in synchronize page you can see below export and import option

In export tab select single item.

Select configuration type as content type and configuration name select Job application.

So you can see below yml code generated.

We are using this yml in our module as mentioned in page Filename: node.type.job_application.yml

Remove uuid from above and create a file node.type.job_application.yml in custom module path dn_careerdemo\config\install

Here dn_careerdemo is the sample module that we have.

Here in order to create new content type we are changing all job_application to job_applications, so file created will be node.type.job_applications.yml

Also content of file will be as below.

We have included below dependency to our own module in order to remove content type and its fields during uninstall of this module.

Same way for each field, select respective fields as below. Here we are exporting application status filed.

So create file field.field.node.job_applications.field_application_status.yml in path /dn_careerdemo\config\install

Copy below content in file and update content type to job_applications.

Same way create yml file for all fields and place in path.

\config\install\

If you have a view of job_applications , same way you can export view. Here I have exported below view,

 

Place above in in file \config\install\views.view.job_applications

Now you can place your custom module in any Drupal 9 instance, upon installation of the module , job applications content type will be created with all fields and also job application view also will be created with all its configuration.

During unintsall of the same module, all these content type and field will be removed.

Download sample module here.

Get Free E-book
Get a free Ebook on Drupal 8 -theme tutorial
I agree to have my personal information transfered to MailChimp ( more information )
if you like this article Buy me a Coffee this will be an ispiration for me to write articles like this.

You may also like...