Commit dd437d05 authored by KarenS's avatar KarenS
Browse files

Add installation function to content migrate that will swap the stored...

Add installation function to content migrate that will swap the stored content_extra_weight values to the new field_bundle_settings variable. Also properly set the body weight, which is otherwise not right.
parent 01e7cc15
* Transfer weights from the D6 Manage Fields screen
* to the D7 stored settings array. Do this once only, on install,
* so later changes to these values in the Field UI screen will
* not be overwritten.
function content_migrate_install() {
$stored_settings = variable_get('field_bundle_settings', array());
// $stored_settings might be empty, set up the basic structure of the
// array to avoid errors.
if (empty($stored_settings) || !array_key_exists('node', $stored_settings)) {
$stored_settings['node'] = array();
foreach (node_type_get_names() as $type_name => $label) {
// This type name may not yet exist in the array, set it up.
if (!array_key_exists($type_name, $stored_settings['node'])) {
$stored_settings['node'][$type_name] = array(
'extra_fields' => array('form' => array(), 'display' => array()),
'view_modes' => array(),
$weights = variable_get('content_extra_weights_'. $type_name, array());
// If body has never been set in D6, it should be set to 0 to match the way D6 worked.
// The D7 core update may have set it to a value like -4.
if (empty($weights) || !array_key_exists('body_field', $weights)) {
$stored_settings['node'][$type_name]['extra_fields']['form']['body'] = array('weight' => 0);
// If a field name provided by a custom module has changed from D6 to D7,
// they will have to alter this array too. We will set the original
// field name, other modules could take this information and move it
// to a setting with the new field name.
// @TODO Have any of the other core field names changed?
// @TODO Should we do anything to alter the display settings?
foreach ($weights as $field => $weight) {
switch ($field) {
case 'body_field':
$new_field = 'body';
$new_field = $field;
$stored_settings['node'][$type_name]['extra_fields']['form'][$new_field] = array('weight' => $weight);
// While we're here, update the body field with the right weight.
$body_weight = !empty($weights['body_field']) ? $weights['body_field'] : 0;
$instance = field_info_instance('node', 'body', $type_name);
if (!empty($instance)) {
$instance['widget']['weight'] = $body_weight;
foreach ($instance['display'] as $context => $format) {
$instance['display'][$context]['weight'] = $body_weight;
variable_set('field_bundle_settings', $stored_settings);
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment