I am interested in the idea of making it possible to add a feature to Backdrop CMS in much the same way that one might use the Features modules in Drupal to create a content type and/or a view (related core issue: https://github.com/backdrop/backdrop-issues/issues/3763)

Imagine a FAQ feature that includes:

  • A FAQ content type
  • The fields associated with that content type
  • A view to display the FAQ nodes

I've created some "config file" recipes for a couple of "features" like this, but I don't have an easy way to import these files in a batch. See this blog post

I would love to add these config files through the config management interface, but I could also package them as modules and import them through the modules interface. Right now, I'm looking for ideas on how to update or add config files through a custom module.

Any thoughts?

Most helpful answers

I see. It was working for me in my test FAQ feature, because I only used Title and body field, which I suppose were already there. This did not work with content types that included new fields.

It does work for views and other config that does not require new tables. 

Comments

You could create a module that loads the config files. All you need is a .info and .module file.

That turned out to be easy.

[EDIT: As per @docwilmot comment below, this process loads config files but does not create database tables (if needed)]

For my use case, it would appear that simply including config files in a config directory (within the module) was all I needed to do. I did not have to add any code or even add info to the module .info file. 

I created a module called = FAQ

The info file looked like this (I included a dependency, only because the view in this feature requires that module):

type = module
name = FAQ Feature
description = FAQ Feature
package = Triplo
backdrop = 1.x

dependencies[] = views_bootstrap

The file structure for the module looked like this:

faq
faq > faq.info
faq > faq.module (required - but empty)
faq > config (directory)
faq > config > field.instance.node.faq.body.json
faq > config > node.type.faq.json
faq > config > views.view.faq.json

The content of the config files was taken from here:  https://github.com/backdrop-contrib/config_recipes/tree/master/FAQ

All I had to do was install this module and enable it and I had working FAQ feature that included a custom content type and a view of the results. 

If I install config this way and then try to add some sample content during the install process

function faq_content_install()

the title for the sample content loads fine, but I don't get any content in the body field. 

If I break this into two modules and enable the feature module first and the content module second, the sample content is just fine, both title and body. 

I think that when I'm using the same module, I need to do something to (save?) the config before I create the content. 

Any ideas what I need to do to ensure that the body field config is active and working before I try to generate sample content?

Unfortunately adding node types like this through just config files "creates" the fields but doesnt create the database tables required to save data in those fields.

I see. It was working for me in my test FAQ feature, because I only used Title and body field, which I suppose were already there. This did not work with content types that included new fields.

It does work for views and other config that does not require new tables.