3

I'm creating a Drupal 7 site that has many content types which are defined programmatically. It is quite likely that, after launch, I will be required to slightly modify some of the content types. During development, whenever I need to make a change, I just uninstall the module, make the changes in code, and reinstall it. In a production environment where the data needs to be kept stable, this is clearly not acceptable.

How can I modify one of my existing content types programmatically? Also, how would I apply this update?

2 Answers 2

2
  1. http://api.drupal.org/api/drupal/modules--field--field.crud.inc/function/field_update_field/7

  2. http://api.drupal.org/api/drupal/modules--field--field.crud.inc/function/field_update_instance/7

Open WWWROOT/profiles/standard/standard.install (starting from line 199) Profile install creates basic content types (like Article and Basic page)

1

What are you changing slightly? If you are just adding a field to a type, all that is doing is creating another database entry, and any preexisting content will just have nothing in that field until edited again, so you could just do that either through your module or through the menus. However, if you are changing field names, well that's a whole 'nother story in itself.

1
  • The most likely case is that I would be adding an additional field, and any existing content wouldn't have anything in that field. This could be done through the UI, but this application needs to be kept consistent across several different environments. I'm concerned with having lots of application state and configuration that is maintained outside of code.
    – rybosome
    Dec 2, 2011 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.