Open stpaultim opened 4 years ago
Yes, it seems the module is just a port of the equivalent Drupal 7 example module. It should be updated to use config files.
@stpaultim Does the code shown on forum.backdropcms.org/comment/1541#comment-1541 require to be updated, or are there any necessary changes to make it work with latest Backdrop releases?
@kiamlaluno - I don't write a lot of code, so I'm not the best person to answer this question.
It seems that I originally thought I could simply add configuration files to a module to create a content type. I learned later, that more is necessary.
The code in that comment works, because I'm just adding an existing field to a new content type. BUT, this is not sufficient to create a new field, which is probably a better example.
I think in the case of content types, it may be possible to create one by just copying the json file (or importing the configuration), but I haven't tested this thoroughly.
In the case of fields (which that 2019 post referred to), docwilmot's comment (if I understand it correctly) no longer applies. Importing config files for field info and field instance DOES create the required tables in the database. You can actually test it this way:
field.field.field_my_test.json
and field.instance.field_my_test.json
to another location temporarilyfield_data_field_my_test
has also been removed from the database That said, I believe there are some contrib modules (OG comes to mind) where there is some additional processing when fields are added. So, the above may not apply to all situations.
Thank you for your reply, @stpaultim and @argiepiano.
I know this has been opened as support request. I was thinking to write the example module following a Backdrop approach, if it is possible. Probably, there are more people who needed to create fields when installing a module and looked at the example modules for the code to use. Showing the code that is better to use in Backdrop would help people with the same need.
Actually, node_type_example.module shows how a module can define a new content type. It uses the same type of code Backdrop core uses, though. I cannot find in Backdrop core examples of content type created only via configuration files. I take that means it is not currently possible.
I am just experimenting with creating a content type via a custom module, using config files. I notice that the example module here does not do anything with config at all.
Is this example module just out of date and using Drupal methods?
Should this example module be updated to create the content type and fields with config files (similar to what I did here: https://forum.backdropcms.org/comment/1541#comment-1541?