Created
October 10, 2017 16:23
-
-
Save MikeNGarrett/38f0d9217b644d33d36dfc66efffb254 to your computer and use it in GitHub Desktop.
Export a Drupal 7 field definition for use in custom modules.
This file contains 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 | |
// 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