Last active
December 30, 2015 00:09
-
-
Save yanniboi/7747268 to your computer and use it in GitHub Desktop.
Code snippet for field creating update hook
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 | |
/** | |
* Code snippet for field create update hook. | |
*/ | |
function module_update_7001() { | |
$t = get_t(); | |
$fields = array(); | |
if (!field_info_field('field_name')) { | |
$fields['field_name'] = array( | |
'field_name' => 'field_name', | |
'type' => 'image', | |
'cardinality' => 1, | |
); | |
} | |
foreach ($fields as $field) { | |
field_create_field($field); | |
} | |
$instances = array(); | |
if (!field_info_field('entity', 'field_name', 'bundle')) { | |
$instances['field_name'] = array( | |
'entity_type' => 'entity', | |
'bundle' => 'bundle', | |
'field_name' => 'field_name', | |
'label' => $t('Field Name'), | |
'description' => $t('Field description'), | |
'settings' => array( | |
'file_directory' => 'images', | |
), | |
'widget' => array( | |
'type' => 'media_generic', | |
), | |
); | |
} | |
foreach ($instances as $instance) { | |
field_create_instance($instance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment