function entityreference_update_7000 in Entity reference 7
Update the field configuration to the new plugin structure.
File
- ./
entityreference.install, line 56
Code
function entityreference_update_7000() {
// Enable ctools.
if (!module_enable(array(
'ctools',
))) {
throw new DrupalUpdateException('This version of Entity Reference requires ctools, but it could not be enabled.');
}
// Get the list of fields of type 'entityreference'.
$fields = array();
foreach (field_info_fields() as $field_name => $field) {
// Update the field configuration.
if ($field['type'] == 'entityreference') {
$settings =& $field['settings'];
if (!isset($settings['handler'])) {
$settings['handler'] = 'base';
$settings['handler_settings']['target_bundles'] = $settings['target_bundles'];
unset($settings['target_bundles']);
field_update_field($field);
}
}
// Update the instance configurations.
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$instance = field_info_instance($entity_type, $field_name, $bundle);
$save = FALSE;
if ($instance['widget']['type'] == 'entityreference_autocomplete') {
$instance['widget']['type'] = 'entityreference_autocomplete_tags';
$save = TRUE;
}
// When the autocomplete path is the default value, remove it from
// the configuration.
if (isset($instance['widget']['settings']['path']) && $instance['widget']['settings']['path'] == 'entityreference/autocomplete') {
unset($instance['widget']['settings']['path']);
$save = TRUE;
}
if ($save) {
field_update_instance($instance);
}
}
}
}
}