Last active
May 11, 2017 14:30
-
-
Save bfodeke/d7ca9dbe91a18d7e9e919b548517af27 to your computer and use it in GitHub Desktop.
After creating a field in the UI, get the export code to put in custom module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7 | |
$entity_type = 'node'; | |
$field_name = 'field_name'; | |
$bundle_name = 'content_type'; | |
$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(\n" . drupal_var_export($info_config) . "\n);\n\n"; | |
$output .= "field_create_instance(\n" . drupal_var_export($info_instance) . "\n);"; | |
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