Commit 236e9d5d authored by yched's avatar yched
Browse files

Issue #1395400 by jalama, zeisilo, yched: Fixed migration of hidden fields...

Issue #1395400 by jalama, zeisilo, yched: Fixed migration of hidden fields causes hiccups when exporting with features
parent 26099e5e
......@@ -8,7 +8,7 @@
* Create a D7-style field array from data stored
* in the D6 content field tables.
*
* @param $field_name
* @param $field_name
* Optionally request only a specific field name.
*/
function _content_migrate_get_field_values($field_name = NULL) {
......@@ -25,10 +25,10 @@ function _content_migrate_get_field_values($field_name = NULL) {
->fields('nf')
->orderBy('type_name')
->execute();
foreach ($result as $row) {
$field_value = $row;
$query2 = db_select('content_node_field_instance', 'nfi', array('fetch' => PDO::FETCH_ASSOC));
$result2 = $query2
->fields('nfi')
......@@ -58,10 +58,10 @@ function _content_migrate_get_field_values($field_name = NULL) {
),
);
unset($field_value['widget_type'], $field_value['widget_module'], $field_value['widget_settings'], $field_value['display_settings']);
// All Drupal 6 fields were attached to nodes.
$field_value['entity_types'] = array();
if ($field_value['multiple'] == 0) {
$field_value['cardinality'] = 1;
}
......@@ -71,25 +71,25 @@ function _content_migrate_get_field_values($field_name = NULL) {
else {
$field_value['cardinality'] = $field_value['multiple'];
}
// We need column information for the old table.
$field_value['columns'] = unserialize($field_value['db_columns']);
// Field settings.
$default_settings = field_info_field_settings($row['type']);
$field_value['settings'] = array_merge($default_settings, unserialize($field_value['global_settings']));
unset($field_value['multiple'], $field_value['global_settings'], $field_value['required'], $field_value['db_columns']);
// Let modules change these values.
drupal_alter('content_migrate_field', $field_value, $instance_value);
unset($field_value['allowed_values_php']);
// We retain $field_value['columns'] and $field_value['db_storage']
// even though they are not used or different in D7
// even though they are not used or different in D7
// so we can find the old table information.
// Add field definiation to $field_values array.
$field_values[$field_value['field_name']] = $field_value;
}
......@@ -117,9 +117,9 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
$allowed_fields = field_info_field_types();
$allowed_widgets = field_info_widget_types();
$allowed_formatters = field_info_formatter_types();
$instance_values = array();
$query = db_select('content_node_field_instance', 'ni', array('fetch' => PDO::FETCH_ASSOC));
$node_field_alias = $query->join('content_node_field', 'nf', 'ni.field_name=nf.field_name');
$result = $query
......@@ -127,8 +127,8 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
->fields($node_field_alias, array('type', 'module', 'required', 'global_settings'))
->orderBy('label', 'ASC')
->execute();
foreach ($result as $row) {
foreach ($result as $row) {
$instance_value = $row;
$instance_value['messages'] = array();
......@@ -139,11 +139,11 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
'module' => $instance_value['module'],
'settings' => unserialize($instance_value['global_settings']),
);
unset($instance_value['type'], $instance_value['module'], $instance_value['required'], $instance_value['global_settings']);
unset($instance_value['type'], $instance_value['module'], $instance_value['required'], $instance_value['global_settings']);
// All Drupal 6 instances were attached to nodes.
$instance_value['entity_type'] = 'node';
// Unserialize arrays.
foreach (array('widget_settings', 'display_settings', 'global_settings') as $key) {
$instance_value[$key] = (!empty($instance_value[$key])) ? (array) unserialize($instance_value[$key]) : array();
......@@ -152,8 +152,8 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
// Build instance values.
$instance_value['bundle'] = $instance_value['type_name'];
$instance_value['default_value'] = !empty($instance_value['widget_settings']['default_value']) ? $instance_value['widget_settings']['default_value'] : '';
// Core does not support this, but retain it so
// Core does not support this, but retain it so
// another module can do something with it
// in drupal_alter.
if (isset($instance_value['widget_settings']['default_value_php'])) {
......@@ -162,16 +162,16 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
// Build widget values.
$instance_value['widget'] = array();
// TODO Some widget types have been renamed in D7.
$instance_value['widget']['type'] = $instance_value['widget_type'];
$instance_value['widget']['weight'] = $instance_value['weight'];
$instance_value['widget']['module'] = $instance_value['widget_module'];
$instance_value['widget']['active'] = $instance_value['widget_active'];
$default_settings = field_info_widget_settings($field_value['type']);
$instance_value['widget']['settings'] = array_merge($default_settings, $instance_value['widget_settings']);
// Build display values.
$instance_value['display'] = array();
$label = $instance_value['display_settings']['label'];
......@@ -185,25 +185,30 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
continue;
}
$instance_value['display'][$context]['label'] = $label['format'];
// The format used in D6 may not match the formatter in D7.
// Fix it using drupal_alter().
$instance_value['display'][$context]['type'] = $settings['format'];
$instance_value['display'][$context]['settings'] = field_info_formatter_settings($settings['format']);
$instance_value['display'][$context]['weight'] = $instance_value['weight'];
$instance_value['display'][$context]['module'] = $instance_value['widget_module'];
if ($settings['format'] == 'hidden') {
$instance_value['display'][$context]['settings'] = array();
unset($instance_value['display'][$context]['module']);
}
else {
$instance_value['display'][$context]['settings'] = field_info_formatter_settings($settings['format']);
$instance_value['display'][$context]['module'] = $instance_value['widget_module'];
}
}
// Unset unneeded values.
unset($instance_value['type_name'], $instance_value['global_settings'], $instance_value['widget_settings'], $instance_value['display_settings'], $instance_value['widget_module'], $instance_value['widget_active']);
// Unset some values that don't exist on all fields.
if (isset($instance_value['widget']['settings']['default_value'])) unset($instance_value['widget']['settings']['default_value']);
// Let modules change these values.
drupal_alter('content_migrate_instance', $instance_value, $field_value);
// Get rid of this value once CCK or some other module has handled it.
if (isset($instance_value['widget']['settings']['default_value_php'])) unset($instance_value['widget']['settings']['default_value_php']);
......@@ -244,7 +249,7 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
// Add instance information to instance array.
$instance_values['instances'][$instance_value['bundle']][$instance_value['field_name']] = $instance_value;
$instance_values['fields'][$instance_value['field_name']][$instance_value['bundle']] = $instance_value;
}
}
if (!empty($bundle)) {
......
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