Issue #1312200 by zuuperman, lemark, chx: Fixed field_create_instance() must fill in the id field but does not.

8.0.x
webchick 2012-09-26 23:47:21 -04:00
parent 3c66dae84e
commit 1881251335
5 changed files with 24 additions and 16 deletions

View File

@ -455,7 +455,7 @@ function field_delete_field($field_name) {
*
* See: @link field Field API data structures @endlink.
*/
function field_create_instance($instance) {
function field_create_instance(&$instance) {
$field = field_read_field($instance['field_name']);
if (empty($field)) {
throw new FieldException(t("Attempt to create an instance of a field @field_name that doesn't exist or is currently inactive.", array('@field_name' => $instance['field_name'])));
@ -555,7 +555,7 @@ function field_update_instance($instance) {
* @param $update
* Whether this is a new or existing instance.
*/
function _field_write_instance($instance, $update = FALSE) {
function _field_write_instance(&$instance, $update = FALSE) {
$field = field_read_field($instance['field_name']);
$field_type = field_info_field_types($field['type']);
@ -639,12 +639,12 @@ function _field_write_instance($instance, $update = FALSE) {
// update.
if ($update) {
$record['id'] = $instance['id'];
$primary_key = array('id');
drupal_write_record('field_config_instance', $record, array('id'));
}
else {
$primary_key = array();
drupal_write_record('field_config_instance', $record);
$instance['id'] = $record['id'];
}
drupal_write_record('field_config_instance', $record, $primary_key);
}
/**

View File

@ -64,6 +64,9 @@ class FieldInstanceCrudTest extends FieldTestBase {
$widget_type = field_info_widget_types($field_type['default_widget']);
$formatter_type = field_info_formatter_types($field_type['default_formatter']);
// Check that the ID key is filled in.
$this->assertIdentical($record['id'], $this->instance_definition['id'], 'The instance id is filled in');
// Check that default values are set.
$this->assertIdentical($record['data']['required'], FALSE, t('Required defaults to false.'));
$this->assertIdentical($record['data']['label'], $this->instance_definition['field_name'], t('Label defaults to field name.'));
@ -140,7 +143,7 @@ class FieldInstanceCrudTest extends FieldTestBase {
// Read the instance back.
$instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue($this->instance_definition < $instance, t('The field was properly read.'));
$this->assertTrue($this->instance_definition == $instance, 'The field was properly read.');
}
/**

View File

@ -247,7 +247,7 @@ class FormTest extends FieldTestBase {
'allowed_values' => array('yes' => 'yes', 'no' => 'no'),
),
));
field_create_instance(array(
$instance = array(
'field_name' => 'required_radio_test',
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
@ -255,7 +255,8 @@ class FormTest extends FieldTestBase {
'widget' => array(
'type' => 'options_buttons',
),
));
);
field_create_instance($instance);
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');

View File

@ -54,7 +54,7 @@ class AlterTest extends WebTestBase {
'field_name' => 'alter_test_text',
'type' => 'text',
));
field_create_instance(array(
$instance = array(
'field_name' => 'alter_test_text',
'entity_type' => 'node',
'bundle' => 'article',
@ -62,7 +62,8 @@ class AlterTest extends WebTestBase {
'type' => 'text_textfield',
'size' => 60,
),
));
);
field_create_instance($instance);
// Test that field_test_field_widget_properties_alter() sets the size to
// 42 and that field_test_field_widget_form_alter() reports the correct
@ -79,22 +80,24 @@ class AlterTest extends WebTestBase {
'type' => 'list_text'
));
// Create instances on users and page nodes.
field_create_instance(array(
$instance = array(
'field_name' => 'alter_test_options',
'entity_type' => 'user',
'bundle' => 'user',
'widget' => array(
'type' => 'options_select',
)
));
field_create_instance(array(
);
field_create_instance($instance);
$instance = array(
'field_name' => 'alter_test_options',
'entity_type' => 'node',
'bundle' => 'page',
'widget' => array(
'type' => 'options_select',
)
));
);
field_create_instance($instance);
// Test that field_test_field_widget_properties_user_alter() replaces
// the widget and that field_test_field_widget_form_alter() reports the

View File

@ -39,11 +39,12 @@ class NodeAccessFieldTest extends NodeTestBase {
// Add a custom field to the page content type.
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
$this->field = field_create_field(array('field_name' => $this->field_name, 'type' => 'text'));
$this->instance = field_create_instance(array(
$instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => 'page',
));
);
$this->instance = field_create_instance($instance);
}
/**