It is a good idea to build content_types in code, especially if you’re working with version control and multipule environments. Building out the fields and all that stuff can sometimes be a true pain in the ass though.
So, like with views, it may be eaiser to build it out in the GUI in your local, then export the fields and put them in your code. So here’s how to do that.
First make sure you have devel installed. Now go to the devel PHP page. This will be http://local.url/devel/php and paste in some code. DO NOT INCLUDE PHP TAGS IF YOU’RE COPY/PASTING THIS FROM HERE
Then just set the top three vars.
The last two lines will dictate which array gets exported. Uncomments the instance line and comment out the info line to show the instance vs. the info. Now, because I’m writing this as a placeholder reminder for when I need to use it, I’m going to use this example to add fields to an existing content_type. This also assumes that the content_type has a module to handle it’s initial configuration. Go to the install file and add an update function. Add the export from the info to a field variable and then run field_create_field with that field variable. Next do the same for instance but use field_create_instance.
And that’s pretty much it. On your local restore a sql-dump from before you added the field via the GUI and then run drush updatedb. After that, assuming it’s all good, then push to your other environments and updatedb. Enjoy your new field.