Commit c4e54e0e authored by KarenS's avatar KarenS
Browse files

Issue #1039466 Add some warning messages if the widget or formatter is missing...

Issue #1039466 Add some warning messages if the widget or formatter is missing when the field is migrated, but allow the migration, they will be set to use the default widget and formatter.
parent 93c4b5fc
......@@ -37,8 +37,11 @@ function content_migrate_get_options() {
$bundles[] = $type_names[$bundle];
$label = $instance_value['label'];
if (!in_array($instance_value['widget']['module'], $available_modules)) {
$missing_module = TRUE;
$missing_modules[] = $instance_value['widget']['module'];
// A missing widget module is not fatal, but we should warn the user.
//$missing_module = TRUE;
if ($instance_value['widget']['module'] != $field_value['module']) {
$missing_modules[] = $instance_value['widget']['module'];
}
}
}
$data = array(
......@@ -204,6 +207,10 @@ function _content_migrate_batch($field_names) {
*/
function _content_migrate_batch_process_create_fields($field_name, &$context) {
$type_names = node_type_get_names();
$allowed_fields = field_info_field_types();
$allowed_widgets = field_info_widget_types();
$allowed_formatters = field_info_formatter_types();
$context['message'] = t('"Creating field: %field', array('%field' => $field_name));
$field_value = content_migrate_get_field_values($field_name);
......@@ -226,6 +233,21 @@ function _content_migrate_batch_process_create_fields($field_name, &$context) {
foreach ($instance_values as $bundle => $instance_value) {
try {
// Warn about missing or invalid widgets or formatters.
if (!array_key_exists($instance_value['widget']['type'], $allowed_widgets)) {
drupal_set_message(t('The @widget widget is not available for the @field field, setting to default widget.', array('@widget' => $instance_value['widget']['type'], '@field' => $field_name)), 'warning');
}
foreach ($instance_value['display'] as $context => $settings) {
if ($context == 'label' || $context == 'parent' || $context == 'weight') {
continue;
}
if (!array_key_exists( $settings['type'], $allowed_formatters)) {
drupal_set_message(t('The @formatter formatter used in the @context context is not available for the @field field, setting to default formatter.', array('@formatter' => $settings['type'], '@context' => $context, '@field' => $field_name)), 'warning');
}
}
$instance = field_create_instance($instance_value);
$context['instances'][$field_name][$instance['bundle']] = $instance;
drupal_set_message(t("Created instance of @field_name in bundle @bundle.", array(
......
......@@ -93,7 +93,7 @@ function _content_migrate_get_field_values($field_name = NULL) {
*/
function _content_migrate_get_instance_values($bundle = NULL, $field_name = NULL) {
$instance_values = &drupal_static(__FUNCTION__);
if (empty($instance_values) && db_table_exists('content_node_field_instance')) {
$instance_values = array();
$query = db_select('content_node_field_instance', 'ni', array('fetch' => PDO::FETCH_ASSOC));
......
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