What is the easiest way to export Field settings into a .install file? I have a bunch of custom fields on a custom content type. I'm trying to make my module create these fields and remove them on install and uninstall respectively.

There was a previous question and answer on this: https://drupal.stackexchange.com/a/629/2384 However, it is not adequate. The code was not completely presented. The author used node_type_delete() without deleting the content first, and that allegedly leads to trouble later down the line. So I checked the node_example.module as per recommendations on Drupal.org, node_example.install etc. These files provide insight into the structure of the module, but do not discuss all the varieties of fields (like file, taxonomy, etc.,) and how they are to be structured in the .install array.

I have tried to export my content type using Features, and it does produce an array. But the syntax is radically different from what was presented in the example, and I was lost in the arrays and sub-sub arrays.

Is there a simple guide somewhere, that can help me convert my content type into an array specification I can smoothly fit into my hook_install declarations?
There are some useful resources on how to do this. And you dont have to use Features.


Exporting and creating field definitions in Drupal 7 blogpost by Joel Stein
Drupal 7 export content type and fields blogpost by Kristian Nissen


Features is great if you understand what it's doing (calling Field API in an automated fashion and exporting definitions). You can use the Field API to define, create instances, attach fields to entities -- and then remove them all module uninistall as you need.

The easiest way for me to do this is look at the functions in the link above and use var_dump() on $field or its $settings after you make it using the Field UI. Then just use the appropriate Field API call like field_create_instance() to wire these var_dump'd arrays into your modules hook_install(). So i'm saying dont create the arrays by hand, create them in Drupal and just copy an export to your code ...