Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Export a Drupal 7 field definition for use in custom modules.
// Found:
// My new favorite developer because of this, "Now that you understand how it works, let me show you some easy tricks to incorporate this into your development workflow."
// Fill in these with your desired field details.
$entity_type = '';
$field_name = 'field_';
$bundle_name = '';
$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
unset($info_instance['id'], $info_instance['field_id']);
include_once DRUPAL_ROOT . '/includes/';
$output = "field_create_field(" . drupal_var_export($info_config) . ");\n";
$output .= "field_create_instance(" . drupal_var_export($info_instance) . ");";
drupal_set_message("<textarea rows=30 style=\"width: 100%;\">" . $output . '</textarea>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.