Drupal 7 export content type and fields

I found this great entry about exporting content types and fields from Drupal 7, there is a comment from David Seddon that shows some very useful stub code.
This snippet does the exporting of data and structure:

$export_data = array();
$export_data['entity_name'] = 'user';
$export_data['bundle_name'] = 'user';
$instances = field_info_instances($export_data['entity_name'], $export_data['bundle_name']);

foreach ($instances as $field_name => $field) {
  $export_data['data'][] = array(
    'field' => field_info_field($field_name),
    'instance' => field_info_instance($export_data['entity_name'], $field_name, $export_data['bundle_name']),

in David’s example a simple var_dump is used to see the structure. I would prefer serializing this data structure and store it somewhere for later use in a hook_install() function.
Once your ready to import this data structure, David’s code snippet does the following:

foreach ($export_data['data'] as $item) {

Again, here I would de-serialize the data and then import it.

About these ads

2 responses to “Drupal 7 export content type and fields

  1. berliner


    I stumbled upon the same blog post and wondered if there is a module that actually provides this functionality. I found http://drupal.org/project/bundle_copy which does the job of exporting / importing whole entities with fields attached to it. However, as far as I can see, it does not allow to export single fields attached to an entity and re-import them to another entity.
    Anyone in the need for this can have a look at my sandbox project on drupal.org:

    • Kristian Nissen

      Hi, thank you for the comment. I did download bundle copy, but as far as I remember (it’s been a while and I might be wrong) but bundle copy is depending on a few other modules. Personally I like modules in Drupal to do just the thing I need and nothing else, I don’t like having to install 2 or 3 modules just to be able to use a single feature in one do them. To me, modules means maintenance and security updates which again means testing your site to make sure nothing’s broken.

      That’s actually why I was considering creating my own module and make it independent from other modules and using the idea of moving field changes between development and production using the module update feature. By doing so I wouldn’t have to have a module in production that can import what I exported from development.

      I will check out your module, maybe it does what I am looking for :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

the dojo


RSS Fork me…

  • An error has occurred; the feed is probably down. Try again later.

Get every new post delivered to your Inbox.

%d bloggers like this: