Download & Extend

Date Fields not set properly when bulk created through Batch

Project:Date
Version:7.x-2.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

When importing Date fields through a batch in the manner shown below, we end up with date fields who display they are of the type Date with a text widget, but are actually using the popup widget. This of course can be fixed by manually changing the widget type from popup to text to get everything back in sync. If the widget is not changed then a Database Transaction Out of Order Exception is thrown when using the field. Perhaps I have not properly set the fields in the batch creation, but my question is what is the easiest way to loop through all the date fields in an entity (there are about 4,000 fields) and properly set the widget to text / set the collection to only year, month, and day?

<?php
if ($field_name_calendar != '' && $field_name_calendar != NULL) {
       
$fields_array_date = array(
            array(
               
'field' => array(
                   
'field_name' => 'field_' . $name . '_date',
                   
'type' => 'datetime',
                   
'cardinality' => 1,
                   
'label' => 'Calendar',
                   
'settings' => array(),
                ),
               
'instance' => array(
                   
'field_name' => 'field_' . $name . '_date',
                   
'entity_type' => 'field_collection_item',
                   
'bundle' => $field_bundle,
                   
'label' => 'Calendar',
                   
'cardinality' => 1,
                   
'description' => '',
                   
'#default_value' => NULL,
                   
'widget' => array(
                       
'type' => 'text_textfield',
                       
'weight' => 0,
                       
'settings' => array('size' => 50),
                    ),
                   
'display' => array(
                       
'default' => array(
                           
'label' => 'above',
                           
'settings' => array(),
                           
'weight' => 1,
                        ),
                       
'teaser' => array(
                           
'label' => 'above',
                           
'settings' => array(),
                           
'type' => 'hidden',
                        ),
                    ),
                   
'required' => FALSE,
                )
            ),
        );
// Loop through date fields array and create field and instance
       
foreach ($fields_array_date as $field) {
// Check if field already exists
           
if (!field_info_field($field['field']['field_name'])) {
               
field_create_field($field['field']);
            }

// Check if instance exists
           
if (!field_info_instance($field['instance']['entity_type'], $field['instance']['field_name'], $field['instance']['bundle'])) {
               
field_create_instance($field['instance']);
            }
           
$new_group->children[] = 'field_' . name . '_date';
        }

    }

?>

Comments

#1

Title:Date Fields not set properly when bulk created through Feeds» Date Fields not set properly when bulk created through Batch
nobody click here