Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export a Drupal 7 field definition for use in custom modules.
<?php
// Found: https://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7
// 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_config['id']);
unset($info_instance['id'], $info_instance['field_id']);
include_once DRUPAL_ROOT . '/includes/utility.inc';
$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.