function entityreference_autofill_update_7001 in Entity reference autofill 7
Move widget settings to behavior class settings.
File
- ./
entityreference_autofill.install, line 56 - Install and update functions for the Entity reference autofill module.
Code
function entityreference_autofill_update_7001() {
// Rebuild settings.
$field_map = field_info_field_map();
$enabled_fields = array();
foreach ($field_map as $field_name => $field) {
if ($field['type'] !== 'entityreference') {
continue;
}
foreach ($field['bundles'] as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$field_info = field_info_instance($entity_type, $field_name, $bundle);
$field_widget = $field_info['widget'];
$is_ac_widget = $field_widget['type'] === 'entityreference_autocomplete';
$is_enabled = $is_ac_widget && $field_widget['settings']['autofill']['enabled'];
if ($is_enabled) {
// Remove enabled setting.
$field_widget['settings']['autofill']['status'] = $field_widget['settings']['autofill']['enabled'];
unset($field_widget['settings']['autofill']['enabled']);
$field_info['settings']['behaviors']['autofill'] = $field_widget['settings']['autofill'];
// Remove old settings.
unset($field_widget['settings']['autofill']);
field_update_instance($field_info);
}
}
}
}
_entityreference_autofill_get_settings(TRUE);
}