diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index 6ac93fa7399bc9e5f26e61b47195f2035aba708d..48a97973bafa67db568049e7955ac61fd5a207ca 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -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); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 1af2f38fe6083a5f68a30282f43397e02246c304..df3b5057a90cd370fbf13fa93da667727c011f4e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -64,6 +64,9 @@ function testCreateFieldInstance() { $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 @@ function testReadFieldInstance() { // 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.'); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 2e6121ed568d75f3fd85c7aed49c931f0b0b8281..0073ed7930efe94e87cd0256c412f591bdc33e87 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -247,7 +247,7 @@ function testFieldFormMultivalueWithRequiredRadio() { '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 @@ function testFieldFormMultivalueWithRequiredRadio() { 'widget' => array( 'type' => 'options_buttons', ), - )); + ); + field_create_instance($instance); // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php index 7ee95011ea5026bf498d9aecdfa027ff9e580c9f..b410e1bbbaec5c87cf27a37966faa3f7914ac127 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/AlterTest.php @@ -54,7 +54,7 @@ function testDefaultWidgetPropertiesAlter() { '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 @@ function testDefaultWidgetPropertiesAlter() { '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 @@ function testDefaultWidgetPropertiesAlter() { '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 diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php index 3d11e26fb1639db64b1a2711ca53b6828fba0148..8dd2ab697c40f537e5184016d6ecc48e2185e950 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php @@ -39,11 +39,12 @@ public function setUp() { // 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); } /**