Commit 52a40bc9 authored by DamienMcKenna's avatar DamienMcKenna Committed by colan

Issue #1996770 by DamienMcKenna: Fix hook architecture.

parent 5bd112fa
......@@ -137,6 +137,7 @@ function content_migrate_old_columns($field_value, $instance_value) {
}
return $columns;
}
/**
* Helper function for figuring out column names
* to be used when storing D7 field data.
......@@ -160,64 +161,6 @@ function content_migrate_new_columns($field) {
}
}
/**
* Implements hook_content_migrate_field_alter().
*
* Use this to tweak the conversion of field settings
* from the D6 style to the D7 style for specific
* situations not handled by basic conversion,
* as when field types or settings are changed.
*/
function content_migrate_content_migrate_field_alter(&$field_value, $instance_value) {
module_load_include('inc', 'content_migrate', 'modules/content_migrate.filefield');
content_migrate_filefield_field_alter($field_value, $instance_value);
module_load_include('inc', 'content_migrate', 'modules/content_migrate.text');
content_migrate_text_field_alter($field_value, $instance_value);
module_load_include('inc', 'content_migrate', 'modules/content_migrate.number');
content_migrate_number_field_alter($field_value, $instance_value);
}
/**
* Implements hook_content_migrate_instance_alter().
*
* Use this to tweak the conversion of instance or widget settings
* from the D6 style to the D7 style for specific
* situations not handled by basic conversion, as when
* formatter or widget names or settings are changed.
*/
function content_migrate_content_migrate_instance_alter(&$instance_value, $field_value) {
module_load_include('inc', 'content_migrate', 'modules/content_migrate.filefield');
content_migrate_filefield_instance_alter($instance_value, $field_value);
module_load_include('inc', 'content_migrate', 'modules/content_migrate.text');
content_migrate_text_instance_alter($instance_value, $field_value);
module_load_include('inc', 'content_migrate', 'modules/content_migrate.number');
content_migrate_number_instance_alter($instance_value, $field_value);
module_load_include('inc', 'content_migrate', 'modules/content_migrate.optionwidgets');
content_migrate_optionwidgets_instance_alter($instance_value, $field_value);
}
/**
* Implements hook_content_migrate_data_record_alter().
*
* Tweaks individual records in a field.
*/
function content_migrate_content_migrate_data_record_alter(&$record, $field, $instance) {
module_load_include('inc', 'content_migrate', 'modules/content_migrate.filefield');
content_migrate_filefield_data_record_alter($record, $field, $instance);
}
/**
* Helper function for migrating D6-style allowed values into D7 arrays.
*
......
......@@ -4,6 +4,13 @@
* Code to process field data migration, moved into a separate file for efficiency.
*/
// Load the include files for each supported module. It is safe to do this here
// as this file is loaded for all actual processing.
include_once(dirname(__FILE__) . '/../modules/content_migrate.file.inc');
include_once(dirname(__FILE__) . '/../modules/content_migrate.number.inc');
include_once(dirname(__FILE__) . '/../modules/content_migrate.options.inc');
include_once(dirname(__FILE__) . '/../modules/content_migrate.text.inc');
/**
* Determine which fields can be migrated, have already been migrated, and are
* unable to be migrated due to missing modules.
......@@ -391,7 +398,8 @@ function _content_migrate_batch_process_migrate_data($field_name, &$context) {
$result = $query->execute();
foreach ($result as $record) {
module_load_include('inc', 'content_migrate', 'modules/content_migrate.' . $field['module']);
// Let modules alter this before the insert.
drupal_alter('content_migrate_data_record', $record, $field, $instance);
......
......@@ -273,4 +273,4 @@ function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL
return $instance_values['fields'][$field_name];
}
return $instance_values;
}
\ No newline at end of file
}
<?php
/**
* @file content_migrate.filefield.inc
* Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
* on behalf of the former filefield and imagefield modules, moved into a separate file for efficiency.
* @file content_migrate.file.inc
* Code to implement Content Migrate hooks on behalf of the File module.
*/
/**
......@@ -13,7 +12,7 @@
* situations not handled by basic conversion,
* as when field types or settings are changed.
*/
function content_migrate_filefield_field_alter(&$field_value, $instance_value) {
function file_content_migrate_field_alter(&$field_value, $instance_value) {
// There are a bunch of custom imagefield widgets. If they at least start the widget name with 'imagefield' this will work.
if (substr($instance_value['widget']['type'], 0, 10) == 'imagefield') {
......@@ -48,7 +47,7 @@ function content_migrate_filefield_field_alter(&$field_value, $instance_value) {
* situations not handled by basic conversion, as when
* formatter or widget names or settings are changed.
*/
function content_migrate_filefield_instance_alter(&$instance_value, $field_value) {
function file_content_migrate_instance_alter(&$instance_value, $field_value) {
// Translate formatters.
// There are a bunch of custom imagefield / filefield widgets. If they at
// least start the widget name with 'imagefield' / 'filefield', we can detect
......@@ -204,7 +203,7 @@ function content_migrate_filefield_instance_alter(&$instance_value, $field_value
*
* Tweaks individual records in a field.
*/
function content_migrate_filefield_data_record_alter(&$record, $field, $instance) {
function file_content_migrate_data_record_alter(&$record, $field, $instance) {
switch($field['type']) {
case 'image':
......
<?php
/**
* @file content_migrate.number.inc
* Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
* on behalf of the former number module, moved into a separate file for efficiency.
* Code to implement Content Migrate hooks on behalf of the Number module.
*/
/**
......@@ -13,7 +12,7 @@
* situations not handled by basic conversion,
* as when field types or settings are changed.
*/
function content_migrate_number_field_alter(&$field_value, $instance_value) {
function number_content_migrate_field_alter(&$field_value, $instance_value) {
switch ($field_value['type']) {
case 'number_integer':
......@@ -72,7 +71,7 @@ function content_migrate_number_field_alter(&$field_value, $instance_value) {
* situations not handled by basic conversion, as when
* formatter or widget names or settings are changed.
*/
function content_migrate_number_instance_alter(&$instance_value, $field_value) {
function number_content_migrate_instance_alter(&$instance_value, $field_value) {
switch ($field_value['module']) {
case 'number':
// The number formatters and formatter settings
......
<?php
/**
* @file content_migrate.optionwidgets.inc
* Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
* on behalf of the former optionwidgets module, moved into a separate file for efficiency.
* @file content_migrate.options.inc
* Code to implement Content Migrate hooks on behalf of the Options module.
*/
/**
......@@ -13,8 +12,7 @@
* situations not handled by basic conversion, as when
* formatter or widget names or settings are changed.
*/
function content_migrate_optionwidgets_instance_alter(&$instance_value, $field_value) {
function options_content_migrate_instance_alter(&$instance_value, $field_value) {
switch ($instance_value['widget']['module']) {
// Optionswidgets module became Options module
// and widget type names changed.
......@@ -28,5 +26,4 @@ function content_migrate_optionwidgets_instance_alter(&$instance_value, $field_v
$instance_value['widget']['type'] = strtr($instance_value['widget']['type'], $replace);
break;
}
}
<?php
/**
* @file content_migrate.text.inc
* Code to implement hook_content_migrate_field_alter, content_migrate_instance_alter() and content_migrate_data_record_alter()
* on behalf of the former text module, moved into a separate file for efficiency.
* Code to implement Content Migrate hooks on behalf of the Text module.
*/
/**
......@@ -13,7 +12,7 @@
* situations not handled by basic conversion,
* as when field types or settings are changed.
*/
function content_migrate_text_field_alter(&$field_value, $instance_value) {
function text_content_migrate_field_alter(&$field_value, $instance_value) {
switch ($field_value['type']) {
case 'text':
......@@ -78,10 +77,17 @@ function content_migrate_text_field_alter(&$field_value, $instance_value) {
case 'list_text':
case 'list_boolean':
$allowed_values = array();
$legacy_values = array();
if (!empty($field_value['settings']['allowed_values'])) {
$allowed_values = content_migrate_extract_allowed_values($field_value['settings']['allowed_values'], $field_value['type']);
// Keep a copy of the legacy values.
if (isset($allowed_values['legacy_values'])) {
$legacy_values = $allowed_values['legacy_values'];
}
unset($allowed_values['legacy_values']);
}
$field_value['settings']['allowed_values'] = $allowed_values;
$field_value['settings']['legacy_values'] = $legacy_values;
break;
}
......@@ -99,7 +105,7 @@ function content_migrate_text_field_alter(&$field_value, $instance_value) {
* situations not handled by basic conversion, as when
* formatter or widget names or settings are changed.
*/
function content_migrate_text_instance_alter(&$instance_value, $field_value) {
function text_content_migrate_instance_alter(&$instance_value, $field_value) {
switch ($field_value['module']) {
case 'text':
......@@ -122,13 +128,13 @@ function content_migrate_text_instance_alter(&$instance_value, $field_value) {
*
* Tweaks individual records in a field.
*/
function content_migrate_text_data_record_alter(&$record, $field, $instance) {
function text_content_migrate_data_record_alter(&$record, $field, $instance) {
$existing_formats = &drupal_static(__FUNCTION__);
if (empty($existing_formats)) {
$existing_formats = db_query("SELECT format FROM {filter_format}")->fetchCol();
}
switch($field_value['module']) {
switch($field['module']) {
case 'text':
if (!empty($instance['settings']['text_processing'])) {
// Adapted from node_update_7006(), to adjust the filter format values
......@@ -137,5 +143,6 @@ function content_migrate_text_data_record_alter(&$record, $field, $instance) {
$record[$field['field_name'] . '_format'] = variable_get('filter_default_format', 1);
}
}
break;
}
}
\ 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