Forked from jackfoust/Drupal Entity Field Export
Last active
August 29, 2015 14:17
-
-
Save reyhansofian/9abca1f69c7f1eb44ddd to your computer and use it in GitHub Desktop.
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 | |
/** | |
* @file | |
* Export serialized data containing fields attached to an Entity. Example used when Features not installed. | |
*/ | |
function MODULE_NAME_install() { | |
drupal_install_schema(SCHEMA_NAME); | |
MODULE_NAME_add_entity_fields(); | |
} | |
/** | |
Implentation of hook_uninstall(). | |
*/ | |
function MODULE_NAME_uninstall() { | |
drupal_uninstall_schema(SCHEMA_NAME); | |
MODULE_NAME_delete_entity_fields(); | |
} | |
function MODULE_NAME_entity_export() { | |
$export_data = array(); | |
$export_data['entity_name'] = 'ENTITY'; | |
$export_data['bundle_name'] = 'BUNDLE'; | |
$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']), | |
); | |
} | |
return serialize($export_data); | |
} | |
function MODULE_NAME_return_entity_fields() { | |
return unserialize(SERIALIZED_EXPORT); | |
} | |
function MODULENAME_add_entity_fields() { | |
$fields = MODULE_NAME_return_entity_fields(); | |
if (!empty($fields)) { | |
foreach ($fields['data'] as $item) { | |
field_create_field($item['field']); | |
field_create_instance($item['instance']); | |
} | |
} | |
} | |
function MODULE_NAME_delete_entity_fields() { | |
$fields = MODULE_NAME_return_entity_fields(); | |
if (!empty($fields)) { | |
foreach ($fields['data'] as $item) { | |
field_delete_instance($item['instance'], TRUE); | |
field_delete_field($item['field']['field_name']); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment