diff --git a/entityreference.install b/entityreference.install index cc7bce5..c06fcbc 100644 --- a/entityreference.install +++ b/entityreference.install @@ -163,3 +163,38 @@ function entityreference_update_7002() { )); } } + +/** + * Move selection handler config to field instance settings. + */ +function entityreference_update_7003() { + // 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'. + foreach (field_info_fields() as $field_name => $field) { + if ($field['type'] == 'entityreference') { + // Update the instances configuration. + foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($bundles as $bundle) { + $instance = field_info_instance($entity_type, $field_name, $bundle); + $updated = FALSE; + if (isset($field['settings']['handler']) && empty($instance['settings']['handler'])) { + $instance['settings']['handler'] = $field['settings']['handler']; + $updated = TRUE; + } + $instance['settings']['handler_settings'] = $field['settings']['handler_settings']; + if (isset($field['settings']['handler_settings']) && empty($instance['settings']['handler_settings'])) { + $instance['settings']['handler_settings'] = $field['settings']['handler_settings']; + $updated = TRUE; + } + if ($updated) { + field_update_instance($instance); + } + } + } + } + } +}