diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 4a03975..4dff7b0 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -292,7 +292,7 @@ protected function submitEntityLanguage(array $form, array &$form_state) { // Handle a possible language change: new language values are inserted, // previous ones are deleted. - if ($field['translatable'] && $previous_langcode != $current_langcode) { + if ($field->translatable && $previous_langcode != $current_langcode) { $form_state['values'][$field_name][$current_langcode] = $form_state['values'][$field_name][$previous_langcode]; $form_state['values'][$field_name][$previous_langcode] = array(); } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 42e4d77..7f0b84f 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -195,7 +195,7 @@ public function processDefinition(&$definition, $plugin_id) { // Prepare entity schema fields SQL info for // Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery(). - if (isset($definition['base_table'])) { + if (isset($definition['base_table']) && drupal_get_schema($definition['base_table']) !== FALSE) { $definition['schema_fields_sql']['base_table'] = drupal_schema_fields_sql($definition['base_table']); if (isset($definition['data_table'])) { $definition['schema_fields_sql']['data_table'] = drupal_schema_fields_sql($definition['data_table']); diff --git a/core/modules/comment/comment.install b/core/modules/comment/comment.install index 48bb5a4..2c6d416 100644 --- a/core/modules/comment/comment.install +++ b/core/modules/comment/comment.install @@ -16,7 +16,7 @@ function comment_uninstall() { variable_del('comment_block_count'); $node_types = array_keys(node_type_get_types()); foreach ($node_types as $node_type) { - field_attach_delete_bundle('comment', 'comment_node_' . $node_type); + field_attach_delete_bundle('comment', 'comment_node_' . $node_type, FALSE); variable_del('comment_' . $node_type); variable_del('comment_anonymous_' . $node_type); variable_del('comment_controls_' . $node_type); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php index a29db8c..1282363 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentFieldsTest.php @@ -41,7 +41,7 @@ function testCommentDefaultFields() { $this->assertTrue(isset($instances['comment_node_' . $type_name]['comment_body']), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name))); // Delete the instance along the way. - field_delete_instance($instances['comment_node_' . $type_name]['comment_body']); + field_delete_instance($instances['comment_node_' . $type_name]['comment_body']->getArray()); } // Check that the 'comment_body' field is deleted. diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 35a935e..c644660 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -71,7 +71,7 @@ function setUp() { // Make comment body translatable. $field = field_info_field('comment_body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; field_update_field($field); $this->assertTrue(field_is_translatable('comment', $field), 'Comment body is translatable.'); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index c67e2b9..7c97769 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -64,7 +64,7 @@ protected function getTranslatorPermissions() { function setupTestFields() { parent::setupTestFields(); $field = field_info_field('comment_body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; field_update_field($field); } diff --git a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php index 7170030..a9e151c 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/Views/ContactFieldsTest.php @@ -58,7 +58,7 @@ protected function setUp() { * Tests the views data generation. */ public function testViewsData() { - $field_name = $this->field['field_name']; + $field_name = $this->field->field_name; $table_name = _field_sql_storage_tablename($this->field); $data = drupal_container()->get('views.views_data')->get($table_name); diff --git a/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php b/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php index 0a386c5..b2da1d9 100644 --- a/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php +++ b/core/modules/edit/lib/Drupal/edit/Plugin/edit/editor/DirectEditor.php @@ -32,7 +32,7 @@ function isCompatible(FieldInstance $instance, array $items) { $field = field_info_field($instance['field_name']); // This editor is incompatible with multivalued fields. - if ($field['cardinality'] != 1) { + if ($field->cardinality != 1) { return FALSE; } // This editor is incompatible with processed ("rich") text fields. diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php index 18d92d8..4216fe9 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php @@ -58,12 +58,12 @@ function setUp() { */ function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) { $field = $field_name . '_field'; - $this->$field = array( + $field_definition = array( 'field_name' => $field_name, 'type' => $type, 'cardinality' => $cardinality, ); - $this->$field_name = field_create_field($this->$field); + $this->$field = field_create_field($field_definition); $instance = $field_name . '_instance'; $this->$instance = array( diff --git a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php index 199a525..1fd6b89 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php @@ -89,7 +89,7 @@ function testText() { $this->assertEqual('direct', $this->getSelectedEditor($items, $field_name), "Without text processing again, cardinality 1, the 'direct' editor is selected."); // Editor selection without text processing, cardinality >1 - $this->field_text_field['cardinality'] = 2; + $this->field_text_field->cardinality = 2; field_update_field($this->field_text_field); $items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html'); $this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "Without text processing, cardinality >1, the 'form' editor is selected."); @@ -134,7 +134,7 @@ function testTextWysiwyg() { $this->assertEqual('wysiwyg', $this->getSelectedEditor($items, $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected."); // Editor selection with text processing, cardinality >1 - $this->field_textarea_field['cardinality'] = 2; + $this->field_textarea_field->cardinality = 2; field_update_field($this->field_textarea_field); $items[] = array('value' => 'Hallo, wereld!', 'format' => 'full_html'); $this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected."); @@ -164,7 +164,7 @@ function testNumber() { $this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality 1, the 'form' editor is selected."); // Editor selection with cardinality >1. - $this->field_nr_field['cardinality'] = 2; + $this->field_nr_field->cardinality = 2; field_update_field($this->field_nr_field); $this->assertEqual('form', $this->getSelectedEditor($items, $field_name), "With cardinality >1, the 'form' editor is selected."); } diff --git a/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php b/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php index 943848f..5b4a53a 100644 --- a/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php +++ b/core/modules/edit/tests/modules/lib/Drupal/edit_test/Plugin/edit/editor/WysiwygEditor.php @@ -30,7 +30,7 @@ function isCompatible(FieldInstance $instance, array $items) { $field = field_info_field($instance['field_name']); // This editor is incompatible with multivalued fields. - if ($field['cardinality'] != 1) { + if ($field->cardinality != 1) { return FALSE; } // This editor is compatible with processed ("rich") text fields; but only diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index c719c97..9bc4dcd 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -49,9 +49,9 @@ function testEmailField() { 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'email', ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -64,7 +64,7 @@ function testEmailField() { field_create_instance($this->instance); // Create a display for the full view mode. entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->field_name, array( 'type' => 'email_mailto', )) ->save(); @@ -72,13 +72,13 @@ function testEmailField() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); $langcode = LANGUAGE_NOT_SPECIFIED; - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget found.'); + $this->assertFieldByName("{$this->field->field_name}[$langcode][0][value]", '', 'Widget found.'); $this->assertRaw('placeholder="example@example.com"'); // Submit a valid e-mail address and ensure it is accepted. $value = 'test@example.com'; $edit = array( - "{$this->field['field_name']}[$langcode][0][value]" => $value, + "{$this->field->field_name}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); diff --git a/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityDisplay.php b/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityDisplay.php index 9048788..8d4e99a 100644 --- a/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityDisplay.php +++ b/core/modules/entity/lib/Drupal/entity/Plugin/Core/Entity/EntityDisplay.php @@ -239,7 +239,7 @@ public function setComponent($name, array $options = array()) { if ($instance = field_info_instance($this->targetEntityType, $name, $this->bundle)) { $field = field_info_field($instance['field_name']); - $options = drupal_container()->get('plugin.manager.field.formatter')->prepareConfiguration($field['type'], $options); + $options = drupal_container()->get('plugin.manager.field.formatter')->prepareConfiguration($field->type, $options); // Clear the persisted formatter, if any. unset($this->formatters[$name]); diff --git a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php index 6d213f6..771339b 100644 --- a/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php +++ b/core/modules/entity/lib/Drupal/entity/Tests/EntityDisplayTest.php @@ -145,17 +145,17 @@ public function testFieldComponent() { 'field_name' => 'test_field', 'type' => 'test_field' ); - field_create_field($field); + $field = field_create_field($field); $instance = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); field_create_instance($instance); // Check that providing no options results in default values being used. - $display->setComponent($field['field_name']); - $field_type_info = field_info_field_types($field['type']); + $display->setComponent($field->field_name); + $field_type_info = field_info_field_types($field->type); $default_formatter = $field_type_info['default_formatter']; $default_settings = field_info_formatter_settings($default_formatter); $expected = array( @@ -164,10 +164,10 @@ public function testFieldComponent() { 'type' => $default_formatter, 'settings' => $default_settings, ); - $this->assertEqual($display->getComponent($field['field_name']), $expected); + $this->assertEqual($display->getComponent($field->field_name), $expected); // Check that the getFormatter() method returns the correct formatter plugin. - $formatter = $display->getFormatter($field['field_name']); + $formatter = $display->getFormatter($field->field_name); $this->assertEqual($formatter->getPluginId(), $default_formatter); $this->assertEqual($formatter->getSettings(), $default_settings); @@ -175,26 +175,26 @@ public function testFieldComponent() { // arbitrary property and reading it back. $random_value = $this->randomString(); $formatter->randomValue = $random_value; - $formatter = $display->getFormatter($field['field_name']); + $formatter = $display->getFormatter($field->field_name); $this->assertEqual($formatter->randomValue, $random_value ); // Check that changing the definition creates a new formatter. - $display->setComponent($field['field_name'], array( + $display->setComponent($field->field_name, array( 'type' => 'field_test_multiple', )); - $formatter = $display->getFormatter($field['field_name']); + $formatter = $display->getFormatter($field->field_name); $this->assertEqual($formatter->getPluginId(), 'field_test_multiple'); $this->assertFalse(isset($formatter->randomValue)); // Check that specifying an unknown formatter (e.g. case of a disabled // module) gets stored as is in the display, but results in the default // formatter being used. - $display->setComponent($field['field_name'], array( + $display->setComponent($field->field_name, array( 'type' => 'unknown_formatter', )); - $options = $display->getComponent($field['field_name']); + $options = $display->getComponent($field->field_name); $this->assertEqual($options['type'], 'unknown_formatter'); - $formatter = $display->getFormatter($field['field_name']); + $formatter = $display->getFormatter($field->field_name); $this->assertEqual($formatter->getPluginId(), $default_formatter); } diff --git a/core/modules/entity_reference/entity_reference.install b/core/modules/entity_reference/entity_reference.install index 1de70ca..5c18a84 100644 --- a/core/modules/entity_reference/entity_reference.install +++ b/core/modules/entity_reference/entity_reference.install @@ -34,7 +34,7 @@ function entity_reference_field_schema($field) { // Create a foreign key to the target entity type base type. // @todo It's still not safe to call entity_get_info() in here. // see http://drupal.org/node/1847582 - // $entity_type = $field['settings']['target_type']; + // $entity_type = $field->settings['target_type']; // $entity_info = entity_get_info($entity_type); // // $base_table = $entity_info['base_table']; diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index 4e98d15..4f2fc3b 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -46,10 +46,10 @@ function entity_reference_entity_field_info($entity_type) { foreach (field_info_instances($entity_type) as $bundle_name => $instances) { foreach ($instances as $field_name => $instance) { $field = field_info_field($field_name); - if ($field['type'] != 'entity_reference') { + if ($field->type != 'entity_reference') { continue; } - $property_info['definitions'][$field_name]['settings']['target_type'] = $field['settings']['target_type']; + $property_info['definitions'][$field_name]['settings']['target_type'] = $field->settings['target_type']; } } return $property_info; @@ -113,7 +113,7 @@ function entity_reference_field_is_empty($item, $field) { */ function entity_reference_field_presave(EntityInterface $entity, $field, $instance, $langcode, &$items) { global $user; - $target_type = $field['settings']['target_type']; + $target_type = $field->settings['target_type']; $entity_info = entity_get_info($target_type); $bundles = entity_get_bundles($target_type); @@ -160,9 +160,9 @@ function entity_reference_field_validate(EntityInterface $entity = NULL, $field, $invalid_entities = array_diff_key($ids, array_flip($valid_ids)); if ($invalid_entities) { foreach ($invalid_entities as $id => $delta) { - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$field->field_name][$langcode][$delta][] = array( 'error' => 'entity_reference_invalid_entity', - 'message' => t('The referenced entity (@type: @id) does not exist.', array('@type' => $field['settings']['target_type'], '@id' => $id)), + 'message' => t('The referenced entity (@type: @id) does not exist.', array('@type' => $field->settings['target_type'], '@id' => $id)), ); } } @@ -188,7 +188,7 @@ function entity_reference_field_settings_form($field, $instance, $has_data) { '#type' => 'select', '#title' => t('Target type'), '#options' => $entity_type_options, - '#default_value' => $field['settings']['target_type'], + '#default_value' => $field->settings['target_type'], '#required' => TRUE, '#description' => t('The entity type that can be referenced through this field.'), '#disabled' => $has_data, @@ -204,24 +204,24 @@ function entity_reference_field_settings_form($field, $instance, $has_data) { * Reset the instance handler settings, when the target type is changed. */ function entity_reference_field_update_field($field, $prior_field, $has_data) { - if ($field['type'] != 'entity_reference') { + if ($field->type != 'entity_reference') { // Not an entity reference field. return; } - if ($field['settings']['target_type'] == $prior_field['settings']['target_type']) { + if ($field->settings['target_type'] == $prior_field->settings['target_type']) { // Target type didn't change. return; } - if (empty($field['bundles'])) { + if (empty($field->bundles)) { // Field has no instances. return; } - $field_name = $field['field_name']; + $field_name = $field->field_name; - foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($field->bundles as $entity_type => $bundles) { foreach ($bundles as $bundle) { $instance = field_info_instance($entity_type, $field_name, $bundle); $instance['settings']['handler_settings'] = array(); @@ -241,7 +241,7 @@ function entity_reference_field_instance_settings_form($field, $instance, $form_ $settings += array('handler' => 'default'); // Get all selection plugins for this entity type. - $selection_plugins = drupal_container()->get('plugin.manager.entity_reference.selection')->getSelectionGroups($field['settings']['target_type']); + $selection_plugins = drupal_container()->get('plugin.manager.entity_reference.selection')->getSelectionGroups($field->settings['target_type']); $handler_groups = array_keys($selection_plugins); $handlers = drupal_container()->get('plugin.manager.entity_reference.selection')->getDefinitions(); @@ -399,7 +399,7 @@ function entity_reference_options_list($field, $instance, $entity_type = NULL, $ } // Rebuild the array by changing the bundle key into the bundle label. - $target_type = $field['settings']['target_type']; + $target_type = $field->settings['target_type']; $bundles = entity_get_bundles($target_type); $return = array(); @@ -442,7 +442,7 @@ function entity_reference_autocomplete_access_callback($type, $field_name, $enti return FALSE; } - if ($field['type'] != 'entity_reference' || !field_access('edit', $field, $entity_type)) { + if ($field->type != 'entity_reference' || !field_access('edit', $field, $entity_type)) { return FALSE; } @@ -503,7 +503,7 @@ function entity_reference_autocomplete_callback($type, $field_name, $entity_type * @see entity_reference_autocomplete_callback() */ function entity_reference_autocomplete_callback_get_matches($type, $field, $instance, $entity_type, $entity_id = '', $string = '') { - $target_type = $field['settings']['target_type']; + $target_type = $field->settings['target_type']; $matches = array(); $entity = NULL; diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php index af91a2d..b2abc72 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/Type/SelectionPluginManager.php @@ -47,7 +47,7 @@ public function createInstance($plugin_id, array $configuration = array()) { */ public function getInstance(array $options) { $selection_handler = $options['instance']['settings']['handler']; - $target_entity_type = $options['field']['settings']['target_type']; + $target_entity_type = $options['field']->settings['target_type']; // Get all available selection plugins for this entity type. $selection_handler_groups = $this->getSelectionGroups($target_entity_type); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php index 205df06..fa6a290 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/entity_reference/selection/SelectionBase.php @@ -63,8 +63,8 @@ public function __construct($field, $instance, EntityInterface $entity = NULL) { * Implements SelectionInterface::settingsForm(). */ public static function settingsForm(&$field, &$instance) { - $entity_info = entity_get_info($field['settings']['target_type']); - $bundles = entity_get_bundles($field['settings']['target_type']); + $entity_info = entity_get_info($field->settings['target_type']); + $bundles = entity_get_bundles($field->settings['target_type']); // Merge-in default values. if (!isset($instance['settings']['handler_settings'])) { @@ -86,10 +86,10 @@ public static function settingsForm(&$field, &$instance) { $target_bundles_title = t('Bundles'); // Default core entity types with sensible labels. - if ($field['settings']['target_type'] == 'node') { + if ($field->settings['target_type'] == 'node') { $target_bundles_title = t('Content types'); } - elseif ($field['settings']['target_type'] == 'taxonomy_term') { + elseif ($field->settings['target_type'] == 'taxonomy_term') { $target_bundles_title = t('Vocabularies'); } @@ -113,10 +113,10 @@ public static function settingsForm(&$field, &$instance) { // @todo Use Entity::getPropertyDefinitions() when all entity types are // converted to the new Field API. $fields = drupal_map_assoc($entity_info['schema_fields_sql']['base_table']); - foreach (field_info_instances($field['settings']['target_type']) as $bundle_instances) { + foreach (field_info_instances($field->settings['target_type']) as $bundle_instances) { foreach ($bundle_instances as $instance_name => $instance_info) { $field_info = field_info_field($instance_name); - foreach ($field_info['columns'] as $column_name => $column_info) { + foreach ($field_info->columns as $column_name => $column_info) { $fields[$instance_name . '.' . $column_name] = t('@label (@column)', array('@label' => $instance_info['label'], '@column' => $column_name)); } } @@ -164,7 +164,7 @@ public static function settingsForm(&$field, &$instance) { * Implements SelectionInterface::getReferencableEntities(). */ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { - $target_type = $this->field['settings']['target_type']; + $target_type = $this->field->settings['target_type']; $query = $this->buildEntityQuery($match, $match_operator); if ($limit > 0) { @@ -203,7 +203,7 @@ public function countReferencableEntities($match = NULL, $match_operator = 'CONT public function validateReferencableEntities(array $ids) { $result = array(); if ($ids) { - $target_type = $this->field['settings']['target_type']; + $target_type = $this->field->settings['target_type']; $entity_info = entity_get_info($target_type); $query = $this->buildEntityQuery(); $result = $query @@ -263,7 +263,7 @@ public function validateAutocompleteInput($input, &$element, &$form_state, $form * it. */ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { - $target_type = $this->field['settings']['target_type']; + $target_type = $this->field->settings['target_type']; $entity_info = entity_get_info($target_type); $query = entity_query($target_type); @@ -276,7 +276,7 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { } // Add entity-access tag. - $query->addTag($this->field['settings']['target_type'] . '_access'); + $query->addTag($this->field->settings['target_type'] . '_access'); // Add the Selection handler for // entity_reference_query_entity_reference_alter(). diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php index 98cc69c..4d470b4 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php @@ -36,7 +36,7 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { * Overrides \Drupal\entity_reference\Plugin\field\formatter\EntityReferenceFormatterBase::settingsForm(). */ public function settingsForm(array $form, array &$form_state) { - $view_modes = entity_get_view_modes($this->field['settings']['target_type']); + $view_modes = entity_get_view_modes($this->field->settings['target_type']); $options = array(); foreach ($view_modes as $view_mode => $view_mode_settings) { $options[$view_mode] = $view_mode_settings['label']; @@ -65,7 +65,7 @@ public function settingsForm(array $form, array &$form_state) { public function settingsSummary() { $summary = array(); - $view_modes = entity_get_view_modes($this->field['settings']['target_type']); + $view_modes = entity_get_view_modes($this->field->settings['target_type']); $view_mode = $this->getSetting('view_mode'); $summary[] = t('Rendered as @mode', array('@mode' => isset($view_modes[$view_mode]['label']) ? $view_modes[$view_mode]['label'] : $view_mode)); $summary[] = $this->getSetting('links') ? t('Display links') : t('Do not display links'); @@ -83,7 +83,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $view_mode = $this->getSetting('view_mode'); $links = $this->getSetting('links'); - $target_type = $this->field['settings']['target_type']; + $target_type = $this->field->settings['target_type']; $elements = array(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php index 76fc029..05b4ba0 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php @@ -40,7 +40,7 @@ public function prepareView(array $entities, $langcode, array &$items) { } } - $target_type = $this->field['settings']['target_type']; + $target_type = $this->field->settings['target_type']; $target_entities = array(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php index 2887af6..b5212de 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php @@ -40,7 +40,7 @@ public function elementValidate($element, &$form_state, $form) { $value = array(); // If a value was entered into the autocomplete. $handler = entity_reference_get_selection_handler($this->field, $this->instance); - $bundles = entity_get_bundles($this->field['settings']['target_type']); + $bundles = entity_get_bundles($this->field->settings['target_type']); $auto_create = isset($this->instance['settings']['handler_settings']['auto_create']) ? $this->instance['settings']['handler_settings']['auto_create'] : FALSE; if (!empty($element['#value'])) { diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php index fe30b11..56caad4 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php @@ -59,7 +59,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr // Prepare the autocomplete path. $autocomplete_path = $this->getSetting('autocomplete_path'); - $autocomplete_path .= '/' . $field['field_name'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/'; + $autocomplete_path .= '/' . $field->field_name . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/'; // Use as a placeholder in the URL when we don't have an entity. // Most web servers collapse two consecutive slashes. @@ -107,7 +107,7 @@ protected function getLabels(array $items) { } // Load those entities and loop through them to extract their labels. - $entities = entity_load_multiple($this->field['settings']['target_type'], $entity_ids); + $entities = entity_load_multiple($this->field->settings['target_type'], $entity_ids); foreach ($entities as $entity_id => $entity_item) { $label = $entity_item->label(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index cf1c619..053961f 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -58,7 +58,7 @@ protected function assertReferencable($field, $instance, $tests, $handler_name) */ public function testNodeHandler() { // Build a fake field instance. - $field = array( + $field = entity_create('field_entity', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -67,7 +67,7 @@ public function testNodeHandler() { 'field_name' => 'test_field', 'type' => 'entity_reference', 'cardinality' => '1', - ); + )); $instance = array( 'settings' => array( 'handler' => 'default', @@ -196,7 +196,7 @@ public function testNodeHandler() { */ public function testUserHandler() { // Build a fake field instance. - $field = array( + $field = entity_create('field_entity', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -205,7 +205,7 @@ public function testUserHandler() { 'field_name' => 'test_field', 'type' => 'entity_reference', 'cardinality' => '1', - ); + )); $instance = array( 'settings' => array( 'handler' => 'default', @@ -336,7 +336,7 @@ public function testUserHandler() { */ public function testCommentHandler() { // Build a fake field instance. - $field = array( + $field = entity_create('field_entity', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -345,7 +345,7 @@ public function testCommentHandler() { 'field_name' => 'test_field', 'type' => 'entity_reference', 'cardinality' => '1', - ); + )); $instance = array( 'settings' => array( 'handler' => 'default', diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php index cc768e2..c29cbf8 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionSortTest.php @@ -55,7 +55,7 @@ public function testSort() { // Build a fake field instance. - $field = array( + $field = entity_create('field_entity', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -64,7 +64,7 @@ public function testSort() { 'field_name' => 'test_field', 'type' => 'entity_reference', 'cardinality' => 1, - ); + )); $instance = array( 'settings' => array( diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php index f11f5a4..136c69b 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/Views/SelectionTest.php @@ -40,7 +40,7 @@ public function testSelectionHandler() { } // Build a fake field instance. - $field = array( + $field = entity_create('field_entity', array( 'translatable' => FALSE, 'entity_types' => array(), 'settings' => array( @@ -49,7 +49,7 @@ public function testSelectionHandler() { 'field_name' => 'test_field', 'type' => 'entity_reference', 'cardinality' => '1', - ); + )); $instance = array( 'settings' => array( 'handler' => 'views', diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 29112ef..9ab5cfc 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -230,7 +230,7 @@ function hook_field_info_alter(&$info) { * - foreign keys: (optional) An array of Schema API foreign key definitions. */ function hook_field_schema($field) { - if ($field['type'] == 'text_long') { + if ($field->type == 'text_long') { $columns = array( 'value' => array( 'type' => 'text', @@ -243,7 +243,7 @@ function hook_field_schema($field) { $columns = array( 'value' => array( 'type' => 'varchar', - 'length' => $field['settings']['max_length'], + 'length' => $field->settings['max_length'], 'not null' => FALSE, ), ); @@ -313,7 +313,7 @@ function hook_field_load($entity_type, $entities, $field, $instances, $langcode, // by formatters if needed. if (empty($instances[$id]['settings']['text_processing']) || filter_format_allowcache($item['format'])) { $items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : ''; - if ($field['type'] == 'text_with_summary') { + if ($field->type == 'text_with_summary') { $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : ''; } } @@ -348,14 +348,14 @@ function hook_field_load($entity_type, $entities, $field, $instances, $langcode, * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}, or an empty array if unset. + * $entity->{$field->field_name}, or an empty array if unset. */ function hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { // Sample code from image.module: if there are no images specified at all, // use the default image. foreach ($entities as $id => $entity) { - if (empty($items[$id]) && $field['settings']['default_image']) { - if ($file = file_load($field['settings']['default_image'])) { + if (empty($items[$id]) && $field->settings['default_image']) { + if ($file = file_load($field->settings['default_image'])) { $items[$id][0] = (array) $file + array( 'is_default' => TRUE, 'alt' => '', @@ -381,7 +381,7 @@ function hook_field_prepare_view($entity_type, $entities, $field, $instances, $l * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * @param $errors * The array of errors (keyed by field name, language code, and delta) that * have already been reported for the entity. The function should add its @@ -393,10 +393,10 @@ function hook_field_prepare_view($entity_type, $entities, $field, $instances, $l function hook_field_validate(\Drupal\Core\Entity\EntityInterface $entity = NULL, $field, $instance, $langcode, $items, &$errors) { foreach ($items as $delta => $item) { if (!empty($item['value'])) { - if (!empty($field['settings']['max_length']) && drupal_strlen($item['value']) > $field['settings']['max_length']) { - $errors[$field['field_name']][$langcode][$delta][] = array( + if (!empty($field->settings['max_length']) && drupal_strlen($item['value']) > $field->settings['max_length']) { + $errors[$field->field_name][$langcode][$delta][] = array( 'error' => 'text_max_length', - 'message' => t('%name: the value may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])), + 'message' => t('%name: the value may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field->settings['max_length'])), ); } } @@ -418,15 +418,15 @@ function hook_field_validate(\Drupal\Core\Entity\EntityInterface $entity = NULL, * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. */ function hook_field_presave(\Drupal\Core\Entity\EntityInterface $entity, $field, $instance, $langcode, &$items) { - if ($field['type'] == 'number_decimal') { + if ($field->type == 'number_decimal') { // Let PHP round the value to ensure consistent behavior across storage // backends. foreach ($items as $delta => $item) { if (isset($item['value'])) { - $items[$delta]['value'] = round($item['value'], $field['settings']['scale']); + $items[$delta]['value'] = round($item['value'], $field->settings['scale']); } } } @@ -451,7 +451,7 @@ function hook_field_presave(\Drupal\Core\Entity\EntityInterface $entity, $field, * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * * @see hook_field_update() * @see hook_field_delete() @@ -490,7 +490,7 @@ function hook_field_insert(\Drupal\Core\Entity\EntityInterface $entity, $field, * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * * @see hook_field_insert() * @see hook_field_delete() @@ -577,7 +577,7 @@ function hook_field_storage_update_field($field, $prior_field, $has_data) { * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * * @see hook_field_insert() * @see hook_field_update() @@ -605,7 +605,7 @@ function hook_field_delete(\Drupal\Core\Entity\EntityInterface $entity, $field, * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. */ function hook_field_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, $field, $instance, $langcode, &$items) { foreach ($items as $delta => $item) { @@ -626,7 +626,7 @@ function hook_field_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * @param $source_entity * The source entity from which field values are being copied. * @param $source_langcode @@ -635,7 +635,7 @@ function hook_field_delete_revision(\Drupal\Core\Entity\EntityInterface $entity, function hook_field_prepare_translation(\Drupal\Core\Entity\EntityInterface $entity, $field, $instance, $langcode, &$items, $source_entity, $source_langcode) { // If the translating user is not permitted to use the assigned text format, // we must not expose the source values. - $field_name = $field['field_name']; + $field_name = $field->field_name; $formats = filter_formats(); $format_id = $source_entity->{$field_name}[$source_langcode][0]['format']; if (!filter_access($formats[$format_id])) { @@ -802,7 +802,7 @@ function hook_field_widget_WIDGET_TYPE_form_alter(&$element, &$form_state, $cont function hook_field_widget_properties_alter(array &$widget_properties, array $context) { // Change a widget's type according to the time of day. $field = $context['field']; - if ($context['entity_type'] == 'node' && $field['field_name'] == 'field_foo') { + if ($context['entity_type'] == 'node' && $field->field_name == 'field_foo') { $time = date('H'); $widget_properties['type'] = $time < 12 ? 'widget_am' : 'widget_pm'; } @@ -1296,8 +1296,8 @@ function hook_field_storage_details($field) { $details = array(); // Add field columns. - foreach ((array) $field['columns'] as $column_name => $attributes) { - $real_name = _field_sql_storage_columnname($field['field_name'], $column_name); + foreach ((array) $field->columns as $column_name => $attributes) { + $real_name = _field_sql_storage_columnname($field->field_name, $column_name); $columns[$column_name] = $real_name; } return array( @@ -1324,9 +1324,9 @@ function hook_field_storage_details($field) { * @see hook_field_storage_details() */ function hook_field_storage_details_alter(&$details, $field) { - if ($field['field_name'] == 'field_of_interest') { + if ($field->field_name == 'field_of_interest') { $columns = array(); - foreach ((array) $field['columns'] as $column_name => $attributes) { + foreach ((array) $field->columns as $column_name => $attributes) { $columns[$column_name] = $column_name; } $details['drupal_variables'] = array( @@ -1375,7 +1375,7 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option foreach ($fields as $field_id => $ids) { $field = field_info_field_by_id($field_id); - $field_name = $field['field_name']; + $field_name = $field->field_name; $table = $load_current ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field); $query = db_select($table, 't') @@ -1397,11 +1397,11 @@ function hook_field_storage_load($entity_type, $entities, $age, $fields, $option $delta_count[$row->entity_id][$row->langcode] = 0; } - if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field['cardinality']) { + if ($field->cardinality == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->cardinality) { $item = array(); // For each column declared by the field, populate the item // from the prefixed database column. - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $column_name = _field_sql_storage_columnname($field_name, $column); $item[$column] = $row->$column_name; } @@ -1439,7 +1439,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $ foreach ($fields as $field_id) { $field = field_info_field_by_id($field_id); - $field_name = $field['field_name']; + $field_name = $field->field_name; $table_name = _field_sql_storage_tablename($field); $revision_name = _field_sql_storage_revision_tablename($field); @@ -1469,7 +1469,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $ // Prepare the multi-insert query. $do_insert = FALSE; $columns = array('entity_type', 'entity_id', 'revision_id', 'bundle', 'delta', 'langcode'); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $columns[] = _field_sql_storage_columnname($field_name, $column); } $query = db_insert($table_name)->fields($columns); @@ -1489,7 +1489,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $ 'delta' => $delta, 'langcode' => $langcode, ); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL; } $query->values($record); @@ -1497,7 +1497,7 @@ function hook_field_storage_write(\Drupal\Core\Entity\EntityInterface $entity, $ $revision_query->values($record); } - if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) { + if ($field->cardinality != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field->cardinality) { break; } } @@ -1603,7 +1603,7 @@ function hook_field_storage_query($query) { $select_query->fields($table_alias, array('entity_type', 'entity_id', 'revision_id', 'bundle')); $field_base_table = $table_alias; } - if ($field['cardinality'] != 1) { + if ($field->cardinality != 1) { $select_query->distinct(); } } @@ -1613,7 +1613,7 @@ function hook_field_storage_query($query) { $table_alias = $table_aliases[$key]; $field = $condition['field']; // Add the specified condition. - $sql_field = "$table_alias." . _field_sql_storage_columnname($field['field_name'], $condition['column']); + $sql_field = "$table_alias." . _field_sql_storage_columnname($field->field_name, $condition['column']); $query->addCondition($select_query, $sql_field, $condition); // Add delta / language group conditions. foreach (array('delta', 'langcode') as $column) { @@ -1666,7 +1666,7 @@ function hook_field_storage_query($query) { $specifier = $order['specifier']; $field = $specifier['field']; $table_alias = $table_aliases[$specifier['index']]; - $sql_field = "$table_alias." . _field_sql_storage_columnname($field['field_name'], $specifier['column']); + $sql_field = "$table_alias." . _field_sql_storage_columnname($field->field_name, $specifier['column']); $select_query->orderBy($sql_field, $order['direction']); } elseif ($order['type'] == 'property') { @@ -1706,7 +1706,7 @@ function hook_field_storage_create_field($field) { */ function hook_field_storage_delete_field($field) { // Mark all data associated with the field for deletion. - $field['deleted'] = 0; + $field->deleted = 0; $table = _field_sql_storage_tablename($field); $revision_table = _field_sql_storage_revision_tablename($field); db_update($table) @@ -1714,7 +1714,7 @@ function hook_field_storage_delete_field($field) { ->execute(); // Move the table to a unique name while the table contents are being deleted. - $field['deleted'] = 1; + $field->deleted = 1; $new_table = _field_sql_storage_tablename($field); $revision_new_table = _field_sql_storage_revision_tablename($field); db_rename_table($table, $new_table); @@ -1921,7 +1921,7 @@ function hook_field_info_max_weight($entity_type, $bundle, $context) { function hook_field_widget_properties_ENTITY_TYPE_alter(array &$widget_properties, array $context) { // Change a widget's type according to the time of day. $field = $context['field']; - if ($field['field_name'] == 'field_foo') { + if ($field->field_name == 'field_foo') { $time = date('H'); $widget_properties['type'] = $time < 12 ? 'widget_am' : 'widget_pm'; } @@ -1987,13 +1987,13 @@ function hook_field_update_forbid($field, $prior_field, $has_data) { // the new field will have fewer values, and any data exists for the // abandoned keys, the field will have no way to display them. So, // forbid such an update. - if ($has_data && count($field['settings']['allowed_values']) < count($prior_field['settings']['allowed_values'])) { + if ($has_data && count($field->settings['allowed_values']) < count($prior_field->settings['allowed_values'])) { // Identify the keys that will be lost. - $lost_keys = array_diff(array_keys($field['settings']['allowed_values']), array_keys($prior_field['settings']['allowed_values'])); + $lost_keys = array_diff(array_keys($field->settings['allowed_values']), array_keys($prior_field->settings['allowed_values'])); // If any data exist for those keys, forbid the update. $query = new EntityFieldQuery(); $found = $query - ->fieldCondition($prior_field['field_name'], 'value', $lost_keys) + ->fieldCondition($prior_field->field_name, 'value', $lost_keys) ->range(0, 1) ->execute(); if ($found) { @@ -2097,7 +2097,7 @@ function hook_field_read_instance($instance) { */ function hook_field_purge_field($field) { db_delete('my_module_field_info') - ->condition('id', $field['id']) + ->condition('id', $field->field_name) ->execute(); } @@ -2201,7 +2201,7 @@ function hook_field_storage_purge(\Drupal\Core\Entity\EntityInterface $entity, $ * TRUE if the operation is allowed, and FALSE if the operation is denied. */ function hook_field_access($op, $field, $entity_type, $entity, $account) { - if ($field['field_name'] == 'field_of_interest' && $op == 'edit') { + if ($field->field_name == 'field_of_interest' && $op == 'edit') { return user_access('edit field of interest', $account); } return TRUE; diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index 69102f4..b2c3d79 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -170,7 +170,7 @@ function field_invoke_method($method, $target_function, EntityInterface $entity, if (method_exists($target, $method)) { $field = field_info_field_by_id($instance['field_id']); - $field_name = $field['field_name']; + $field_name = $field->field_name; // Determine the list of languages to iterate on. $available_langcodes = field_available_languages($entity_type, $field); @@ -400,8 +400,8 @@ function _field_invoke($op, EntityInterface $entity, &$a = NULL, &$b = NULL, $op // field_info_field() is not available for deleted fields, so use // field_info_field_by_id(). $field = field_info_field_by_id($instance['field_id']); - $field_name = $field['field_name']; - $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op; + $field_name = $field->field_name; + $function = $options['default'] ? 'field_default_' . $op : $field->module . '_field_' . $op; if (function_exists($function)) { // Determine the list of languages to iterate on. $available_langcodes = field_available_languages($entity->entityType(), $field); @@ -510,7 +510,7 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b = $field_id = $instance['field_id']; $field_name = $instance['field_name']; $field = field_info_field_by_id($field_id); - $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op; + $function = $options['default'] ? 'field_default_' . $op : $field->module . '_field_' . $op; if (function_exists($function)) { // Add the field to the list of fields to invoke the hook on. if (!isset($fields[$field_id])) { @@ -538,8 +538,8 @@ function _field_invoke_multiple($op, $entity_type, $entities, &$a = NULL, &$b = // For each field, invoke the field hook and collect results. foreach ($fields as $field_id => $field) { - $field_name = $field['field_name']; - $function = $options['default'] ? 'field_default_' . $op : $field['module'] . '_field_' . $op; + $field_name = $field->field_name; + $function = $options['default'] ? 'field_default_' . $op : $field->module . '_field_' . $op; // Iterate over all the field translations. foreach ($grouped_items[$field_id] as $langcode => &$items) { $entities = $grouped_entities[$field_id][$langcode]; @@ -786,7 +786,7 @@ function _field_invoke_widget_target() { * // Only for multiple widgets: * '#entity_type' => The name of the entity type, * '#bundle' => $instance['bundle'], - * '#columns' => array_keys($field['columns']), + * '#columns' => array_keys($field->columns), * // The remaining elements in the sub-array depend on the widget. * '#type' => The type of the widget, * ... @@ -951,7 +951,7 @@ function field_attach_load($entity_type, $entities, $age = FIELD_LOAD_CURRENT, $ // Collect the storage backend if the field has not been loaded yet. if (!isset($skip_fields[$field_id])) { $field = field_info_field_by_id($field_id); - $storages[$field['storage']['type']][$field_id][] = $load_current ? $id : $vid; + $storages[$field->storage['type']][$field_id][] = $load_current ? $id : $vid; } } } @@ -1170,12 +1170,12 @@ function field_attach_insert(EntityInterface $entity) { $storages = array(); foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field = field_info_field_by_id($instance['field_id']); - $field_id = $field['id']; - $field_name = $field['field_name']; + $field_id = $field->id(); + $field_name = $field->field_name; if (!empty($entity->$field_name)) { // Collect the storage backend if the field has not been written yet. if (!isset($skip_fields[$field_id])) { - $storages[$field['storage']['type']][$field_id] = $field_id; + $storages[$field->storage['type']][$field_id] = $field_id; } } } @@ -1211,8 +1211,8 @@ function field_attach_update(EntityInterface $entity) { $storages = array(); foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field = field_info_field_by_id($instance['field_id']); - $field_id = $field['id']; - $field_name = $field['field_name']; + $field_id = $field->id(); + $field_name = $field->field_name; // Leave the field untouched if $entity comes with no $field_name property, // but empty the field if it comes as a NULL value or an empty array. // Function property_exists() is slower, so we catch the more frequent @@ -1220,7 +1220,7 @@ function field_attach_update(EntityInterface $entity) { if (isset($entity->$field_name) || property_exists($entity, $field_name)) { // Collect the storage backend if the field has not been written yet. if (!isset($skip_fields[$field_id])) { - $storages[$field['storage']['type']][$field_id] = $field_id; + $storages[$field->storage['type']][$field_id] = $field_id; } } } @@ -1254,8 +1254,8 @@ function field_attach_delete(EntityInterface $entity) { $storages = array(); foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field = field_info_field_by_id($instance['field_id']); - $field_id = $field['id']; - $storages[$field['storage']['type']][$field_id] = $field_id; + $field_id = $field->id(); + $storages[$field->storage['type']][$field_id] = $field_id; } // Field storage backends delete their data. @@ -1287,8 +1287,8 @@ function field_attach_delete_revision(EntityInterface $entity) { $storages = array(); foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field = field_info_field_by_id($instance['field_id']); - $field_id = $field['id']; - $storages[$field['storage']['type']][$field_id] = $field_id; + $field_id = $field->id(); + $storages[$field->storage['type']][$field_id] = $field_id; } // Field storage backends delete their data. @@ -1549,11 +1549,18 @@ function field_attach_create_bundle($entity_type, $bundle) { * The new name of the bundle. */ function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { - db_update('field_config_instance') - ->fields(array('bundle' => $bundle_new)) - ->condition('entity_type', $entity_type) - ->condition('bundle', $bundle_old) - ->execute(); + $instances = field_read_instances(); + foreach ($instances as $id => $instance) { + if ($instance['entity_type'] == $entity_type && $instance['bundle'] == $bundle_old) { + $new_instance_id = $instance['entity_type'] . '.' . $bundle_new . '.' . $instance['field_name']; + config('field.instance.' . $instance['entity_type'] . '.' . $bundle_old . '.' . $instance['field_name'])->rename('field.instance.' . $new_instance_id); + config('field.instance.' . $instance['entity_type'] . '.' . $bundle_new . '.' . $instance['field_name']) + ->set('data.bundle', $bundle_new) + ->set('id', $new_instance_id) + ->set('label', $new_instance_id) + ->save(); + } + } // Clear the cache. field_cache_clear(); @@ -1569,7 +1576,7 @@ function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { } /** - * Notifies field.module the a bundle was deleted. + * Notifies field.module that a bundle was deleted. * * This deletes the data for the field instances as well as the field instances * themselves. This function actually just marks the data and field instances as @@ -1582,14 +1589,18 @@ function field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) { * The entity type to which the bundle is bound. * @param $bundle * The bundle to delete. + * @param $field_cleanup + * If TRUE, the field will be deleted as well if its last instance is being + * deleted. If FALSE, it is the caller's responsibility to handle the case of + * fields left without instances. Defaults to TRUE. */ -function field_attach_delete_bundle($entity_type, $bundle) { +function field_attach_delete_bundle($entity_type, $bundle, $field_cleanup = TRUE) { // First, delete the instances themselves. field_read_instances() must be // used here since field_info_instances() does not return instances for // disabled entity types or bundles. $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle), array('include_inactive' => 1)); foreach ($instances as $instance) { - field_delete_instance($instance); + field_delete_instance($instance, $field_cleanup); } // Clear the cache. diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index f6ee8a2..02b05f2 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\field\FieldException; +use Drupal\Field\FieldInstance; /** * @defgroup field_crud Field CRUD API @@ -29,7 +30,7 @@ * field_create_instance() for that. * * @param $field - * A field definition array. The field_name and type properties are required. + * A field definition. The field_name and type properties are required. * Other properties, if omitted, will be given the following default values: * - cardinality: 1 * - locked: FALSE @@ -49,41 +50,48 @@ * hook_field_storage_info(). * * @return - * The $field array with the id property filled in. + * The $field entity. * * @throws Drupal\field\FieldException * * See: @link field Field API data structures @endlink. */ function field_create_field($field) { + + // Module developers can still pass in an array of properties + // into field_create_field(). + if (is_array($field)) { + $field = entity_create('field_entity', $field); + } + // Field name is required. - if (empty($field['field_name'])) { + if (empty($field->field_name)) { throw new FieldException('Attempt to create an unnamed field.'); } // Field type is required. - if (empty($field['type'])) { + if (empty($field->type)) { throw new FieldException('Attempt to create a field with no type.'); } // Field name cannot contain invalid characters. - if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $field['field_name'])) { + if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $field->field_name)) { throw new FieldException('Attempt to create a field with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character'); } // Field name cannot be longer than 32 characters. We use drupal_strlen() // because the DB layer assumes that column widths are given in characters, // not bytes. - if (drupal_strlen($field['field_name']) > 32) { + if (drupal_strlen($field->field_name) > 32) { throw new FieldException(t('Attempt to create a field with a name longer than 32 characters: %name', - array('%name' => $field['field_name']))); + array('%name' => $field->field_name))); } // Ensure the field name is unique over active and disabled fields. // We do not care about deleted fields. - $prior_field = field_read_field($field['field_name'], array('include_inactive' => TRUE)); + $prior_field = field_read_field($field->field_name, array('include_inactive' => TRUE)); if (!empty($prior_field)) { - $message = $prior_field['active']? - t('Attempt to create field name %name which already exists and is active.', array('%name' => $field['field_name'])): - t('Attempt to create field name %name which already exists, although it is inactive.', array('%name' => $field['field_name'])); + $message = $prior_field->active ? + t('Attempt to create field name %name which already exists and is active.', array('%name' => $field->field_name)): + t('Attempt to create field name %name which already exists, although it is inactive.', array('%name' => $field->field_name)); throw new FieldException($message); } @@ -91,110 +99,97 @@ function field_create_field($field) { // collisions with existing entity properties, but some is better // than none. foreach (entity_get_info() as $type => $info) { - if (in_array($field['field_name'], $info['entity_keys'])) { - throw new FieldException(t('Attempt to create field name %name which is reserved by entity type %type.', array('%name' => $field['field_name'], '%type' => $type))); + if (in_array($field->field_name, $info['entity_keys'])) { + throw new FieldException(t('Attempt to create field name %name which is reserved by entity type %type.', array('%name' => $field->field_name, '%type' => $type))); } } - $field += array( + $defaults = array( 'entity_types' => array(), 'cardinality' => 1, 'translatable' => FALSE, - 'locked' => FALSE, 'settings' => array(), - 'storage' => array(), + 'bundles' => array(), + 'entity_types' => array(), + 'locked' => FALSE, 'deleted' => 0, + 'storage' => array(), + 'indexes' => array(), + 'foreign_keys' => array(), ); + foreach ($defaults as $key => $value) { + if (!isset($field->{$key})) { + $field->{$key} = $value; + } + } + // Check that the field type is known. - $field_type = field_info_field_types($field['type']); + $field_type = field_info_field_types($field->type); if (!$field_type) { - throw new FieldException(t('Attempt to create a field of unknown type %type.', array('%type' => $field['type']))); + throw new FieldException(t('Attempt to create a field of unknown type %type.', array('%type' => $field->type))); } // Create all per-field-type properties (needed here as long as we have // settings that impact column definitions). - $field['settings'] += field_info_field_settings($field['type']); - $field['module'] = $field_type['module']; - $field['active'] = 1; + $field->settings += field_info_field_settings($field->type); + $field->module = $field_type['module']; + $field->active = 1; // Provide default storage. - $field['storage'] += array( + $field->storage += array( 'type' => variable_get('field_storage_default', 'field_sql_storage'), 'settings' => array(), ); // Check that the storage type is known. - $storage_type = field_info_storage_types($field['storage']['type']); + $storage_type = field_info_storage_types($field->storage['type']); if (!$storage_type) { - throw new FieldException(t('Attempt to create a field with unknown storage type %type.', array('%type' => $field['storage']['type']))); + throw new FieldException(t('Attempt to create a field with unknown storage type %type.', array('%type' => $field->storage['type']))); } // Provide default storage settings. - $field['storage']['settings'] += field_info_storage_settings($field['storage']['type']); - $field['storage']['module'] = $storage_type['module']; - $field['storage']['active'] = 1; + $field->storage['settings'] += field_info_storage_settings($field->storage['type']); + $field->storage['module'] = $storage_type['module']; + $field->storage['active'] = 1; + $field->storage_type = $field->storage['type']; + $field->storage_module = $storage_type['module']; + $field->storage_active = 1; // Collect storage information. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); + module_load_install($field->module); + $schema = (array) module_invoke($field->module, 'field_schema', $field); $schema += array('columns' => array(), 'indexes' => array(), 'foreign keys' => array()); // 'columns' are hardcoded in the field type. - $field['columns'] = $schema['columns']; - if (array_intersect(array_keys($field['columns']), field_reserved_columns())) { + $field->columns = $schema['columns']; + if (array_intersect(array_keys($field->columns), field_reserved_columns())) { throw new FieldException(t('Illegal field type columns.')); } // 'foreign keys' are hardcoded in the field type. - $field['foreign keys'] = $schema['foreign keys']; + $field->foreign_keys = $schema['foreign keys']; // 'indexes' can be both hardcoded in the field type, and specified in the // incoming $field definition. - $field += array( - 'indexes' => array(), - ); - $field['indexes'] += $schema['indexes']; + $field->indexes += $schema['indexes']; - // The serialized 'data' column contains everything from $field that does not - // have its own column and is not automatically populated when the field is - // read. - $data = $field; - unset($data['columns'], $data['field_name'], $data['type'], $data['active'], $data['module'], $data['storage_type'], $data['storage_active'], $data['storage_module'], $data['locked'], $data['cardinality'], $data['deleted']); // Additionally, do not save the 'bundles' property populated by // field_info_field(). - unset($data['bundles']); - - $record = array( - 'field_name' => $field['field_name'], - 'type' => $field['type'], - 'module' => $field['module'], - 'active' => $field['active'], - 'storage_type' => $field['storage']['type'], - 'storage_module' => $field['storage']['module'], - 'storage_active' => $field['storage']['active'], - 'locked' => $field['locked'], - 'data' => $data, - 'cardinality' => $field['cardinality'], - 'translatable' => $field['translatable'], - 'deleted' => $field['deleted'], - ); + $field->bundles = array(); - // Store the field and get the id back. - drupal_write_record('field_config', $record); - $field['id'] = $record['id']; + // Save the configuration. + $field->id = $field->field_name; + $field->save(); // Invoke hook_field_storage_create_field after the field is // complete (e.g. it has its id). try { - // Invoke hook_field_storage_create_field after - // drupal_write_record() sets the field id. + // Invoke hook_field_storage_create_field. module_invoke($storage_type['module'], 'field_storage_create_field', $field); } catch (Exception $e) { // If storage creation failed, remove the field_config record before // rethrowing the exception. - db_delete('field_config') - ->condition('id', $field['id']) - ->execute(); + entity_delete_multiple('field_entity', array($field->field_name)); throw $e; } // Clear caches - field_cache_clear(TRUE); + field_cache_clear(); // Invoke external hooks after the cache is cleared for API consistency. module_invoke_all('field_create_field', $field); @@ -213,7 +208,7 @@ function field_create_field($field) { * that cannot be updated. * * @param $field - * A field structure. $field['field_name'] must provided; it + * A field structure. $field->field_name must provided; it * identifies the field that will be updated to match this * structure. Any other properties of the field that are not * specified in $field will be left unchanged, so it is not @@ -224,41 +219,66 @@ function field_create_field($field) { * @see field_create_field() */ function field_update_field($field) { + + // Module developers can still pass in an array of properties + // into field_update_field(). + if (is_array($field)) { + $field_loaded = entity_load('field_entity', $field['field_name']); + if (empty($field_loaded)) { + throw new FieldException('Attempt to update a non-existent field.'); + } + // Override settings + // @todo should we make updating a field completely different ? + foreach ($field as $key => $value) { + if (is_array($value)) { + if ($key == 'indexes') { + $field_loaded->{$key} = $value; + } + else { + $field_loaded->{$key} += $value; + } + } + else { + $field_loaded->{$key} = $value; + } + } + $field = $field_loaded; + } + // Check that the specified field exists. - $prior_field = field_read_field($field['field_name']); + $prior_field = field_read_field($field->field_name); if (empty($prior_field)) { throw new FieldException('Attempt to update a non-existent field.'); } // Use the prior field values for anything not specifically set by the new - // field to be sure that all values are set. - $field += $prior_field; - $field['settings'] += $prior_field['settings']; + // field to be sure that all values are set. // @todo remove ? + $field->settings += $prior_field->settings; // Some updates are always disallowed. - if ($field['type'] != $prior_field['type']) { + if ($field->type != $prior_field->type) { throw new FieldException("Cannot change an existing field's type."); } - if ($field['entity_types'] != $prior_field['entity_types']) { + if ($field->entity_types != $prior_field->entity_types) { throw new FieldException("Cannot change an existing field's entity_types property."); } - if ($field['storage']['type'] != $prior_field['storage']['type']) { + if ($field->storage['type'] != $prior_field->storage['type']) { throw new FieldException("Cannot change an existing field's storage type."); } // Collect the new storage information, since what is in // $prior_field may no longer be right. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); + module_load_install($field->module); + $schema = (array) module_invoke($field->module, 'field_schema', $field); $schema += array('columns' => array(), 'indexes' => array()); // 'columns' are hardcoded in the field type. - $field['columns'] = $schema['columns']; + $field->columns = $schema['columns']; // 'indexes' can be both hardcoded in the field type, and specified in the // incoming $field definition. - $field += array( - 'indexes' => array(), - ); - $field['indexes'] += $schema['indexes']; + if (!isset($field->indexes)) { + $field->indexes = array(); + } + $field->indexes += $schema['indexes']; $has_data = field_has_data($field); @@ -270,29 +290,21 @@ function field_update_field($field) { // Tell the storage engine to update the field. Do this before // saving the new definition since it still might fail. - $storage_type = field_info_storage_types($field['storage']['type']); + $storage_type = field_info_storage_types($field->storage['type']); module_invoke($storage_type['module'], 'field_storage_update_field', $field, $prior_field, $has_data); // Save the new field definition. @todo: refactor with // field_create_field. - // The serialized 'data' column contains everything from $field that does not - // have its own column and is not automatically populated when the field is - // read. - $data = $field; - unset($data['columns'], $data['field_name'], $data['type'], $data['locked'], $data['module'], $data['cardinality'], $data['active'], $data['deleted']); // Additionally, do not save the 'bundles' property populated by // field_info_field(). - unset($data['bundles']); + $field->bundles = array(); - $field['data'] = $data; - - // Store the field and create the id. - $primary_key = array('id'); - drupal_write_record('field_config', $field, $primary_key); + // Save the configuration. + $field->save(); // Clear caches - field_cache_clear(TRUE); + field_cache_clear(); // Invoke external hooks after the cache is cleared for API consistency. module_invoke_all('field_update_field', $field, $prior_field, $has_data); @@ -342,64 +354,49 @@ function field_read_field($field_name, $include_additional = array()) { * field ID, otherwise it is keyed by field name. */ function field_read_fields($params = array(), $include_additional = array()) { - $query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC)); - $query->fields('fc'); - - // Turn the conditions into a query. - foreach ($params as $key => $value) { - // Allow filtering on the 'entity_type' and 'bundle' columns of the - // field_config_instance table. - if ($key == 'entity_type' || $key == 'bundle') { - if (empty($fci_join)) { - $fci_join = $query->join('field_config_instance', 'fci', 'fc.id = fci.field_id'); - } - $key = 'fci.' . $key; - } - else { - $key = 'fc.' . $key; - } + $fields = array(); - $query->condition($key, $value); + // Check if we need to retrieve deleted fields. + $include_deleted = (isset($include_additional['include_deleted']) && $include_additional['include_deleted']) || (isset($params['deleted']) && $params['deleted']); + if ($include_deleted) { + $deleted_fields = state()->get('field.field.deleted') ?: array(); } + // Add active and storage active parameters. if (!isset($include_additional['include_inactive']) || !$include_additional['include_inactive']) { - $query - ->condition('fc.active', 1) - ->condition('fc.storage_active', 1); + $params['active'] = 1; + $params['storage_active'] = 1; } - $include_deleted = (isset($include_additional['include_deleted']) && $include_additional['include_deleted']); - if (!$include_deleted) { - $query->condition('fc.deleted', 0); + + // Get configuration fields. + $config_fields = entity_load_multiple('field_entity'); + + // Merge deleted fields. + if (!empty($deleted_fields)) { + $config_fields += $deleted_fields; } - $fields = array(); - $results = $query->execute(); - foreach ($results as $record) { - $field = unserialize($record['data']); - $field['id'] = $record['id']; - $field['field_name'] = $record['field_name']; - $field['type'] = $record['type']; - $field['module'] = $record['module']; - $field['active'] = $record['active']; - $field['storage']['type'] = $record['storage_type']; - $field['storage']['module'] = $record['storage_module']; - $field['storage']['active'] = $record['storage_active']; - $field['locked'] = $record['locked']; - $field['cardinality'] = $record['cardinality']; - $field['translatable'] = $record['translatable']; - $field['deleted'] = $record['deleted']; + foreach ($config_fields as $field) { + // Conditions. + foreach ($params as $key => $value) { + if ($field->{$key} != $value) { + continue 2; + } + } + + // Invoke read field. module_invoke_all('field_read_field', $field); // Populate storage information. - module_load_install($field['module']); - $schema = (array) module_invoke($field['module'], 'field_schema', $field); + module_load_install($field->module); + $schema = (array) module_invoke($field->module, 'field_schema', $field); $schema += array('columns' => array(), 'indexes' => array()); - $field['columns'] = $schema['columns']; + $field->columns = $schema['columns']; - $field_name = $field['field_name']; + $field_name = $field->field_name; if ($include_deleted) { - $field_name = $field['id']; + $field_name = $field->id(); } $fields[$field_name] = $field; } @@ -415,26 +412,30 @@ function field_read_fields($params = array(), $include_additional = array()) { function field_delete_field($field_name) { // Delete all non-deleted instances. $field = field_info_field($field_name); - if (isset($field['bundles'])) { - foreach ($field['bundles'] as $entity_type => $bundles) { + + if (isset($field->bundles)) { + foreach ($field->bundles as $entity_type => $bundles) { foreach ($bundles as $bundle) { $instance = field_info_instance($entity_type, $field_name, $bundle); - field_delete_instance($instance, FALSE); + field_delete_instance($instance->getArray(), FALSE); } } } // Mark field data for deletion. - module_invoke($field['storage']['module'], 'field_storage_delete_field', $field); + module_invoke($field->storage['module'], 'field_storage_delete_field', $field); - // Mark the field for deletion. - db_update('field_config') - ->fields(array('deleted' => 1)) - ->condition('field_name', $field_name) - ->execute(); + // Delete the configuration of this field and save the field configuration + // in the key_value table so we can use it later during field_purge_batch(). + // This makes sure a new field can be created immediately with the same name. + $deleted_fields = state()->get('field.field.deleted') ?: array(); + $field->deleted = TRUE; + $deleted_fields[$field->id()] = $field; + state()->set('field.field.deleted', $deleted_fields); + entity_delete_multiple('field_entity', array($field->field_name)); // Clear the cache. - field_cache_clear(TRUE); + field_cache_clear(); module_invoke_all('field_delete_field', $field); } @@ -487,12 +488,15 @@ function field_create_instance(&$instance) { throw new FieldException(t('Attempt to create an instance of field @field_name without a bundle.', array('@field_name' => $instance['field_name']))); } // Check that the field can be attached to this entity type. - if (!empty($field['entity_types']) && !in_array($instance['entity_type'], $field['entity_types'])) { + if (!empty($field->entity_types) && !in_array($instance['entity_type'], $field->entity_types)) { throw new FieldException(t('Attempt to create an instance of field @field_name on forbidden entity type @entity_type.', array('@field_name' => $instance['field_name'], '@entity_type' => $instance['entity_type']))); } // Set the field id. - $instance['field_id'] = $field['id']; + $instance['field_id'] = $field->id(); + + // Generate id for the instance. + $instance['id'] = field_generate_id(); // Note that we do *not* prevent creating a field on non-existing bundles, // because that would break the 'Body as field' upgrade for contrib @@ -513,7 +517,7 @@ function field_create_instance(&$instance) { throw new FieldException($message); } - _field_write_instance($instance); + _field_write_instance($instance, TRUE); // Clear caches field_cache_clear(); @@ -558,7 +562,7 @@ function field_update_instance($instance) { $instance['id'] = $prior_instance['id']; $instance['field_id'] = $prior_instance['field_id']; - _field_write_instance($instance, TRUE); + _field_write_instance($instance); // Clear caches. field_cache_clear(); @@ -571,12 +575,10 @@ function field_update_instance($instance) { * * @param $instance * An instance structure. - * @param $update - * Whether this is a new or existing instance. */ -function _field_write_instance(&$instance, $update = FALSE) { +function _field_write_instance(&$instance, $create = TRUE) { $field = field_read_field($instance['field_name']); - $field_type = field_info_field_types($field['type']); + $field_type = field_info_field_types($field->type); // Temporary workaround to allow incoming $instance as arrays or classed // objects. @@ -597,8 +599,7 @@ function _field_write_instance(&$instance, $update = FALSE) { ); // Set default instance settings. - $instance['settings'] += field_info_instance_settings($field['type']); - + $instance['settings'] += field_info_instance_settings($field->type); // Set default widget and settings. $instance['widget'] += array( // TODO: what if no 'default_widget' specified ? @@ -615,30 +616,20 @@ function _field_write_instance(&$instance, $update = FALSE) { $instance['widget']['module'] = $widget_type['module']; $instance['widget']['settings'] += field_info_widget_settings($instance['widget']['type']); - // The serialized 'data' column contains everything from $instance that does - // not have its own column and is not automatically populated when the - // instance is read. - $data = $instance; - unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']); - - $record = array( - 'field_id' => $instance['field_id'], - 'field_name' => $instance['field_name'], - 'entity_type' => $instance['entity_type'], - 'bundle' => $instance['bundle'], - 'data' => $data, - 'deleted' => $instance['deleted'], - ); - // We need to tell drupal_update_record() the primary keys to trigger an - // update. - if ($update) { - $record['id'] = $instance['id']; - drupal_write_record('field_config_instance', $record, array('id')); - } - else { - drupal_write_record('field_config_instance', $record); - $instance['id'] = $record['id']; + // Save into config. + if ($create) { + $field_instance = entity_create('field_instance', array( + 'id' => $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name'], + 'label' => $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name'], + 'data' => $instance, + )); + } + else { + $field_instance = entity_load('field_instance', $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name']); + $field_instance->data = $instance; } + + $field_instance->save(); } /** @@ -673,8 +664,8 @@ function field_read_instance($entity_type, $field_name, $bundle, $include_additi * * @param $param * An array of properties to use in selecting a field instance. Valid keys - * include any column of the field_config_instance table. If NULL, all - * instances will be returned. + * include any property of the instance config object, except for data. + * If NULL, all instances will be returned. * @param $include_additional * The default behavior of this function is to not return field instances that * have been marked deleted, or whose field is inactive. Setting @@ -685,44 +676,71 @@ function field_read_instance($entity_type, $field_name, $bundle, $include_additi * An array of instances matching the arguments. */ function field_read_instances($params = array(), $include_additional = array()) { - $include_inactive = isset($include_additional['include_inactive']) && $include_additional['include_inactive']; - $include_deleted = isset($include_additional['include_deleted']) && $include_additional['include_deleted']; + $instances = array(); - $query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC)); - $query->join('field_config', 'fc', 'fc.id = fci.field_id'); - $query->fields('fci'); + $deleted_fields = state()->get('field.field.deleted'); + $include_inactive = isset($include_additional['include_inactive']) && $include_additional['include_inactive']; + $include_deleted = (isset($include_additional['include_deleted']) && $include_additional['include_deleted']) || (isset($params['deleted']) && $params['deleted']); - // Turn the conditions into a query. - foreach ($params as $key => $value) { - $query->condition('fci.' . $key, $value); + if ($include_deleted) { + $deleted_instances = state()->get('field.instance.deleted') ?: array(); } - if (!$include_inactive) { - $query - ->condition('fc.active', 1) - ->condition('fc.storage_active', 1); - } - if (!$include_deleted) { - $query->condition('fc.deleted', 0); - $query->condition('fci.deleted', 0); + + // Get configuration instances. + $config_instances = entity_load_multiple('field_instance'); + // Merge deleted instances. + if (!empty($deleted_instances)) { + $config_instances += $deleted_instances; } - $instances = array(); - $results = $query->execute(); + foreach ($config_instances as $config) { + if (is_object($config)) { + $instance = $config->data; + } + else { + $instance = $config; + } + + $entity_info = entity_get_info($instance['entity_type']); + + // Get data from the field. If the field is marked as deleted, we + // need to get it from the state storage. + $field = entity_load('field_entity', $instance['field_name']); + if ($include_deleted) { + if (empty($field) && isset($deleted_fields[$instance['field_id']])) { + $field = $deleted_fields[$instance['field_id']]; + } + } + if (empty($field)) { + continue; + } + + $instance['active'] = $field->active; + $instance['locked'] = $field->locked; + $instance['type'] = $field->type; + $instance['module'] = $field->module; + $instance['storage_type'] = $field->storage_type; + $instance['storage_active'] = $field->storage_active; + $instance['storage_module'] = $field->storage_module; - foreach ($results as $record) { - // Filter out instances on unknown entity types (for instance because the - // module exposing them was disabled). - $entity_info = entity_get_info($record['entity_type']); if ($include_inactive || $entity_info) { - $instance = unserialize($record['data']); - $instance['id'] = $record['id']; - $instance['field_id'] = $record['field_id']; - $instance['field_name'] = $record['field_name']; - $instance['entity_type'] = $record['entity_type']; - $instance['bundle'] = $record['bundle']; - $instance['deleted'] = $record['deleted']; + // Conditions. + if (!$include_inactive) { + $params['active'] = 1; + $params['storage_active'] = 1; + } + if (!$include_deleted) { + $params['deleted'] = 0; + } + foreach ($params as $key => $value) { + if ($instance[$key] != $value) { + continue 2; + } + } + // Invoke read instance. module_invoke_all('field_read_instance', $instance); + $instances[] = $instance; } } @@ -740,27 +758,28 @@ function field_read_instances($params = array(), $include_additional = array()) * fields left without instances. Defaults to TRUE. */ function field_delete_instance($instance, $field_cleanup = TRUE) { - // Mark the field instance for deletion. - db_update('field_config_instance') - ->fields(array('deleted' => 1)) - ->condition('field_name', $instance['field_name']) - ->condition('entity_type', $instance['entity_type']) - ->condition('bundle', $instance['bundle']) - ->execute(); + + // Delete the configuration of this instance and save the configuration + // in the key_value table so we can use it later during field_purge_batch(). + $deleted_instances = state()->get('field.instance.deleted') ?: array(); + $instance['deleted'] = TRUE; + $deleted_instances[$instance['id']] = $instance; + state()->set('field.instance.deleted', $deleted_instances); + entity_load('field_instance', $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name'])->delete(); // Clear the cache. field_cache_clear(); // Mark instance data for deletion. $field = field_info_field($instance['field_name']); - module_invoke($field['storage']['module'], 'field_storage_delete_instance', $instance); + module_invoke($field->storage['module'], 'field_storage_delete_instance', $instance); // Let modules react to the deletion of the instance. module_invoke_all('field_delete_instance', $instance); // Delete the field itself if we just deleted its last instance. - if ($field_cleanup && count($field['bundles']) == 0) { - field_delete_field($field['field_name']); + if ($field_cleanup && count($field->bundles) == 0) { + field_delete_field($field->field_name); } } @@ -866,7 +885,7 @@ function field_purge_batch($batch_size) { $field = field_info_field_by_id($instance['field_id']); // Retrieve some entities. $query = $factory->get($entity_type) - ->condition('id:' . $field['id'] . '.deleted', 1) + ->condition('id:' . $field->id() . '.deleted', 1) ->range(0, $batch_size); // If there's no bundle key, all results will have the same bundle. if (!empty($info[$entity_type]['entity_keys']['bundle'])) { @@ -884,7 +903,7 @@ function field_purge_batch($batch_size) { $ids->entity_id = $entity_id; $entities[$entity_id] = _field_create_entity_from_ids($ids); } - field_attach_load($entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1)); + field_attach_load($entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field->id(), 'deleted' => 1)); foreach ($entities as $entity) { // Purge the data for the entity. field_purge_data($entity, $field, $instance); @@ -897,9 +916,9 @@ function field_purge_batch($batch_size) { } // Retrieve all deleted fields. Any that have no instances can be purged. - $fields = field_read_fields(array('deleted' => 1), array('include_deleted' => 1)); - foreach ($fields as $field) { - $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => 1)); + $deleted_fields = state()->get('field.field.deleted') ?: array(); + foreach ($deleted_fields as $field) { + $instances = field_read_instances(array('field_id' => $field->id()), array('include_deleted' => 1)); if (empty($instances)) { field_purge_field($field); } @@ -927,7 +946,7 @@ function field_purge_data(EntityInterface $entity, $field, $instance) { _field_invoke('delete', $entity, $dummy, $dummy, $options); // Tell the field storage system to purge the data. - module_invoke($field['storage']['module'], 'field_storage_purge', $entity, $field, $instance); + module_invoke($field->storage['module'], 'field_storage_purge', $entity, $field, $instance); // Let other modules act on purging the data. foreach (module_implements('field_attach_purge') as $module) { @@ -946,13 +965,13 @@ function field_purge_data(EntityInterface $entity, $field, $instance) { * The instance record to purge. */ function field_purge_instance($instance) { - db_delete('field_config_instance') - ->condition('id', $instance['id']) - ->execute(); - // Notify the storage engine. $field = field_info_field_by_id($instance['field_id']); - module_invoke($field['storage']['module'], 'field_storage_purge_instance', $instance); + module_invoke($field->storage['module'], 'field_storage_purge_instance', $instance); + + $deleted_instances = state()->get('field.instance.deleted'); + unset($deleted_instances[$instance['id']]); + state()->set('field.instance.deleted', $deleted_instances); // Clear the cache. field_info_cache_clear(); @@ -971,17 +990,17 @@ function field_purge_instance($instance) { * The field record to purge. */ function field_purge_field($field) { - $instances = field_read_instances(array('field_id' => $field['id']), array('include_deleted' => 1)); + $instances = field_read_instances(array('field_id' => $field->id()), array('include_deleted' => 1)); if (count($instances) > 0) { - throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field['field_name']))); + throw new FieldException(t('Attempt to purge a field @field_name that still has instances.', array('@field_name' => $field->field_name))); } - db_delete('field_config') - ->condition('id', $field['id']) - ->execute(); + $deleted_fields = state()->get('field.field.deleted'); + unset($deleted_fields[$field->id()]); + state()->set('field.field.deleted', $deleted_fields); // Notify the storage engine. - module_invoke($field['storage']['module'], 'field_storage_purge_field', $field); + module_invoke($field->storage['module'], 'field_storage_purge_field', $field); // Clear the cache. field_info_cache_clear(); diff --git a/core/modules/field/field.default.inc b/core/modules/field/field.default.inc index 27ba32c..55ccdad 100644 --- a/core/modules/field/field.default.inc +++ b/core/modules/field/field.default.inc @@ -29,7 +29,7 @@ * @param $langcode * The language associated with $items. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * @param $errors * The array of errors, keyed by field name and by value delta, that have * already been reported for the entity. The function should add its errors to @@ -45,10 +45,10 @@ function field_default_validate(EntityInterface $entity, $field, $instance, $lan // Check that the number of values doesn't exceed the field cardinality. // For form submitted values, this can only happen with 'multiple value' // widgets. - if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && count($items) > $field['cardinality']) { - $errors[$field['field_name']][$langcode][0][] = array( + if ($field->cardinality != FIELD_CARDINALITY_UNLIMITED && count($items) > $field->cardinality) { + $errors[$field->field_name][$langcode][0][] = array( 'error' => 'field_cardinality', - 'message' => t('%name: this field cannot hold more than @count values.', array('%name' => $instance['label'], '@count' => $field['cardinality'])), + 'message' => t('%name: this field cannot hold more than @count values.', array('%name' => $instance['label'], '@count' => $field->cardinality)), ); } } @@ -65,14 +65,14 @@ function field_default_validate(EntityInterface $entity, $field, $instance, $lan * @param $langcode * The language the entity has to be translated to. * @param $items - * $entity->{$field['field_name']}[$langcode], or an empty array if unset. + * $entity->{$field->field_name}[$langcode], or an empty array if unset. * @param \Drupal\Core\Entity\EntityInterface $source_entity * The source entity holding the field values to be translated. * @param $source_langcode * The source language from which to translate. */ function field_default_prepare_translation(EntityInterface $entity, $field, $instance, $langcode, &$items, EntityInterface $source_entity, $source_langcode) { - $field_name = $field['field_name']; + $field_name = $field->field_name; // If the field is untranslatable keep using LANGUAGE_NOT_SPECIFIED. if ($langcode == LANGUAGE_NOT_SPECIFIED) { $source_langcode = LANGUAGE_NOT_SPECIFIED; diff --git a/core/modules/field/field.form.inc b/core/modules/field/field.form.inc index 203a112..7ac7ef1 100644 --- a/core/modules/field/field.form.inc +++ b/core/modules/field/field.form.inc @@ -159,7 +159,7 @@ function field_add_more_js($form, $form_state) { $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); $field = $field_state['field']; - if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED) { + if ($field->cardinality != FIELD_CARDINALITY_UNLIMITED) { return; } diff --git a/core/modules/field/field.info b/core/modules/field/field.info index c74da0e..3c6c5fb 100644 --- a/core/modules/field/field.info +++ b/core/modules/field/field.info @@ -3,5 +3,4 @@ description = Field API to add fields to entities like nodes and users. package = Core version = VERSION core = 8.x -dependencies[] = field_sql_storage required = TRUE diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index b422b47..73e03b2 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -299,8 +299,8 @@ function field_info_fields() { $fields = array(); foreach ($info as $key => $field) { - if (!$field['deleted']) { - $fields[$field['field_name']] = $field; + if (!$field->deleted) { + $fields[$field->field_name] = $field; } } diff --git a/core/modules/field/field.install b/core/modules/field/field.install index 695fd89..dfba4e9 100644 --- a/core/modules/field/field.install +++ b/core/modules/field/field.install @@ -9,158 +9,7 @@ * Implements hook_schema(). */ function field_schema() { - // Static (meta) tables. - $schema['field_config'] = array( - 'fields' => array( - 'id' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'The primary identifier for a field', - ), - 'field_name' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'description' => 'The name of this field. Non-deleted field names are unique, but multiple deleted fields can have the same name.', - ), - 'type' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'description' => 'The type of this field.', - ), - 'module' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The module that implements the field type.', - ), - 'active' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Boolean indicating whether the module that implements the field type is enabled.', - ), - 'storage_type' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'description' => 'The storage backend for the field.', - ), - 'storage_module' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '', - 'description' => 'The module that implements the storage backend.', - ), - 'storage_active' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - 'description' => 'Boolean indicating whether the module that implements the storage backend is enabled.', - ), - 'locked' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - 'description' => '@TODO', - ), - 'data' => array( - 'type' => 'blob', - 'size' => 'big', - 'not null' => TRUE, - 'serialize' => TRUE, - 'description' => 'Serialized data containing the field properties that do not warrant a dedicated column.', - ), - 'cardinality' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - ), - 'translatable' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - ), - 'deleted' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('id'), - 'indexes' => array( - 'field_name' => array('field_name'), - // Used by field_read_fields(). - 'active' => array('active'), - 'storage_active' => array('storage_active'), - 'deleted' => array('deleted'), - // Used by field_sync_field_status(). - 'module' => array('module'), - 'storage_module' => array('storage_module'), - 'type' => array('type'), - 'storage_type' => array('storage_type'), - ), - ); - $schema['field_config_instance'] = array( - 'fields' => array( - 'id' => array( - 'type' => 'serial', - 'not null' => TRUE, - 'description' => 'The primary identifier for a field instance', - ), - 'field_id' => array( - 'type' => 'int', - 'not null' => TRUE, - 'description' => 'The identifier of the field attached by this instance', - ), - 'field_name' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '' - ), - 'entity_type' => array( - 'type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'default' => '' - ), - 'bundle' => array( - 'type' => 'varchar', - 'length' => 128, - 'not null' => TRUE, - 'default' => '' - ), - 'data' => array( - 'type' => 'blob', - 'size' => 'big', - 'not null' => TRUE, - 'serialize' => TRUE, - ), - 'deleted' => array( - 'type' => 'int', - 'size' => 'tiny', - 'not null' => TRUE, - 'default' => 0, - ), - ), - 'primary key' => array('id'), - 'indexes' => array( - // Used by field_delete_instance(). - 'field_name_bundle' => array('field_name', 'entity_type', 'bundle'), - // Used by field_read_instances(). - 'deleted' => array('deleted'), - ), - ); + $schema['cache_field'] = drupal_get_schema_unprocessed('system', 'cache'); $schema['cache_field']['description'] = 'Cache table for the Field module to store already built field informations.'; @@ -172,7 +21,7 @@ function field_schema() { * * @ingroup update_api */ -function _update_7000_field_create_field(&$field) { +function _update_7000_field_create_field($field) { // Merge in default values.` $field += array( 'entity_types' => array(), @@ -229,12 +78,25 @@ function _update_7000_field_create_field(&$field) { 'deleted' => (int) $field['deleted'], ); // We don't use drupal_write_record() here because it depends on the schema. - $field['id'] = db_insert('field_config') + $record['id'] = db_insert('field_config') ->fields($record) ->execute(); - // Create storage for the field. - field_sql_storage_field_storage_create_field($field); + // Extra keys - @todo clean this up. + $record['settings'] = $data['settings']; + $record['columns'] = $field['columns']; + $record['indexes'] = isset($data['indexes']) ? $data['indexes'] : array(); + if (!isset($record['foreign_keys'])) { + $record['foreign_keys'] = array(); + } + if (isset($data['foreign keys'])) { + $record['foreign_keys'] += $data['foreign keys']; + } + $record['storage'] = $data['storage']; + unset($record['data']); + field_sql_storage_field_storage_create_field((object) $record); + + return $record; } /** @@ -271,7 +133,6 @@ function _update_7000_field_delete_field($field_name) { ->execute(); } - /** * Deletes an instance and all its data of a field stored in SQL Storage. * @@ -382,15 +243,14 @@ function _update_7000_field_create_instance($field, &$instance) { */ /** - * Reassign all list.module fields to be controlled by options.module. + * Implements hook_update_dependencies(). */ -function field_update_8001() { - db_update('field_config') - ->fields(array( - 'module' => 'options', - )) - ->condition('module', 'list') - ->execute(); +function field_update_dependencies() { + // Convert to config after SQL storage has been updated. + $dependencies['field_sql_storage'][8000] = array( + 'field' => 8002, + ); + return $dependencies; } /** @@ -398,7 +258,7 @@ function field_update_8001() { * * @ingroup config_upgrade */ -function field_update_8002() { +function field_update_8001() { $displays = array(); module_load_install('entity'); @@ -442,7 +302,7 @@ function field_update_8002() { // Migration of 'extra_fields' display settings. Avoid calling // entity_get_info() by fetching the relevant variables directly in the - // cariables table. + // variable table. $variables = array_map('unserialize', db_query("SELECT name, value FROM {variable} WHERE name LIKE '%field_bundle_settings_%'")->fetchAllKeyed()); foreach ($variables as $variable_name => $variable_value) { if (preg_match('/field_bundle_settings_(.*)__(.*)/', $variable_name, $matches)) { @@ -484,6 +344,105 @@ function field_update_8002() { } /** + * Convert fields and instances to config. + */ +function field_update_8002() { + $manifest_ids = array('fields' => array(), 'instances' => array()); + + $deleted_fields = state()->get('field.field.deleted') ?: array(); + $deleted_instances = state()->get('field.instance.deleted') ?: array(); + + $field_ids = array(); + $fields = db_query("SELECT * FROM {field_config}")->fetchAll(PDO::FETCH_ASSOC); + foreach ($fields as $field) { + $field['data'] = unserialize($field['data']); + + // Keep old id for the field. + $old_id = $field['id']; + $field['id'] = $field['field_name']; + $field['settings'] = $field['data']['settings']; + + // @todo clean this up. + $field['storage'] = $field['data']['storage']; + if (!isset($field['indexes'])) { + $field['indexes'] = array(); + } + $field['foreign_keys'] = array(); + if (isset($field['data']['foreign keys'])) { + $field['foreign_keys'] += $field['data']['foreign keys']; + } + $schema = (array) module_invoke($field['module'], 'field_schema', (object) $field); + $schema += array('columns' => array(), 'indexes' => array()); + // 'columns' are hardcoded in the field type. + $field['columns'] = $schema['columns']; + // 'indexes' can be both hardcoded in the field type, and specified in the + // incoming $field definition. + $field['indexes'] += $schema['indexes']; + + // Remove data key. + unset($field['data']); + + // Reassign all list.module fields to be controlled by options.module. + if ($field['module'] == 'list') { + $field['module'] = 'options'; + } + + if (!$field['deleted']) { + $e_field = entity_create('field_entity', $field); + $e_field->save(); + $manifest_ids['fields'][] = $field['field_name']; + } + else { + $deleted_fields[$field->field_name] = $field; + } + $field_ids[$old_id] = array( + 'id' => $e_field->id(), + ); + } + + $instances = db_query("SELECT * FROM {field_config_instance}")->fetchAll(PDO::FETCH_ASSOC); + foreach ($instances as $instance) { + $instance += unserialize($instance['data']); + unset($instance['data']); + + // Map old field id to new UUID. + $old_id = $instance['field_id']; + $instance['field_id'] = $field_ids[$old_id]['id']; + + // Generate id for the instance. + $instance['id'] = field_generate_id(); + + if (!$instance['deleted']) { + $field_instance = entity_create('field_instance', array( + 'id' => $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name'], + 'label' => $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name'], + 'data' => $instance, + ))->save(); + $manifest_ids['instances'][] = $instance['entity_type'] . '.' . $instance['bundle'] . '.' . $instance['field_name']; + } + else { + $deleted_instances[$instance['id']] = $instance; + } + + // Update file_usage table in case this instance has a default image. + if (!empty($instance['settings']['default_image'])) { + db_update('file_usage') + ->fields(array('id' => $instance['field_id'])) + ->condition('fid', $instance['settings']['default_image']) + ->execute(); + } + } + + // Create the manifest files. + update_config_manifest_add('field.field', $manifest_ids['fields']); + update_config_manifest_add('field.instance', $manifest_ids['instances']); + + // Save the deleted fields and instances in state. + state()->set('field.field.deleted', $deleted_fields); + state()->set('field.instance.deleted', $deleted_instances); +} + +/** * @} End of "addtogroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 36bd18a..ec02ab8 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Template\Attribute; +use Drupal\Component\Uuid\Uuid; /* * Load all public Field API functions. Drupal currently has no @@ -334,7 +335,9 @@ function field_cron() { * required if there are any active fields of that type. */ function field_system_info_alter(&$info, $file, $type) { - if ($type == 'module' && module_hook($file->name, 'field_info')) { + // During a Drupal 7 to Drupal 8 upgrade it is only safe to call + // field_read_fields() once field_update_8002() has finished. + if ($type == 'module' && module_hook($file->name, 'field_info') && drupal_get_installed_schema_version('field') >= 8002) { $fields = field_read_fields(array('module' => $file->name), array('include_deleted' => TRUE)); if ($fields) { $info['required'] = TRUE; @@ -343,7 +346,7 @@ function field_system_info_alter(&$info, $file, $type) { // remains no actual, non-deleted fields) $non_deleted = FALSE; foreach ($fields as $field) { - if (empty($field['deleted'])) { + if (empty($field->deleted)) { $non_deleted = TRUE; break; } @@ -436,14 +439,14 @@ function field_entity_field_info($entity_type) { foreach ($instances as $field_name => $instance) { $field = field_info_field($field_name); - if (!empty($field_types[$field['type']]['field item class'])) { + if (!empty($field_types[$field->type]['field item class'])) { // @todo: Allow for adding field type settings. $definition = array( 'label' => t('Field !name', array('!name' => $field_name)), - 'type' => $field['type'] . '_field', + 'type' => $field->type . '_field', 'configurable' => TRUE, - 'translatable' => !empty($field['translatable']) + 'translatable' => !empty($field->translatable) ); if ($optional) { @@ -536,23 +539,41 @@ function field_modules_disabled($modules) { } /** - * Refreshes the 'active' and 'storage_active' columns for fields. + * Refreshes the 'active' and 'storage_active' values for fields. */ function field_sync_field_status() { - // Refresh the 'active' and 'storage_active' columns according to the current + + $deleted_fields = state()->get('field.field.deleted') ?: array(); + $fields = field_read_fields(array(), array('include_deleted' => 1 ,'include_inactive' => 1)); + // Refresh the 'active' and 'storage_active' values according to the current // set of enabled modules. $modules = array_keys(drupal_container()->get('module_handler')->getModuleList()); foreach ($modules as $module_name) { - field_associate_fields($module_name); + $fields = field_associate_fields($module_name, $fields); + } + + foreach ($fields as $id => $field) { + if (!in_array($field->module, $modules)) { + $fields[$id]->active = 0; + } + if (!in_array($field->storage_module, $modules)) { + $fields[$id]->storage_active = 0; + } + } + + foreach ($fields as $id => $field) { + if (!$field->deleted) { + $field->save(); + } + else { + $deleted_fields[$field->id()] = $field; + } } - db_update('field_config') - ->fields(array('active' => 0)) - ->condition('module', $modules, 'NOT IN') - ->execute(); - db_update('field_config') - ->fields(array('storage_active' => 0)) - ->condition('storage_module', $modules, 'NOT IN') - ->execute(); + + // Save the deleted fields. + state()->set('field.field.deleted', $deleted_fields); + + field_cache_clear(); } /** @@ -560,24 +581,37 @@ function field_sync_field_status() { * * @param $module * The name of the module to update on. + * @param $fields + * A collection of fields. */ -function field_associate_fields($module) { +function field_associate_fields($module, $fields) { + // Associate field types. $field_types = (array) module_invoke($module, 'field_info'); + if ($field_types) { - db_update('field_config') - ->fields(array('module' => $module, 'active' => 1)) - ->condition('type', array_keys($field_types)) - ->execute(); + $field_types = array_keys($field_types); + foreach ($fields as $id => $field) { + if (in_array($field->type, $field_types)) { + $fields[$id]->module = $module; + $fields[$id]->active = TRUE; + } + } } + // Associate storage backends. $storage_types = (array) module_invoke($module, 'field_storage_info'); if ($storage_types) { - db_update('field_config') - ->fields(array('storage_module' => $module, 'storage_active' => 1)) - ->condition('storage_type', array_keys($storage_types)) - ->execute(); + $storage_types = array_keys($storage_types); + foreach ($fields as $id => $field) { + if (in_array($field->storage_type, $storage_types)) { + $fields[$id]->storage_module = $module; + $fields[$id]->storage_active = TRUE; + } + } } + + return $fields; } /** @@ -617,7 +651,7 @@ function field_get_default_value(EntityInterface $entity, $field, $instance, $la * the array keys to ensure sequential deltas. */ function _field_filter_items($field, $items) { - $function = $field['module'] . '_field_is_empty'; + $function = $field->module . '_field_is_empty'; foreach ((array) $items as $delta => $item) { // Explicitly break if the function is undefined. if ($function($item, $field)) { @@ -639,7 +673,7 @@ function _field_filter_items($field, $items) { * The sorted array of field items. */ function _field_sort_items($field, $items) { - if (($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) && isset($items[0]['_weight'])) { + if (($field->cardinality > 1 || $field->cardinality == FIELD_CARDINALITY_UNLIMITED) && isset($items[0]['_weight'])) { usort($items, '_field_sort_items_helper'); foreach ($items as $delta => $item) { if (is_array($items[$delta])) { @@ -784,6 +818,27 @@ function field_cache_clear() { } /** + * Generate an id for fields or instances. + * + * When a field is a deleted, the tables are renamed to {field_data_field_id} + * and {field_revision_field_id}. To make sure alternative uuid implementations + * don't generate longer uuid's and using str_replace() to replace dashes + * to underscores might end up in table names longer than 64 characters, we + * hash the uuid and then take the first 6 characters so we end up with a short + * unique id. + */ +function field_generate_id($existing_uuid = '') { + if (empty($existing_uuid)) { + $uuid = new Uuid(); + $uuid = $uuid->generate(); + } + else { + $uuid = $existing_uuid; + } + return substr(hash('sha256', $uuid), 0, 6); +} + +/** * Filters an HTML string to prevent cross-site-scripting (XSS) vulnerabilities. * * Like filter_xss_admin(), but with a shorter list of allowed tags. @@ -933,7 +988,7 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options // $display_options, so we cannot let preparation happen internally. $field = field_info_field($field_name); $formatter_manager = drupal_container()->get('plugin.manager.field.formatter'); - $display_options = $formatter_manager->prepareConfiguration($field['type'], $display_options); + $display_options = $formatter_manager->prepareConfiguration($field->type, $display_options); $formatter = $formatter_manager->getInstance(array( 'instance' => $instance, 'view_mode' => $view_mode, @@ -1010,10 +1065,10 @@ function field_get_items(EntityInterface $entity, $field_name, $langcode = NULL) * TRUE if the field has data for any entity; FALSE otherwise. */ function field_has_data($field) { - $field = field_info_field_by_id($field['id']); - $columns = array_keys($field['columns']); + $field = field_info_field_by_id($field->id()); + $columns = array_keys($field->columns); $factory = drupal_container()->get('entity.query'); - foreach ($field['bundles'] as $entity_type => $bundle) { + foreach ($field->bundles as $entity_type => $bundle) { // Entity Query throws an exception if there is no base table. $entity_info = entity_get_info($entity_type); if (!isset($entity_info['base_table'])) { @@ -1022,7 +1077,7 @@ function field_has_data($field) { $query = $factory->get($entity_type); $group = $query->orConditionGroup(); foreach ($columns as $column) { - $group->exists($field['field_name'] . '.' . $column); + $group->exists($field->field_name . '.' . $column); } $result = $query ->condition($group) diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index a9b33ac..5f063ff 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -28,7 +28,7 @@ * * The available language codes for a particular field are returned by * field_available_languages(). Whether a field is translatable is determined by - * calling field_is_translatable(), which checks the $field['translatable'] + * calling field_is_translatable(), which checks the $field->translatable * property returned by field_info_field(), and whether there is at least one * translation handler available for the field. A translation handler is a * module registering itself via hook_entity_info_alter() to handle field @@ -129,7 +129,7 @@ function field_available_languages($entity_type, $field) { $drupal_static_fast['field_langcodes'] = &drupal_static(__FUNCTION__); } $field_langcodes = &$drupal_static_fast['field_langcodes']; - $field_name = $field['field_name']; + $field_name = $field->field_name; if (!isset($field_langcodes[$entity_type][$field_name])) { // If the field has language support enabled we retrieve an (alterable) list @@ -208,7 +208,10 @@ function field_content_languages() { * TRUE if the field can be translated. */ function field_is_translatable($entity_type, $field) { - return $field['translatable'] && field_has_translation_handler($entity_type); + // See http://drupal.org/node/1862758#comment-7035586 + if (!empty($field)) { + return $field->translatable && field_has_translation_handler($entity_type); + } } /** diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index 6c769cd..4a53bcb 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -18,11 +18,11 @@ function field_views_data() { $data = array(); foreach (field_info_fields() as $field) { - if ($field['storage']['type'] != 'field_sql_storage') { + if ($field->storage['type'] != 'field_sql_storage') { continue; } - $module = $field['module']; + $module = $field->module; $result = (array) module_invoke($module, 'field_views_data', $field); if (empty($result)) { @@ -48,11 +48,11 @@ function field_views_data() { */ function field_views_data_alter(&$data) { foreach (field_info_fields() as $field) { - if ($field['storage']['type'] != 'field_sql_storage') { + if ($field->storage['type'] != 'field_sql_storage') { continue; } - $function = $field['module'] . '_field_views_data_views_data_alter'; + $function = $field->module . '_field_views_data_views_data_alter'; if (function_exists($function)) { $function($data, $field); } @@ -93,7 +93,7 @@ function field_views_field_default_views_data($field) { $field_types = field_info_field_types(); // Check the field module is available. - if (!isset($field_types[$field['type']])) { + if (!isset($field_types[$field->type])) { return; } @@ -110,10 +110,10 @@ function field_views_field_default_views_data($field) { $revision_tables = array(); $groups = array(); - $group_name = count($field['bundles']) > 1 ? t('Field') : NULL; + $group_name = count($field->bundles) > 1 ? t('Field') : NULL; // Build the relationships between the field table and the entity tables. - foreach ($field['bundles'] as $entity => $bundles) { + foreach ($field->bundles as $entity => $bundles) { $entity_info = entity_get_info($entity); $groups[$entity] = $entity_info['label']; @@ -171,25 +171,25 @@ function field_views_field_default_views_data($field) { } $add_fields = array('delta', 'langcode', 'bundle'); - foreach ($field['columns'] as $column_name => $attributes) { - $add_fields[] = _field_sql_storage_columnname($field['field_name'], $column_name); + foreach ($field->columns as $column_name => $attributes) { + $add_fields[] = _field_sql_storage_columnname($field->field_name, $column_name); } // Note: we don't have a label available here, because we are at the field // level, not at the instance level. So we just go through all instances // and take the one which is used the most frequently. - $field_name = $field['field_name']; + $field_name = $field->field_name; list($label, $all_labels) = field_views_field_label($field_name); foreach ($tables as $type => $table) { if ($type == FIELD_LOAD_CURRENT) { $group = $group_name; $old_column = 'entity_id'; - $column = $field['field_name']; + $column = $field->field_name; } else { $group = t('@group (historical data)', array('@group' => $group_name)); $old_column = 'revision_id'; - $column = $field['field_name'] . '-' . $old_column; + $column = $field->field_name . '-' . $old_column; } $data[$table][$column] = array( @@ -237,12 +237,12 @@ function field_views_field_default_views_data($field) { $data[$table][$column]['help'] .= ' ' . t('Also known as: !also.', array('!also' => implode(', ', $also_known))); } - $keys = array_keys($field['columns']); + $keys = array_keys($field->columns); $real_field = reset($keys); $data[$table][$column]['field'] = array( 'table' => $table, 'id' => 'field', - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, // Provide a real field for group by. 'real field' => $column . '_' . $real_field, 'additional fields' => $add_fields, @@ -253,7 +253,7 @@ function field_views_field_default_views_data($field) { ); } - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $allow_sort = TRUE; // Identify likely filters and arguments for each column based on field type. @@ -280,12 +280,12 @@ function field_views_field_default_views_data($field) { break; } - if (count($field['columns']) == 1 || $column == 'value') { - $title = t('@label (!name)', array('@label' => $label, '!name' => $field['field_name'])); + if (count($field->columns) == 1 || $column == 'value') { + $title = t('@label (!name)', array('@label' => $label, '!name' => $field->field_name)); $title_short = $label; } else { - $title = t('@label (!name:!column)', array('@label' => $label, '!name' => $field['field_name'], '!column' => $column)); + $title = t('@label (!name:!column)', array('@label' => $label, '!name' => $field->field_name, '!column' => $column)); $title_short = t('@label:!column', array('@label' => $label, '!column' => $column)); } @@ -296,10 +296,10 @@ function field_views_field_default_views_data($field) { else { $group = t('@group (historical data)', array('@group' => $group_name)); } - $column_real_name = $field['storage']['details']['sql'][$type][$table][$column]; + $column_real_name = $field->storage['details']['sql'][$type][$table][$column]; // Load all the fields from the table by default. - $additional_fields = array_values($field['storage']['details']['sql'][$type][$table]); + $additional_fields = array_values($field->storage['details']['sql'][$type][$table]); $data[$table][$column_real_name] = array( 'group' => $group, @@ -315,11 +315,11 @@ function field_views_field_default_views_data($field) { foreach ($all_labels as $entity_name => $labels) { foreach ($labels as $label_name => $true) { if ($group_name != $groups[$entity_name] || $label != $label_name) { - if (count($field['columns']) == 1 || $column == 'value') { - $alias_title = t('@label (!name)', array('@label' => $label_name, '!name' => $field['field_name'])); + if (count($field->columns) == 1 || $column == 'value') { + $alias_title = t('@label (!name)', array('@label' => $label_name, '!name' => $field->field_name)); } else { - $alias_title = t('@label (!name:!column)', array('@label' => $label_name, '!name' => $field['field_name'], '!column' => $column)); + $alias_title = t('@label (!name:!column)', array('@label' => $label_name, '!name' => $field->field_name, '!column' => $column)); } $aliases[] = array( 'group' => $groups[$entity_name], @@ -340,7 +340,7 @@ function field_views_field_default_views_data($field) { 'table' => $table, 'id' => $argument, 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'empty field name' => t('- No value -'), ); $data[$table][$column_real_name]['filter'] = array( @@ -348,7 +348,7 @@ function field_views_field_default_views_data($field) { 'table' => $table, 'id' => $filter, 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'allow empty' => TRUE, ); if (!empty($allow_sort)) { @@ -357,13 +357,13 @@ function field_views_field_default_views_data($field) { 'table' => $table, 'id' => $sort, 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, ); } // Expose additional delta column for multiple value fields. - if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) { - $title_delta = t('@label (!name:delta)', array('@label' => $label, '!name' => $field['field_name'])); + if ($field->cardinality > 1 || $field->cardinality == FIELD_CARDINALITY_UNLIMITED) { + $title_delta = t('@label (!name:delta)', array('@label' => $label, '!name' => $field->field_name)); $title_short_delta = t('@label:delta', array('@label' => $label)); $data[$table]['delta'] = array( @@ -381,14 +381,14 @@ function field_views_field_default_views_data($field) { 'id' => 'numeric', 'additional fields' => $additional_fields, 'empty field name' => t('- No value -'), - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, ); $data[$table]['delta']['filter'] = array( 'field' => 'delta', 'table' => $table, 'id' => 'numeric', 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'allow empty' => TRUE, ); $data[$table]['delta']['sort'] = array( @@ -396,13 +396,13 @@ function field_views_field_default_views_data($field) { 'table' => $table, 'id' => 'standard', 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, ); } // Expose additional language column for translatable fields. - if (!empty($field['translatable'])) { - $title_language = t('@label (!name:language)', array('@label' => $label, '!name' => $field['field_name'])); + if (!empty($field->translatable)) { + $title_language = t('@label (!name:language)', array('@label' => $label, '!name' => $field->field_name)); $title_short_language = t('@label:language', array('@label' => $label)); $data[$table]['language'] = array( @@ -420,14 +420,14 @@ function field_views_field_default_views_data($field) { 'id' => 'language', 'additional fields' => $additional_fields, 'empty field name' => t(''), - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, ); $data[$table]['language']['filter'] = array( 'field' => 'language', 'table' => $table, 'id' => 'language', 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'allow empty' => TRUE, ); $data[$table]['language']['sort'] = array( @@ -435,7 +435,7 @@ function field_views_field_default_views_data($field) { 'table' => $table, 'id' => 'standard', 'additional fields' => $additional_fields, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, ); } } @@ -455,7 +455,7 @@ function list_field_views_data($field) { $data[$table_name][$field_name]['filter']['id'] = 'field_list'; } if (isset($field_data['argument']) && $field_name != 'delta') { - if ($field['type'] == 'list_text') { + if ($field->type == 'list_text') { $data[$table_name][$field_name]['argument']['id'] = 'field_list_string'; } else { diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 7ff6850..877cc08 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -142,17 +142,10 @@ public function getFieldMap() { $map = array(); - $query = db_select('field_config_instance', 'fci'); - $query->join('field_config', 'fc', 'fc.id = fci.field_id'); - $query->fields('fc', array('type')); - $query->fields('fci', array('field_name', 'entity_type', 'bundle')) - ->condition('fc.active', 1) - ->condition('fc.storage_active', 1) - ->condition('fc.deleted', 0) - ->condition('fci.deleted', 0); - foreach ($query->execute() as $row) { - $map[$row->field_name]['bundles'][$row->entity_type][] = $row->bundle; - $map[$row->field_name]['type'] = $row->type; + $instances = field_read_instances(); + foreach ($instances as $key => $instance) { + $map[$instance['field_name']]['bundles'][$instance['entity_type']][] = $instance['bundle']; + $map[$instance['field_name']]['type'] = $instance['type']; } // Save in "static" and persistent caches. @@ -181,7 +174,7 @@ public function getFields() { else { // Collect and prepare fields. foreach (field_read_fields(array(), array('include_deleted' => TRUE)) as $field) { - $this->fieldsById[$field['id']] = $this->prepareField($field); + $this->fieldsById[$field->id()] = $this->prepareField($field); } // Store in persistent cache. @@ -190,8 +183,8 @@ public function getFields() { // Fill the name/ID map. foreach ($this->fieldsById as $field) { - if (!$field['deleted']) { - $this->fieldIdsByName[$field['field_name']] = $field['id']; + if (!$field->deleted) { + $this->fieldIdsByName[$field->field_name] = $field->id(); } } @@ -228,7 +221,7 @@ public function getInstances($entity_type = NULL) { foreach (field_read_instances() as $instance) { $field = $this->getField($instance['field_name']); - $instance = $this->prepareInstance($instance, $field['type']); + $instance = $this->prepareInstance($instance, $field->type); $this->bundleInstances[$instance['entity_type']][$instance['bundle']][$instance['field_name']] = new FieldInstance($instance); } @@ -275,8 +268,8 @@ public function getField($field_name) { $field = $this->prepareField($field); // Save in the "static" cache. - $this->fieldsById[$field['id']] = $field; - $this->fieldIdsByName[$field['field_name']] = $field['id']; + $this->fieldsById[$field->id()] = $field; + $this->fieldIdsByName[$field->field_name] = $field->id(); return $field; } @@ -309,14 +302,14 @@ public function getFieldById($field_id) { // bundle. // Cache miss: read from definition. - if ($fields = field_read_fields(array('id' => $field_id), array('include_deleted' => TRUE))) { + if ($fields = field_read_fields(array('uuid' => $field_id), array('include_deleted' => TRUE))) { $field = current($fields); $field = $this->prepareField($field); // Store in the static cache. - $this->fieldsById[$field['id']] = $field; - if (!$field['deleted']) { - $this->fieldIdsByName[$field['field_name']] = $field['id']; + $this->fieldsById[$field->id()] = $field; + if (!$field->deleted) { + $this->fieldIdsByName[$field->field_name] = $field->id(); } return $field; @@ -355,10 +348,10 @@ public function getBundleInstances($entity_type, $bundle) { // Extract the field definitions and save them in the "static" cache. foreach ($info['fields'] as $field) { - if (!isset($this->fieldsById[$field['id']])) { - $this->fieldsById[$field['id']] = $field; - if (!$field['deleted']) { - $this->fieldIdsByName[$field['field_name']] = $field['id']; + if (!isset($this->fieldsById[$field->id()])) { + $this->fieldsById[$field->id()] = $field; + if (!$field->deleted) { + $this->fieldIdsByName[$field->field_name] = $field->id(); } } } @@ -382,22 +375,22 @@ public function getBundleInstances($entity_type, $bundle) { // Collect the fields in the bundle. $params = array('entity_type' => $entity_type, 'bundle' => $bundle); - $fields = field_read_fields($params); + $fields = field_read_fields(); // This iterates on non-deleted instances, so deleted fields are kept out of // the persistent caches. foreach (field_read_instances($params) as $instance) { $field = $fields[$instance['field_name']]; - $instance = $this->prepareInstance($instance, $field['type']); - $instances[$field['field_name']] = new FieldInstance($instance); + $instance = $this->prepareInstance($instance, $field->type); + $instances[$field->field_name] = new FieldInstance($instance); // If the field is not in our global "static" list yet, add it. - if (!isset($this->fieldsById[$field['id']])) { + if (!isset($this->fieldsById[$field->id()])) { $field = $this->prepareField($field); - $this->fieldsById[$field['id']] = $field; - $this->fieldIdsByName[$field['field_name']] = $field['id']; + $this->fieldsById[$field->id()] = $field; + $this->fieldIdsByName[$field->field_name] = $field->id(); } } @@ -413,6 +406,7 @@ public function getBundleInstances($entity_type, $bundle) { // The persistent cache additionally contains the definitions of the fields // involved in the bundle. + uasort($instances, array($this, '_orderInstances')); $cache = array( 'instances' => $instances, 'fields' => array() @@ -477,20 +471,20 @@ public function getBundleExtraFields($entity_type, $bundle) { */ public function prepareField($field) { // Make sure all expected field settings are present. - $field['settings'] += field_info_field_settings($field['type']); - $field['storage']['settings'] += field_info_storage_settings($field['storage']['type']); + $field->settings += field_info_field_settings($field->type); + $field->storage['settings'] += field_info_storage_settings($field->storage['type']); // Add storage details. - $details = (array) module_invoke($field['storage']['module'], 'field_storage_details', $field); + $details = (array) module_invoke($field->storage['module'], 'field_storage_details', $field); drupal_alter('field_storage_details', $details, $field); - $field['storage']['details'] = $details; + $field->storage['details'] = $details; // Populate the list of bundles using the field. - $field['bundles'] = array(); - if (!$field['deleted']) { + $field->bundles = array(); + if (!$field->deleted) { $map = $this->getFieldMap(); - if (isset($map[$field['field_name']])) { - $field['bundles'] = $map[$field['field_name']]['bundles']; + if (isset($map[$field->field_name])) { + $field->bundles = $map[$field->field_name]['bundles']; } } @@ -553,4 +547,11 @@ public function prepareExtraFields($extra_fields, $entity_type, $bundle) { return $result; } + + /** + * Helper function to sort the instances on the widget weight. + */ + function _orderInstances($a, $b) { + return ($a['widget']['weight'] < $b['widget']['weight']) ? -1 : 1; + } } diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php new file mode 100644 index 0000000..8a4d0e9 --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldInstanceStorageController.php @@ -0,0 +1,46 @@ +get('data'); + field_create_instance($config); + } + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::importChange(). + */ + public function importChange($name, Config $new_config, Config $old_config) { + $config = $new_config->get('data'); + field_update_instance($config); + } + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::importDelete(). + */ + public function importDelete($name, Config $new_config, Config $old_config) { + $config = $old_config->get('data'); + // In case the field has been deleted through this import hook, + // the instance will be deleted by then already. + if (!empty($config)) { + field_delete_instance($config); + } + } + +} diff --git a/core/modules/field/lib/Drupal/field/FieldStorageController.php b/core/modules/field/lib/Drupal/field/FieldStorageController.php new file mode 100644 index 0000000..a86c39c --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldStorageController.php @@ -0,0 +1,39 @@ +get()); + } + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::importChange(). + */ + public function importChange($name, Config $new_config, Config $old_config) { + field_update_field($new_config->get()); + } + + /** + * Overrides \Drupal\Core\Config\Entity\ConfigStorageController::importDelete(). + */ + public function importDelete($name, Config $new_config, Config $old_config) { + field_delete_field($old_config->get('field_name')); + } + +} diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldEntity.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldEntity.php new file mode 100644 index 0000000..5fe7c5c --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldEntity.php @@ -0,0 +1,185 @@ +uuid; + } +} diff --git a/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php new file mode 100644 index 0000000..177a26f --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Plugin/Core/Entity/FieldInstance.php @@ -0,0 +1,60 @@ + $this->label, '#view_mode' => $this->viewMode, '#language' => $langcode, - '#field_name' => $field['field_name'], - '#field_type' => $field['type'], - '#field_translatable' => $field['translatable'], + '#field_name' => $field->field_name, + '#field_type' => $field->type, + '#field_translatable' => $field->translatable, '#entity_type' => $entity_type, '#bundle' => $entity->bundle(), '#object' => $entity, @@ -108,7 +108,7 @@ public function view(EntityInterface $entity, $langcode, array $items) { '#formatter' => $this->getPluginId(), ); - $addition[$field['field_name']] = array_merge($info, $elements); + $addition[$field->field_name] = array_merge($info, $elements); } return $addition; diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php index c935c44..f4ee39f 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Formatter/FormatterPluginManager.php @@ -73,7 +73,7 @@ public function getInstance(array $options) { // Fill in default configuration if needed. if (!isset($options['prepare']) || $options['prepare'] == TRUE) { - $configuration = $this->prepareConfiguration($field['type'], $configuration); + $configuration = $this->prepareConfiguration($field->type, $configuration); } $plugin_id = $configuration['type']; @@ -82,9 +82,9 @@ public function getInstance(array $options) { // - $type_info doesn't exist (the widget type is unknown), // - the field type is not allowed for the widget. $definition = $this->getDefinition($configuration['type']); - if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) { + if (!isset($definition['class']) || !in_array($field->type, $definition['field_types'])) { // Grab the default widget for the field type. - $field_type_definition = field_info_field_types($field['type']); + $field_type_definition = field_info_field_types($field->type); $plugin_id = $field_type_definition['default_formatter']; } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php index 12118f8..aca00df 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetBase.php @@ -76,7 +76,7 @@ public function __construct($plugin_id, DiscoveryInterface $discovery, FieldInst public function form(EntityInterface $entity, $langcode, array $items, array &$form, array &$form_state, $get_delta = NULL) { $field = $this->field; $instance = $this->instance; - $field_name = $field['field_name']; + $field_name = $field->field_name; $parents = $form['#parents']; @@ -137,7 +137,7 @@ public function form(EntityInterface $entity, $langcode, array $items, array &$f '#type' => 'container', '#attributes' => array( 'class' => array( - 'field-type-' . drupal_html_class($field['type']), + 'field-type-' . drupal_html_class($field->type), 'field-name-' . drupal_html_class($field_name), 'field-widget-' . drupal_html_class($this->getPluginId()), ), @@ -176,12 +176,12 @@ public function form(EntityInterface $entity, $langcode, array $items, array &$f protected function formMultipleElements(EntityInterface $entity, array $items, $langcode, array &$form, array &$form_state) { $field = $this->field; $instance = $this->instance; - $field_name = $field['field_name']; + $field_name = $field->field_name; $parents = $form['#parents']; // Determine the number of widgets to display. - switch ($field['cardinality']) { + switch ($field->cardinality) { case FIELD_CARDINALITY_UNLIMITED: $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state); $max = $field_state['items_count']; @@ -189,8 +189,8 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ break; default: - $max = $field['cardinality'] - 1; - $is_multiple = ($field['cardinality'] > 1); + $max = $field->cardinality - 1; + $is_multiple = ($field->cardinality > 1); break; } @@ -234,8 +234,8 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ if ($elements) { $elements += array( '#theme' => 'field_multiple_value_form', - '#field_name' => $field['field_name'], - '#cardinality' => $field['cardinality'], + '#field_name' => $field->field_name, + '#cardinality' => $field->cardinality, '#required' => $instance['required'], '#title' => $title, '#description' => $description, @@ -245,7 +245,7 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ ); // Add 'add more' button, if not working with a programmed form. - if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED && empty($form_state['programmed'])) { + if ($field->cardinality == FIELD_CARDINALITY_UNLIMITED && empty($form_state['programmed'])) { $elements['add_more'] = array( '#type' => 'submit', '#name' => strtr($id_prefix, '-', '_') . '_add_more', @@ -276,10 +276,10 @@ protected function formSingleElement(EntityInterface $entity, array $items, $del '#entity_type' => $entity->entityType(), '#bundle' => $entity->bundle(), '#entity' => $entity, - '#field_name' => $field['field_name'], + '#field_name' => $field->field_name, '#language' => $langcode, '#field_parents' => $form['#parents'], - '#columns' => array_keys($field['columns']), + '#columns' => array_keys($field->columns), // Only the first widget should be required. '#required' => $delta == 0 && $instance['required'], '#delta' => $delta, @@ -309,7 +309,7 @@ protected function formSingleElement(EntityInterface $entity, array $items, $del * Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::extractFormValues(). */ public function extractFormValues(EntityInterface $entity, $langcode, array &$items, array $form, array &$form_state) { - $field_name = $this->field['field_name']; + $field_name = $this->field->field_name; // Extract the values from $form_state['values']. $path = array_merge($form['#parents'], array($field_name, $langcode)); @@ -360,7 +360,7 @@ public function extractFormValues(EntityInterface $entity, $langcode, array &$it * Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::flagErrors(). */ public function flagErrors(EntityInterface $entity, $langcode, array $items, array $form, array &$form_state) { - $field_name = $this->field['field_name']; + $field_name = $this->field->field_name; $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); @@ -423,7 +423,7 @@ public function massageFormValues(array $values, array $form, array &$form_state * The field values. */ protected function sortItems(array &$items) { - $is_multiple = ($this->field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) || ($this->field['cardinality'] > 1); + $is_multiple = ($this->field->cardinality == FIELD_CARDINALITY_UNLIMITED) || ($this->field->cardinality > 1); if ($is_multiple && isset($items[0]['_weight'])) { usort($items, function ($a, $b) { $a_weight = (is_array($a) ? $a['_weight'] : 0); diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php index 2d2c6e2..64c7106 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/Widget/WidgetPluginManager.php @@ -55,9 +55,9 @@ public function getInstance(array $options) { // Switch back to default widget if either: // - $type_info doesn't exist (the widget type is unknown), // - the field type is not allowed for the widget. - if (!isset($definition['class']) || !in_array($field['type'], $definition['field_types'])) { + if (!isset($definition['class']) || !in_array($field->type, $definition['field_types'])) { // Grab the default widget for the field type. - $field_type_definition = field_info_field_types($field['type']); + $field_type_definition = field_info_field_types($field->type); $type = $field_type_definition['default_widget']; } diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/widget/LegacyWidget.php b/core/modules/field/lib/Drupal/field/Plugin/field/widget/LegacyWidget.php index ee66f3f..b876e51 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/widget/LegacyWidget.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/widget/LegacyWidget.php @@ -68,7 +68,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr * code in field_default_form_errors(). */ public function flagErrors(EntityInterface $entity, $langcode, array $items, array $form, array &$form_state) { - $field_name = $this->field['field_name']; + $field_name = $this->field->field_name; $field_state = field_form_get_state($form['#parents'], $field_name, $langcode, $form_state); diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 30836a3..5e6edee 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -78,7 +78,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o $this->multiple = FALSE; $this->limit_values = FALSE; - if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) { + if ($field->cardinality > 1 || $field->cardinality == FIELD_CARDINALITY_UNLIMITED) { $this->multiple = TRUE; // If "Display all values in the same row" is FALSE, then we always limit @@ -94,7 +94,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o // Otherwise, we only limit values if the user hasn't selected "all", 0, or // the value matching field cardinality. - if ((intval($this->options['delta_limit']) && ($this->options['delta_limit'] != $field['cardinality'])) || intval($this->options['delta_offset'])) { + if ((intval($this->options['delta_limit']) && ($this->options['delta_limit'] != $field->cardinality)) || intval($this->options['delta_offset'])) { $this->limit_values = TRUE; } } @@ -262,8 +262,8 @@ protected function defineOptions() { // defineOptions runs before init/construct, so no $this->field_info $field = field_info_field($this->definition['field_name']); - $field_type = field_info_field_types($field['type']); - $column_names = array_keys($field['columns']); + $field_type = field_info_field_types($field->type); + $column_names = array_keys($field->columns); $default_column = ''; // Try to determine a sensible default. if (count($column_names) == 1) { @@ -298,7 +298,7 @@ protected function defineOptions() { // If we know the exact number of allowed values, then that can be // the default. Otherwise, default to 'all'. $options['delta_limit'] = array( - 'default' => ($field['cardinality'] > 1) ? $field['cardinality'] : 'all', + 'default' => ($field->cardinality > 1) ? $field->cardinality : 'all', ); $options['delta_offset'] = array( 'default' => 0, @@ -331,8 +331,8 @@ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); $field = $this->field_info; - $formatters = _field_view_formatter_options($field['type']); - $column_names = array_keys($field['columns']); + $formatters = _field_view_formatter_options($field->type); + $column_names = array_keys($field->columns); // If this is a multiple value field, add its options. if ($this->multiple) { @@ -340,7 +340,7 @@ public function buildOptionsForm(&$form, &$form_state) { } // No need to ask the user anything if the field has only one column. - if (count($field['columns']) == 1) { + if (count($field->columns) == 1) { $form['click_sort_column'] = array( '#type' => 'value', '#value' => isset($column_names[0]) ? $column_names[0] : '', @@ -426,7 +426,7 @@ function fakeFieldInstance($formatter, $formatter_settings) { $field_name = $this->definition['field_name']; $field = field_read_field($field_name); - $field_type = field_info_field_types($field['type']); + $field_type = field_info_field_types($field->type); return array( // Build a fake entity type and bundle. @@ -435,7 +435,7 @@ function fakeFieldInstance($formatter, $formatter_settings) { 'bundle' => 'views_fake', // Use the default field settings for settings and widget. - 'settings' => field_info_instance_settings($field['type']), + 'settings' => field_info_instance_settings($field->type), 'widget' => array( 'type' => $field_type['default_widget'], 'settings' => array(), @@ -483,14 +483,14 @@ function multiple_options_form(&$form, &$form_state) { // translating prefix and suffix separately. list($prefix, $suffix) = explode('@count', t('Display @count value(s)')); - if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) { + if ($field->cardinality == FIELD_CARDINALITY_UNLIMITED) { $type = 'textfield'; $options = NULL; $size = 5; } else { $type = 'select'; - $options = drupal_map_assoc(range(1, $field['cardinality'])); + $options = drupal_map_assoc(range(1, $field->cardinality)); $size = 1; } $form['multi_type'] = array( @@ -810,14 +810,14 @@ function render_item($count, $item) { function document_self_tokens(&$tokens) { $field = $this->field_info; - foreach ($field['columns'] as $id => $column) { + foreach ($field->columns as $id => $column) { $tokens['[' . $this->options['id'] . '-' . $id . ']'] = t('Raw @column', array('@column' => $id)); } } function add_self_tokens(&$tokens, $item) { $field = $this->field_info; - foreach ($field['columns'] as $id => $column) { + foreach ($field->columns as $id => $column) { // Use filter_xss_admin because it's user data and we can't be sure it is safe. // We know nothing about the data, though, so we can't really do much else. diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index c365961..7b3114e 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Field\FieldInstance; + /** * Unit test class for field bulk delete and batch purge functionality. */ @@ -119,7 +121,7 @@ function setUp() { foreach ($this->bundles as $bundle) { foreach ($this->fields as $field) { $instance = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => $this->entity_type, 'bundle' => $bundle, 'widget' => array( @@ -132,7 +134,7 @@ function setUp() { for ($i = 0; $i < 10; $i++) { $entity = field_test_create_entity($id, $id, $bundle); foreach ($this->fields as $field) { - $entity->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field['cardinality']); + $entity->{$field->field_name}[LANGUAGE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field->cardinality); } $entity->save(); $id++; @@ -157,7 +159,7 @@ function setUp() { function testDeleteFieldInstance() { $bundle = reset($this->bundles); $field = reset($this->fields); - $field_name = $field['field_name']; + $field_name = $field->field_name; $factory = drupal_container()->get('entity.query'); // There are 10 entities of this bundle. @@ -167,11 +169,11 @@ function testDeleteFieldInstance() { $this->assertEqual(count($found), 10, 'Correct number of entities found before deleting'); // Delete the instance. - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->field_name, $bundle); + field_delete_instance($instance->getArray()); // The instance still exists, deleted. - $instances = field_read_instances(array('field_id' => $field['id'], 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); + $instances = field_read_instances(array('field_id' => $field->id(), 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); $this->assertEqual($instances[0]['bundle'], $bundle, 'The deleted instance is for the correct bundle'); @@ -198,10 +200,10 @@ function testDeleteFieldInstance() { $ids->entity_id = $entity_id; $entities[$entity_id] = _field_create_entity_from_ids($ids); } - field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field['id'], 'deleted' => 1)); + field_attach_load($this->entity_type, $entities, FIELD_LOAD_CURRENT, array('field_id' => $field->id(), 'deleted' => 1)); $this->assertEqual(count($found), 10, 'Correct number of entities found after deleting'); foreach ($entities as $id => $entity) { - $this->assertEqual($this->entities[$id]->{$field['field_name']}, $entity->{$field['field_name']}, "Entity $id with deleted data loaded correctly"); + $this->assertEqual($this->entities[$id]->{$field->field_name}, $entity->{$field->field_name}, "Entity $id with deleted data loaded correctly"); } } @@ -217,8 +219,8 @@ function testPurgeInstance() { $field = reset($this->fields); // Delete the instance. - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->field_name, $bundle); + field_delete_instance($instance->getArray()); // No field hooks were called. $mem = field_test_memorize(); @@ -232,7 +234,7 @@ function testPurgeInstance() { // There are $count deleted entities left. $found = entity_query('test_entity') ->condition('fttype', $bundle) - ->condition($field['field_name'] . '.deleted', 1) + ->condition($field->field_name . '.deleted', 1) ->execute(); $this->assertEqual(count($found), $count, 'Correct number of entities found after purging 2'); } @@ -244,7 +246,7 @@ function testPurgeInstance() { // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); - $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->field_name); foreach (array_chunk($entities, $batch_size, TRUE) as $chunk_entity) { $hooks['field_test_field_load'][] = $chunk_entity; } @@ -254,19 +256,19 @@ function testPurgeInstance() { $this->checkHooksInvocations($hooks, $actual_hooks); // The instance still exists, deleted. - $instances = field_read_instances(array('field_id' => $field['id'], 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); + $instances = field_read_instances(array('field_id' => $field->id(), 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); // Purge the instance. field_purge_batch($batch_size); // The instance is gone. - $instances = field_read_instances(array('field_id' => $field['id'], 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); + $instances = field_read_instances(array('field_id' => $field->id(), 'deleted' => 1), array('include_deleted' => 1, 'include_inactive' => 1)); $this->assertEqual(count($instances), 0, 'The instance is gone'); // The field still exists, not deleted, because it has a second instance. - $fields = field_read_fields(array('id' => $field['id']), array('include_deleted' => 1, 'include_inactive' => 1)); - $this->assertTrue(isset($fields[$field['id']]), 'The field exists and is not deleted'); + $fields = field_read_fields(array('uuid' => $field->id()), array('include_deleted' => 1, 'include_inactive' => 1)); + $this->assertTrue(isset($fields[$field->id()]), 'The field exists and is not deleted'); } /** @@ -281,8 +283,8 @@ function testPurgeField() { // Delete the first instance. $bundle = reset($this->bundles); - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->field_name, $bundle); + field_delete_instance($instance->getArray()); // Assert that hook_field_delete() was not called yet. $mem = field_test_memorize(); @@ -298,7 +300,7 @@ function testPurgeField() { // bundle. $actual_hooks = field_test_memorize(); $hooks = array(); - $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->field_name); $hooks['field_test_field_load'][] = $entities; $hooks['field_test_field_delete'] = $entities; $this->checkHooksInvocations($hooks, $actual_hooks); @@ -307,13 +309,13 @@ function testPurgeField() { field_purge_batch(0); // The field still exists, not deleted. - $fields = field_read_fields(array('id' => $field['id']), array('include_deleted' => 1)); - $this->assertTrue(isset($fields[$field['id']]) && !$fields[$field['id']]['deleted'], 'The field exists and is not deleted'); + $fields = field_read_fields(array('uuid' => $field->id()), array('include_deleted' => 1)); + $this->assertTrue(isset($fields[$field->id()]) && !$fields[$field->id()]->deleted, 'The field exists and is not deleted'); // Delete the second instance. $bundle = next($this->bundles); - $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle); - field_delete_instance($instance); + $instance = field_info_instance($this->entity_type, $field->field_name, $bundle); + field_delete_instance($instance->getArray()); // Assert that hook_field_delete() was not called yet. $mem = field_test_memorize(); @@ -325,20 +327,20 @@ function testPurgeField() { // Check hooks invocations (same as above, for the 2nd bundle). $actual_hooks = field_test_memorize(); $hooks = array(); - $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field['field_name']); + $entities = $this->convertToPartialEntities($this->entities_by_bundles[$bundle], $field->field_name); $hooks['field_test_field_load'][] = $entities; $hooks['field_test_field_delete'] = $entities; $this->checkHooksInvocations($hooks, $actual_hooks); // The field still exists, deleted. - $fields = field_read_fields(array('id' => $field['id']), array('include_deleted' => 1)); - $this->assertTrue(isset($fields[$field['id']]) && $fields[$field['id']]['deleted'], 'The field exists and is deleted'); + $fields = field_read_fields(array('uuid' => $field->id()), array('include_deleted' => 1)); + $this->assertTrue(isset($fields[$field->id()]) && $fields[$field->id()]->deleted, 'The field exists and is deleted'); // Purge again to purge the instance and the field. field_purge_batch(0); // The field is gone. - $fields = field_read_fields(array('id' => $field['id']), array('include_deleted' => 1, 'include_inactive' => 1)); + $fields = field_read_fields(array('uuid' => $field->id()), array('include_deleted' => 1, 'include_inactive' => 1)); $this->assertEqual(count($fields), 0, 'The field is purged.'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index 1c539da..9503780 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -41,28 +41,27 @@ function testCreateField() { 'type' => 'test_field', ); field_test_memorize(); - $field_definition = field_create_field($field_definition); + $create_field = field_create_field($field_definition); $mem = field_test_memorize(); - $this->assertIdentical($mem['field_test_field_create_field'][0][0], $field_definition, 'hook_field_create_field() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_create_field'][0][0]->field_name, $field_definition['field_name'], 'hook_field_create_field() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_create_field'][0][0]->type, $field_definition['type'], 'hook_field_create_field() called with correct arguments.'); - // Read the raw record from the {field_config_instance} table. - $result = db_query('SELECT * FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name'])); - $record = $result->fetchAssoc(); - $record['data'] = unserialize($record['data']); + // Read the configuration. + $record = entity_load('field_entity', $field_definition['field_name']); // Ensure that basic properties are preserved. - $this->assertEqual($record['field_name'], $field_definition['field_name'], 'The field name is properly saved.'); - $this->assertEqual($record['type'], $field_definition['type'], 'The field type is properly saved.'); + $this->assertEqual($record->field_name, $field_definition['field_name'], 'The field name is properly saved.'); + $this->assertEqual($record->type, $field_definition['type'], 'The field type is properly saved.'); // Ensure that cardinality defaults to 1. - $this->assertEqual($record['cardinality'], 1, 'Cardinality defaults to 1.'); + $this->assertEqual($record->cardinality, 1, 'Cardinality defaults to 1.'); // Ensure that default settings are present. $field_type = field_info_field_types($field_definition['type']); - $this->assertIdentical($record['data']['settings'], $field_type['settings'], 'Default field settings have been written.'); + $this->assertEqual($record->settings, $field_type['settings'], 'Default field settings have been written.'); // Ensure that default storage was set. - $this->assertEqual($record['storage_type'], variable_get('field_storage_default'), 'The field type is properly saved.'); + $this->assertEqual($record->storage_type, variable_get('field_storage_default'), 'The field type is properly saved.'); // Guarantee that the name is unique. try { @@ -157,11 +156,10 @@ function testCreateField() { function testCreateFieldFail() { $field_name = 'duplicate'; $field_definition = array('field_name' => $field_name, 'type' => 'test_field', 'storage' => array('type' => 'field_test_storage_failure')); - $query = db_select('field_config')->condition('field_name', $field_name)->countQuery(); + $field = entity_load('field_entity', $field_name); - // The field does not appear in field_config. - $count = $query->execute()->fetchField(); - $this->assertEqual($count, 0, 'A field_config row for the field does not exist.'); + // The field does not exist. + $this->assertFalse($field, 'The field does not exist.'); // Try to create the field. try { @@ -172,9 +170,10 @@ function testCreateFieldFail() { $this->assertTrue(TRUE, 'Field creation (correctly) fails.'); } - // The field does not appear in field_config. - $count = $query->execute()->fetchField(); - $this->assertEqual($count, 0, 'A field_config row for the field does not exist.'); + // The field does not exist. + // $field = config('field.field.' . $field_name)->get(); + $field = entity_load('field_entity', $field_name); + $this->assertFalse($field, 'The field does not exist.'); } /** @@ -221,10 +220,11 @@ function testReadFields() { field_create_instance($instance_definition); // Check that criteria spanning over the field_config_instance table work. - $fields = field_read_fields(array('entity_type' => $instance_definition['entity_type'], 'bundle' => $instance_definition['bundle'])); + // @todo do we still want to support this ? + /*$fields = field_read_fields(array('entity_type' => $instance_definition['entity_type'], 'bundle' => $instance_definition['bundle'])); $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.'); $fields = field_read_fields(array('entity_type' => $instance_definition['entity_type'], 'field_name' => $instance_definition['field_name'])); - $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.'); + $this->assertTrue(count($fields) == 1 && isset($fields[$field_definition['field_name']]), 'The field was properly read.');*/ } /** @@ -239,7 +239,7 @@ function testFieldIndexes() { field_create_field($field_definition); $field = field_read_field($field_definition['field_name']); $expected_indexes = array('value' => array('value')); - $this->assertEqual($field['indexes'], $expected_indexes, 'Field type indexes saved by default'); + $this->assertEqual($field->indexes, $expected_indexes, 'Field type indexes saved by default'); // Check that indexes specified by the field definition override the field // type indexes. @@ -253,7 +253,7 @@ function testFieldIndexes() { field_create_field($field_definition); $field = field_read_field($field_definition['field_name']); $expected_indexes = array('value' => array()); - $this->assertEqual($field['indexes'], $expected_indexes, 'Field definition indexes override field type indexes'); + $this->assertEqual($field->indexes, $expected_indexes, 'Field definition indexes override field type indexes'); // Check that indexes specified by the field definition add to the field // type indexes. @@ -267,7 +267,7 @@ function testFieldIndexes() { field_create_field($field_definition); $field = field_read_field($field_definition['field_name']); $expected_indexes = array('value' => array('value'), 'value_2' => array('value')); - $this->assertEqual($field['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes'); + $this->assertEqual($field->indexes, $expected_indexes, 'Field definition indexes are merged with field type indexes'); } /** @@ -278,13 +278,13 @@ function testDeleteField() { // Create two fields (so we can test that only one is deleted). $this->field = array('field_name' => 'field_1', 'type' => 'test_field'); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->another_field = array('field_name' => 'field_2', 'type' => 'test_field'); - field_create_field($this->another_field); + $this->another_field = field_create_field($this->another_field); // Create instances for each. $this->instance_definition = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -293,18 +293,18 @@ function testDeleteField() { ); field_create_instance($this->instance_definition); $this->another_instance_definition = $this->instance_definition; - $this->another_instance_definition['field_name'] = $this->another_field['field_name']; + $this->another_instance_definition['field_name'] = $this->another_field->field_name; field_create_instance($this->another_instance_definition); // Test that the first field is not deleted, and then delete it. - $field = field_read_field($this->field['field_name'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field is not marked for deletion.'); - field_delete_field($this->field['field_name']); + $field = field_read_field($this->field->field_name, array('include_deleted' => TRUE)); + $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); + field_delete_field($this->field->field_name); // Make sure that the field is marked as deleted when it is specifically // loaded. - $field = field_read_field($this->field['field_name'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($field['deleted']), 'A deleted field is marked for deletion.'); + $deleted_fields = state()->get('field.field.deleted'); + $this->assertTrue(isset($deleted_fields[$field->id()]), 'A deleted field is marked for deletion.'); // Make sure that this field's instance is marked as deleted when it is // specifically loaded. @@ -312,7 +312,7 @@ function testDeleteField() { $this->assertTrue(!empty($instance['deleted']), 'An instance for a deleted field is marked for deletion.'); // Try to load the field normally and make sure it does not show up. - $field = field_read_field($this->field['field_name']); + $field = field_read_field($this->field->field_name); $this->assertTrue(empty($field), 'A deleted field is not loaded by default.'); // Try to load the instance normally and make sure it does not show up. @@ -320,8 +320,8 @@ function testDeleteField() { $this->assertTrue(empty($instance), 'An instance for a deleted field is not loaded by default.'); // Make sure the other field (and its field instance) are not deleted. - $another_field = field_read_field($this->another_field['field_name']); - $this->assertTrue(!empty($another_field) && empty($another_field['deleted']), 'A non-deleted field is not marked for deletion.'); + $another_field = field_read_field($this->another_field->field_name); + $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.'); $another_instance = field_read_instance('test_entity', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']); $this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), 'An instance of a non-deleted field is not marked for deletion.'); @@ -329,8 +329,8 @@ function testDeleteField() { // write data into it. field_create_field($this->field); field_create_instance($this->instance_definition); - $field = field_read_field($this->field['field_name']); - $this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field with a previously used name is created.'); + $field = field_read_field($this->field->field_name); + $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field with a previously used name is created.'); $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']); $this->assertTrue(!empty($instance) && empty($instance['deleted']), 'A new instance for a previously used field name is created.'); @@ -338,16 +338,16 @@ function testDeleteField() { $entity = field_test_create_entity(0, 0, $instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; $values[0]['value'] = mt_rand(1, 127); - $entity->{$field['field_name']}[$langcode] = $values; + $entity->{$field->field_name}[$langcode] = $values; $entity_type = 'test_entity'; field_attach_insert($entity); // Verify the field is present on load $entity = field_test_create_entity(0, 0, $this->instance_definition['bundle']); field_attach_load($entity_type, array(0 => $entity)); - $this->assertIdentical(count($entity->{$field['field_name']}[$langcode]), count($values), "Data in previously deleted field saves and loads correctly"); + $this->assertIdentical(count($entity->{$field->field_name}[$langcode]), count($values), "Data in previously deleted field saves and loads correctly"); foreach ($values as $delta => $value) { - $this->assertEqual($entity->{$field['field_name']}[$langcode][$delta]['value'], $values[$delta]['value'], "Data in previously deleted field saves and loads correctly"); + $this->assertEqual($entity->{$field->field_name}[$langcode][$delta]['value'], $values[$delta]['value'], "Data in previously deleted field saves and loads correctly"); } } @@ -389,7 +389,7 @@ function testUpdateField() { 'type' => 'test_field', 'cardinality' => $cardinality, ); - $field_definition = field_create_field($field_definition); + field_create_field($field_definition); $instance = array( 'field_name' => 'field_update', 'entity_type' => 'test_entity', @@ -427,7 +427,7 @@ function testUpdateField() { function testUpdateFieldForbid() { $field = array('field_name' => 'forbidden', 'type' => 'test_field', 'settings' => array('changeable' => 0, 'unchangeable' => 0)); $field = field_create_field($field); - $field['settings']['changeable']++; + $field->settings['changeable']++; try { field_update_field($field); $this->pass(t("A changeable setting can be updated.")); @@ -435,7 +435,7 @@ function testUpdateFieldForbid() { catch (FieldException $e) { $this->fail(t("An unchangeable setting cannot be updated.")); } - $field['settings']['unchangeable']++; + $field->settings['unchangeable']++; try { field_update_field($field); $this->fail(t("An unchangeable setting can be updated.")); @@ -505,6 +505,6 @@ function _testActiveHelper($field_definition, $modules) { // Check that the field is active again after all modules have been // enabled. $field = field_read_field($field_name); - $this->assertTrue($field_definition <= $field, 'The field was was marked active.'); + $this->assertTrue($field_definition <= $field, 'The field was marked active.'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php index bc1a380..8f237bb 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAccessTest.php @@ -37,13 +37,13 @@ function setUp() { $this->content_type_info = $this->drupalCreateContentType(); $this->content_type = $this->content_type_info->type; - $this->field = array( + $field = array( 'field_name' => 'test_view_field', 'type' => 'text', ); - field_create_field($this->field); + $this->field = field_create_field($field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'node', 'bundle' => $this->content_type, 'widget' => array( @@ -55,7 +55,7 @@ function setUp() { // Assign display properties for the 'default' and 'teaser' view modes. foreach (array('default', 'teaser') as $view_mode) { entity_get_display('node', $this->content_type, $view_mode) - ->setComponent($this->field['field_name']) + ->setComponent($this->field->field_name) ->save(); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 89e07c6..750dc63 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -33,9 +33,9 @@ function testFieldAttachView() { $options = array('field_name' => $this->field_name_2); // Populate values to be displayed. - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); $entity_init->{$this->field_name}[$langcode] = $values; - $values_2 = $this->_generateTestFieldValues($this->field_2['cardinality']); + $values_2 = $this->_generateTestFieldValues($this->field_2->cardinality); $entity_init->{$this->field_name_2}[$langcode] = $values_2; // Simple formatter, label displayed. @@ -51,7 +51,7 @@ function testFieldAttachView() { 'test_formatter_setting' => $formatter_setting, ), ); - $display->setComponent($this->field['field_name'], $display_options); + $display->setComponent($this->field->field_name, $display_options); $formatter_setting_2 = $this->randomName(); $display_options_2 = array( @@ -61,7 +61,7 @@ function testFieldAttachView() { 'test_formatter_setting' => $formatter_setting_2, ), ); - $display->setComponent($this->field_2['field_name'], $display_options_2); + $display->setComponent($this->field_2->field_name, $display_options_2); // View all fields. field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays); @@ -97,7 +97,7 @@ function testFieldAttachView() { // Label hidden. $entity = clone($entity_init); $display_options['label'] = 'hidden'; - $display->setComponent($this->field['field_name'], $display_options); + $display->setComponent($this->field->field_name, $display_options); field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays); $entity->content = field_attach_view($entity, $display); $output = drupal_render($entity->content); @@ -106,7 +106,7 @@ function testFieldAttachView() { // Field hidden. $entity = clone($entity_init); - $display->removeComponent($this->field['field_name']); + $display->removeComponent($this->field->field_name); field_attach_prepare_view($entity_type, array($entity->ftid => $entity), $displays); $entity->content = field_attach_view($entity, $display); $output = drupal_render($entity->content); @@ -119,7 +119,7 @@ function testFieldAttachView() { // Multiple formatter. $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field['field_name'], array( + $display->setComponent($this->field->field_name, array( 'label' => 'above', 'type' => 'field_test_multiple', 'settings' => array( @@ -139,7 +139,7 @@ function testFieldAttachView() { // Test a formatter that uses hook_field_formatter_prepare_view(). $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field['field_name'], array( + $display->setComponent($this->field->field_name, array( 'label' => 'above', 'type' => 'field_test_with_prepare_view', 'settings' => array( @@ -180,7 +180,7 @@ function testFieldAttachPrepareViewMultiple() { // Set the instance to be hidden. $display = entity_get_display('test_entity', 'test_bundle', 'full') - ->removeComponent($this->field['field_name']); + ->removeComponent($this->field->field_name); // Set up a second instance on another bundle, with a formatter that uses // hook_field_formatter_prepare_view(). @@ -191,7 +191,7 @@ function testFieldAttachPrepareViewMultiple() { field_create_instance($this->instance2); $display_2 = entity_get_display('test_entity', 'test_bundle_2', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->field_name, array( 'type' => 'field_test_with_prepare_view', 'settings' => array( 'test_formatter_setting_additional' => $formatter_setting, @@ -202,11 +202,11 @@ function testFieldAttachPrepareViewMultiple() { // Create one entity in each bundle. $entity1_init = field_test_create_entity(1, 1, 'test_bundle'); - $values1 = $this->_generateTestFieldValues($this->field['cardinality']); + $values1 = $this->_generateTestFieldValues($this->field->cardinality); $entity1_init->{$this->field_name}[$langcode] = $values1; $entity2_init = field_test_create_entity(2, 2, 'test_bundle_2'); - $values2 = $this->_generateTestFieldValues($this->field['cardinality']); + $values2 = $this->_generateTestFieldValues($this->field->cardinality); $entity2_init->{$this->field_name}[$langcode] = $values2; // Run prepare_view, and check that the entities come out as expected. @@ -233,7 +233,7 @@ function testFieldAttachCache() { // Initialize random values and a test entity. $entity_init = field_test_create_entity(1, 1, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); // Non-cacheable entity type. $entity_type = 'test_entity'; @@ -288,7 +288,7 @@ function testFieldAttachCache() { $this->assertEqual($cache->data[$this->field_name][$langcode], $values, 'Cached: correct cache entry on load'); // Update with different values, and check that the cache entry is wiped. - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); $entity = clone($entity_init); $entity->{$this->field_name}[$langcode] = $values; field_attach_update($entity); @@ -306,7 +306,7 @@ function testFieldAttachCache() { 'ftvid' => 2, 'fttype' => $this->instance['bundle'], )); - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); $entity = clone($entity_init); $entity->{$this->field_name}[$langcode] = $values; field_attach_update($entity); @@ -339,7 +339,7 @@ function testFieldAttachValidate() { // Set up all but one values of the first field to generate errors. $values = array(); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { $values[$delta]['value'] = -1; } // Arrange for item 1 not to generate an error. @@ -348,7 +348,7 @@ function testFieldAttachValidate() { // Set up all values of the second field to generate errors. $values_2 = array(); - for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field_2->cardinality; $delta++) { $values_2[$delta]['value'] = -1; } $entity->{$this->field_name_2}[$langcode] = $values_2; @@ -397,7 +397,7 @@ function testFieldAttachValidate() { $this->assertEqual(count($errors[$this->field_name_2][$langcode]), 0, 'No extraneous errors set for second field'); // Check that cardinality is validated. - $entity->{$this->field_name_2}[$langcode] = $this->_generateTestFieldValues($this->field_2['cardinality'] + 1); + $entity->{$this->field_name_2}[$langcode] = $this->_generateTestFieldValues($this->field_2->cardinality + 1); // When validating all fields. try { field_attach_validate($entity); @@ -436,11 +436,11 @@ function testFieldAttachForm() { $this->assertEqual($form[$this->field_name][$langcode]['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}"); $this->assertEqual($form[$this->field_name_2][$langcode]['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name][$langcode][$delta]['value']['#type'], 'textfield', "First field's form delta $delta widget is textfield"); } - for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field_2->cardinality; $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name_2][$langcode][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } @@ -453,7 +453,7 @@ function testFieldAttachForm() { $this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form'); $this->assertEqual($form[$this->field_name_2][$langcode]['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); - for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field_2->cardinality; $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name_2][$langcode][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } @@ -478,11 +478,11 @@ function testFieldAttachExtractFormValues() { // First field. $values = array(); $weights = array(); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); // Assign random weight. do { - $weight = mt_rand(0, $this->field['cardinality']); + $weight = mt_rand(0, $this->field->cardinality); } while (in_array($weight, $weights)); $weights[$delta] = $weight; $values[$delta]['_weight'] = $weight; @@ -492,11 +492,11 @@ function testFieldAttachExtractFormValues() { // Second field. $values_2 = array(); $weights_2 = array(); - for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field_2->cardinality; $delta++) { $values_2[$delta]['value'] = mt_rand(1, 127); // Assign random weight. do { - $weight = mt_rand(0, $this->field_2['cardinality']); + $weight = mt_rand(0, $this->field_2->cardinality); } while (in_array($weight, $weights_2)); $weights_2[$delta] = $weight; $values_2[$delta]['_weight'] = $weight; diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index 5ae3610..6546c10 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -44,7 +44,7 @@ function testFieldAttachSaveLoad() { for ($revision_id = 0; $revision_id < 3; $revision_id++) { $revision[$revision_id] = field_test_create_entity(0, $revision_id, $this->instance['bundle']); // Note: we try to insert one extra value. - $values[$revision_id] = $this->_generateTestFieldValues($this->field['cardinality'] + 1); + $values[$revision_id] = $this->_generateTestFieldValues($this->field->cardinality + 1); $current_revision = $revision_id; // If this is the first revision do an insert. if (!$revision_id) { @@ -62,8 +62,8 @@ function testFieldAttachSaveLoad() { $entity = field_test_create_entity(0, 0, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $entity)); // Number of values per field loaded equals the field cardinality. - $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], 'Current revision: expected number of values'); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field->cardinality, 'Current revision: expected number of values'); + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { // The field value loaded matches the one inserted or updated. $this->assertEqual($entity->{$this->field_name}[$langcode][$delta]['value'] , $values[$current_revision][$delta]['value'], format_string('Current revision: expected value %delta was found.', array('%delta' => $delta))); // The value added in hook_field_load() is found. @@ -75,8 +75,8 @@ function testFieldAttachSaveLoad() { $entity = field_test_create_entity(0, $revision_id, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $entity)); // Number of values per field loaded equals the field cardinality. - $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id))); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field->cardinality, format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id))); + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { // The field value loaded matches the one inserted or updated. $this->assertEqual($entity->{$this->field_name}[$langcode][$delta]['value'], $values[$revision_id][$delta]['value'], format_string('Revision %revision_id: expected value %delta was found.', array('%revision_id' => $revision_id, '%delta' => $delta))); // The value added in hook_field_load() is found. @@ -112,7 +112,7 @@ function testFieldAttachLoadMultiple() { $field_names[$i] = 'field_' . $i; $field = array('field_name' => $field_names[$i], 'type' => 'test_field'); $field = field_create_field($field); - $field_ids[$i] = $field['id']; + $field_ids[$i] = $field->id(); foreach ($field_bundles_map[$i] as $bundle) { $instance = array( 'field_name' => $field_names[$i], @@ -199,7 +199,7 @@ function testFieldAttachSaveLoadDifferentStorage() { $entity = clone($entity_init); $values = array(); foreach ($fields as $field) { - $values[$field['field_name']] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$field['field_name']] = $this->_generateTestFieldValues($this->field->cardinality); $entity->{$field['field_name']}[$langcode] = $values[$field['field_name']]; } field_attach_insert($entity); @@ -237,9 +237,9 @@ function testFieldStorageDetailsAlter() { $instance = field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle']); // The storage details are indexed by a storage engine type. - $this->assertTrue(array_key_exists('drupal_variables', $field['storage']['details']), 'The storage type is Drupal variables.'); + $this->assertTrue(array_key_exists('drupal_variables', $field->storage['details']), 'The storage type is Drupal variables.'); - $details = $field['storage']['details']['drupal_variables']; + $details = $field->storage['details']['drupal_variables']; // The field_test storage details are indexed by variable name. The details // are altered, so moon and mars are correct for this test. @@ -248,7 +248,7 @@ function testFieldStorageDetailsAlter() { // Test current and revision storage details together because the columns // are the same. - foreach ((array) $field['columns'] as $column_name => $attributes) { + foreach ($field->columns as $column_name => $attributes) { $this->assertEqual($details[FIELD_LOAD_CURRENT]['moon'][$column_name], $column_name, format_string('Column name %value matches the definition in %bin.', array('%value' => $column_name, '%bin' => 'moon[FIELD_LOAD_CURRENT]'))); $this->assertEqual($details[FIELD_LOAD_REVISION]['mars'][$column_name], $column_name, format_string('Column name %value matches the definition in %bin.', array('%value' => $column_name, '%bin' => 'mars[FIELD_LOAD_REVISION]'))); } @@ -382,7 +382,7 @@ function testFieldAttachDelete() { $rev[0] = field_test_create_entity(0, 0, $this->instance['bundle']); // Create revision 0 - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); $rev[0]->{$this->field_name}[$langcode] = $values; field_attach_insert($rev[0]); @@ -400,7 +400,7 @@ function testFieldAttachDelete() { foreach (array_keys($rev) as $vid) { $read = field_test_create_entity(0, $vid, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $read)); - $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); + $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field->cardinality, "The test entity revision $vid has {$this->field->cardinality} values."); } // Delete revision 1, confirm the other two still load. @@ -408,13 +408,13 @@ function testFieldAttachDelete() { foreach (array(0, 2) as $vid) { $read = field_test_create_entity(0, $vid, $this->instance['bundle']); field_attach_load_revision($entity_type, array(0 => $read)); - $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); + $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field->cardinality, "The test entity revision $vid has {$this->field->cardinality} values."); } // Confirm the current revision still loads $read = field_test_create_entity(0, 2, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $read)); - $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field['cardinality'], "The test entity current revision has {$this->field['cardinality']} values."); + $this->assertEqual(count($read->{$this->field_name}[$langcode]), $this->field->cardinality, "The test entity current revision has {$this->field->cardinality} values."); // Delete all field data, confirm nothing loads field_attach_delete($rev[2]); @@ -443,7 +443,7 @@ function testFieldAttachCreateRenameBundle() { // Save an entity with data in the field. $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); $entity->{$this->field_name}[$langcode] = $values; $entity_type = 'test_entity'; field_attach_insert($entity); @@ -451,7 +451,7 @@ function testFieldAttachCreateRenameBundle() { // Verify the field data is present on load. $entity = field_test_create_entity(0, 0, $this->instance['bundle']); field_attach_load($entity_type, array(0 => $entity)); - $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Data is retrieved for the new bundle"); + $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field->cardinality, "Data is retrieved for the new bundle"); // Rename the bundle. $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); @@ -464,7 +464,7 @@ function testFieldAttachCreateRenameBundle() { // Verify the field data is present on load. $entity = field_test_create_entity(0, 0, $new_bundle); field_attach_load($entity_type, array(0 => $entity)); - $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field['cardinality'], "Bundle name has been updated in the field storage"); + $this->assertEqual(count($entity->{$this->field_name}[$langcode]), $this->field->cardinality, "Bundle name has been updated in the field storage"); } /** @@ -500,7 +500,7 @@ function testFieldAttachDeleteBundle() { // Save an entity with data for both fields $entity = field_test_create_entity(0, 0, $this->instance['bundle']); $langcode = LANGUAGE_NOT_SPECIFIED; - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->cardinality); $entity->{$this->field_name}[$langcode] = $values; $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues(1); field_attach_insert($entity); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php index 9d15ba2..53bf543 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachTestBase.php @@ -38,7 +38,7 @@ function createFieldWithInstance($suffix = '') { $this->$field_name = drupal_strtolower($this->randomName() . '_field_name' . $suffix); $this->$field = array('field_name' => $this->$field_name, 'type' => 'test_field', 'cardinality' => 4); $this->$field = field_create_field($this->$field); - $this->$field_id = $this->{$field}['id']; + $this->$field_id = $this->{$field}->uuid; $this->$instance = array( 'field_name' => $this->$field_name, 'entity_type' => 'test_entity', diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php new file mode 100644 index 0000000..67657da --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php @@ -0,0 +1,69 @@ + 'Field config change tests', + 'description' => 'Update field and instances during config change method invocation.', + 'group' => 'Field API', + ); + } + + function setUp() { + parent::setUp(); + + $this->instance_manifest = 'manifest.field.instance'; + $this->instance_name = 'field.instance.node.test_import.field_test_import'; + $this->drupalCreateContentType(array('type' => 'test_import', 'name' => 'Test import')); + + $admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access')); + $this->drupalLogin($admin_user); + } + + /** + * Test importing changes. + */ + function testImportChange() { + + // Assert default test import. + $this->drupalGet('node/add/test_import'); + $this->assertRaw('Test import field'); + + // Change label. + $active = $this->container->get('config.storage'); + $staging = $this->container->get('config.storage.staging'); + $manifest = $active->read($this->instance_manifest); + $instance = $active->read($this->instance_name); + $instance['data']['label'] = 'Test update import field'; + $staging->write($this->instance_name, $instance); + $staging->write($this->instance_manifest, $manifest); + + // Import. + config_import(); + + // Assert updated label. + $this->drupalGet('node/add/test_import'); + $this->assertText('Test update import field'); + } +} diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php new file mode 100644 index 0000000..6bda93f --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php @@ -0,0 +1,87 @@ + 'Field config create tests', + 'description' => 'Create field and instances during config create method invocation.', + 'group' => 'Field API', + ); + } + + function setUp() { + parent::setUp(); + + $this->field_test_import_staging = 'field.field.field_test_import_staging'; + $this->instance_test_import_staging = 'field.instance.node.test_import.field_test_import_staging'; + $this->field_manifest = 'manifest.field.field'; + $this->instance_manifest = 'manifest.field.instance'; + $this->drupalCreateContentType(array('type' => 'test_import', 'name' => 'Test import')); + + $admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access')); + $this->drupalLogin($admin_user); + } + + /** + * Test importing new fields. + */ + function testImportCreate() { + + // Assert default test import. + $this->drupalGet('node/add/test_import'); + $this->assertNoText('Test import field'); + + // Enable field_test_config module and assert the test import + // field and instance is available on the Test content type. + // This tests creating fields and instances that are provided + // by a module. + module_enable(array('field_test_config')); + $this->drupalGet('node/add/test_import'); + $this->assertText('Test import field'); + $module_path = drupal_get_path('module', 'field_test_config'); + + // Copy another field and instance to the staging directory + // on the Test content type and run config_import() to test + // importing from the staging directory. + $active = $this->container->get('config.storage'); + $staging = $this->container->get('config.storage.staging'); + $field_manifest = $active->read($this->field_manifest); + $instance_manifest = $active->read($this->instance_manifest); + + // Copy the files. + $copied = file_unmanaged_copy($module_path .'/staging/' . $this->field_test_import_staging . '.yml', 'public://config_staging/' . $this->field_test_import_staging . '.yml'); + $this->assertTrue($copied); + $copied = file_unmanaged_copy($module_path .'/staging/' . $this->instance_test_import_staging . '.yml', 'public://config_staging/' . $this->instance_test_import_staging . '.yml'); + $this->assertTrue($copied); + + // Add to manifest. + $field_manifest['field_test_import_staging'] = array('name' => $this->field_test_import_staging); + $instance_manifest['node.test_import.field_test_import_staging'] = array('name' => $this->instance_test_import_staging); + + // Write to manifest and new config. + $staging->write($this->field_manifest, $field_manifest); + $staging->write($this->instance_manifest, $instance_manifest); + + // Import. + config_import(); + + // Assert the staging field is there. + $this->drupalGet('node/add/test_import'); + $this->assertText('Import from staging'); + } +} diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php new file mode 100644 index 0000000..f6d548f --- /dev/null +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportDeleteTest.php @@ -0,0 +1,100 @@ + 'Field config delete tests', + 'description' => 'Delete field and instances during config delete method invocation.', + 'group' => 'Field API', + ); + } + + function setUp() { + parent::setUp(); + + $this->body_field_name = 'field.field.body'; + $this->test_import_field_name = 'field.field.test_import'; + $this->body_instance_name = 'field.instance.node.test_import.body'; + $this->test_import_instance_name = 'field.instance.node.test_import.field_test_import'; + $this->field_manifest = 'manifest.field.field'; + $this->instance_manifest = 'manifest.field.instance'; + $this->drupalCreateContentType(array('type' => 'test_import', 'name' => 'Test import')); + + $admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access')); + $this->drupalLogin($admin_user); + } + + /** + * Test importing deletions. + */ + function testImportDelete() { + + $body_field = field_info_field('body'); + $field_test_import = field_info_field('field_test_import'); + + // Assert default test import. + $this->drupalGet('node/add/test_import'); + $this->assertRaw('Test import field'); + $this->assertRaw('Body'); + + // Delete body field and instance, the test import instance + // from the manifest. + $active = $this->container->get('config.storage'); + $staging = $this->container->get('config.storage.staging'); + $field_manifest = $active->read($this->field_manifest); + $instance_manifest = $active->read($this->instance_manifest); + unset($field_manifest['body']); + unset($instance_manifest['node.test_import.body']); + unset($instance_manifest['node.test_import.field_test_import']); + $staging->write($this->field_manifest, $field_manifest); + $staging->write($this->instance_manifest, $instance_manifest); + + // Import. + config_import(); + + // Assert the field and instance are gone from the form. + $this->drupalGet('node/add/test_import'); + $this->assertNoText('Test import field'); + $this->assertNoText('Body'); + + // Check that body and import field are in state of deleted fields. + $deleted_fields = state()->get('field.field.deleted') ?: array(); + $this->assertTrue(isset($deleted_fields[$body_field->id()])); + $this->assertTrue(isset($deleted_fields[$field_test_import->uuid])); + + // Run purge_batch(). + field_purge_batch(10); + + // Check that the deleted fields are removed from state. + $deleted_fields = state()->get('field.field.deleted') ?: array(); + $this->assertTrue(empty($deleted_fields), 'Fields are deleted'); + + // Check all config files are gone. + $active = $this->container->get('config.storage'); + $this->assertIdentical($active->listAll($this->body_field_name), array()); + $this->assertIdentical($active->listAll($this->test_import_field_name), array()); + $this->assertIdentical($active->listAll($this->body_instance_name), array()); + $this->assertIdentical($active->listAll($this->test_import_instance_name), array()); + } +} diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index 3115851..e001f40 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -65,22 +65,22 @@ function testFieldInfo() { 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', ); - field_create_field($field); + $field = field_create_field($field); $fields = field_info_fields(); $this->assertEqual(count($fields), count($core_fields) + 1, 'One new field exists'); - $this->assertEqual($fields[$field['field_name']]['field_name'], $field['field_name'], 'info fields contains field name'); - $this->assertEqual($fields[$field['field_name']]['type'], $field['type'], 'info fields contains field type'); - $this->assertEqual($fields[$field['field_name']]['module'], 'field_test', 'info fields contains field module'); + $this->assertEqual($fields[$field->field_name]->field_name, $field->field_name, 'info fields contains field name'); + $this->assertEqual($fields[$field->field_name]->type, $field->type, 'info fields contains field type'); + $this->assertEqual($fields[$field->field_name]->module, 'field_test', 'info fields contains field module'); $settings = array('test_field_setting' => 'dummy test string'); foreach ($settings as $key => $val) { - $this->assertEqual($fields[$field['field_name']]['settings'][$key], $val, format_string('Field setting %key has correct default value %value', array('%key' => $key, '%value' => $val))); + $this->assertEqual($fields[$field->field_name]->settings[$key], $val, format_string('Field setting %key has correct default value %value', array('%key' => $key, '%value' => $val))); } - $this->assertEqual($fields[$field['field_name']]['cardinality'], 1, 'info fields contains cardinality 1'); - $this->assertEqual($fields[$field['field_name']]['active'], 1, 'info fields contains active 1'); + $this->assertEqual($fields[$field->field_name]->cardinality, 1, 'info fields contains cardinality 1'); + $this->assertEqual($fields[$field->field_name]->active, 1, 'info fields contains active 1'); // Create an instance, verify that it shows up $instance = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'label' => $this->randomName(), @@ -143,13 +143,9 @@ function testFieldPrepare() { // Simulate a stored field definition missing a field setting (e.g. a // third-party module adding a new field setting has been enabled, and // existing fields do not know the setting yet). - $data = db_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']))->fetchField(); - $data = unserialize($data); - $data['settings'] = array(); - db_update('field_config') - ->fields(array('data' => serialize($data))) - ->condition('field_name', $field_definition['field_name']) - ->execute(); + $field = entity_load('field_entity', $field_definition['field_name']); + $field->settings = array(); + field_update_field($field); field_cache_clear(); @@ -158,7 +154,7 @@ function testFieldPrepare() { // Check that all expected settings are in place. $field_type = field_info_field_types($field_definition['type']); - $this->assertIdentical($field['settings'], $field_type['settings'], 'All expected default field settings are present.'); + $this->assertEqual($field->settings, $field_type['settings'], 'All expected default field settings are present.'); } /** @@ -180,25 +176,19 @@ function testInstancePrepare() { // Simulate a stored instance definition missing various settings (e.g. a // third-party module adding instance or widget settings has been enabled, // but existing instances do not know the new settings). - $data = db_query('SELECT data FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $instance_definition['field_name'], ':bundle' => $instance_definition['bundle']))->fetchField(); - $data = unserialize($data); - $data['settings'] = array(); - $data['widget']['settings'] = 'unavailable_widget'; - $data['widget']['settings'] = array(); - db_update('field_config_instance') - ->fields(array('data' => serialize($data))) - ->condition('field_name', $instance_definition['field_name']) - ->condition('bundle', $instance_definition['bundle']) - ->execute(); - - field_cache_clear(); + $entity_instance = entity_load('field_instance', $instance_definition['entity_type'] . '.' . $instance_definition['bundle'] . '.' . $instance_definition['field_name']); + $instance = $entity_instance->data; + $instance['settings'] = array(); + $instance['widget']['settings'] = 'unavailable_widget'; + $instance['widget']['settings'] = array(); + field_update_instance($instance); // Read the instance back. $instance = field_info_instance($instance_definition['entity_type'], $instance_definition['field_name'], $instance_definition['bundle']); // Check that all expected instance settings are in place. $field_type = field_info_field_types($field_definition['type']); - $this->assertIdentical($instance['settings'], $field_type['instance_settings'] , 'All expected instance settings are present.'); + $this->assertEqual($instance['settings'], $field_type['instance_settings'] , 'All expected instance settings are present.'); // Check that the default widget is used and expected settings are in place. $widget = $instance->getWidget(); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 90fcc05..3a662a2 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -8,6 +8,7 @@ namespace Drupal\field\Tests; use Drupal\field\FieldException; +use Drupal\field\FieldInstance; class FieldInstanceCrudTest extends FieldTestBase { @@ -35,9 +36,9 @@ function setUp() { 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance_definition = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', ); @@ -55,26 +56,25 @@ function setUp() { function testCreateFieldInstance() { field_create_instance($this->instance_definition); - // Read the raw record from the {field_config_instance} table. - $result = db_query('SELECT * FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $this->instance_definition['field_name'], ':bundle' => $this->instance_definition['bundle'])); - $record = $result->fetchAssoc(); - $record['data'] = unserialize($record['data']); + // Read the configuration. + $e_record = entity_load('field_instance', $this->instance_definition['entity_type'] . '.' . $this->instance_definition['bundle'] . '.' . $this->instance_definition['field_name']); + $record = $e_record->data; - $field_type = field_info_field_types($this->field['type']); + $field_type = field_info_field_types($this->field->type); $widget_type = field_info_widget_types($field_type['default_widget']); // 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, 'Required defaults to false.'); - $this->assertIdentical($record['data']['label'], $this->instance_definition['field_name'], 'Label defaults to field name.'); - $this->assertIdentical($record['data']['description'], '', 'Description defaults to empty string.'); - $this->assertIdentical($record['data']['widget']['type'], $field_type['default_widget'], 'Default widget has been written.'); + $this->assertEqual($record['required'], FALSE, 'Required defaults to false.'); + $this->assertIdentical($record['label'], $this->instance_definition['field_name'], 'Label defaults to field name.'); + $this->assertIdentical($record['description'], '', 'Description defaults to empty string.'); + $this->assertIdentical($record['widget']['type'], $field_type['default_widget'], 'Default widget has been written.'); // Check that default settings are set. - $this->assertIdentical($record['data']['settings'], $field_type['instance_settings'] , 'Default instance settings have been written.'); - $this->assertIdentical($record['data']['widget']['settings'], $widget_type['settings'] , 'Default widget settings have been written.'); + $this->assertEqual($record['settings'], $field_type['instance_settings'] , 'Default instance settings have been written.'); + $this->assertIdentical($record['widget']['settings'], $widget_type['settings'] , 'Default widget settings have been written.'); // Guarantee that the field/bundle combination is unique. try { @@ -139,7 +139,13 @@ 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, 'The field was properly read.'); + $this->assertTrue($this->instance_definition['id'] == $instance['id'], 'The field was properly read.'); + $this->assertTrue($this->instance_definition['label'] == $instance['label'], 'The field was properly read.'); + $this->assertTrue($this->instance_definition['field_id'] == $instance['field_id'], 'The field was properly read.'); + $this->assertTrue($this->instance_definition['entity_type'] == $instance['entity_type'], 'The field was properly read.'); + $this->assertTrue($this->instance_definition['bundle'] == $instance['bundle'], 'The field was properly read.'); + $this->assertTrue($this->instance_definition['settings'] == $instance['settings'], 'The field was properly read.'); + $this->assertTrue($this->instance_definition['widget'] == $instance['widget'], 'The field was properly read.'); } /** @@ -213,7 +219,9 @@ function testDeleteFieldInstance() { // Make sure the field is deleted when its last instance is deleted. field_delete_instance($another_instance); - $field = field_read_field($another_instance['field_name'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($field['deleted']), 'A deleted field is marked for deletion after all its instances have been marked for deletion.'); + $deleted_fields = state()->get('field.field.deleted'); + $this->assertTrue(isset($deleted_fields[$another_instance['field_id']]), 'A deleted field is marked for deletion.'); + $field = field_read_field(array('field_name' => $another_instance['field_name'])); + $this->assertFalse($field, 'The field marked to be deleted is not found anymore in the configuration.'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldItemUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldItemUnitTestBase.php index e201fb5..dd9b6a8 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldItemUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldItemUnitTestBase.php @@ -24,8 +24,6 @@ class FieldItemUnitTestBase extends DrupalUnitTestBase { public function setUp() { parent::setUp(); $this->installSchema('system', 'sequences'); - $this->installSchema('field', 'field_config'); - $this->installSchema('field', 'field_config_instance'); $this->installSchema('entity_test', 'entity_test'); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index 2f5dbee..cc476dc 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -57,7 +57,7 @@ function testFieldFormSingle() { $this->field = $this->field_single; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -123,7 +123,7 @@ function testFieldFormDefaultValue() { $this->instance['field_name'] = $this->field_name; $default = rand(1, 127); $this->instance['default_value'] = array(array('value' => $default)); - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -147,7 +147,7 @@ function testFieldFormSingleRequired() { $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; $this->instance['required'] = TRUE; - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -175,7 +175,7 @@ function testFieldFormSingleRequired() { // function testFieldFormMultiple() { // $this->field = $this->field_multiple; -// $this->field_name = $this->field['field_name']; +// $this->field_name = $this->field->field_name; // $this->instance['field_name'] = $this->field_name; // field_create_field($this->field); // field_create_instance($this->instance); @@ -185,7 +185,7 @@ function testFieldFormUnlimited() { $this->field = $this->field_unlimited; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -265,7 +265,7 @@ function testFieldFormMultivalueWithRequiredRadio() { $this->field = $this->field_unlimited; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -307,7 +307,7 @@ function testFieldFormJSAddMore() { $this->field = $this->field_unlimited; $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -367,7 +367,7 @@ function testFieldFormMultipleWidget() { $this->field_name = $this->field['field_name']; $this->instance['field_name'] = $this->field_name; $this->instance['widget']['type'] = 'test_field_widget_multiple'; - field_create_field($this->field); + $this->field = field_create_field($this->field); field_create_instance($this->instance); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -406,7 +406,7 @@ function testFieldFormAccess() { $field_name = $field['field_name']; $instance = $this->instance; $instance['field_name'] = $field_name; - field_create_field($field); + $this->field = field_create_field($field); field_create_instance($instance); // Create a field with no edit access - see field_test_field_access(). diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index f2ada97..751da58 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -47,6 +47,7 @@ function setUp() { ); field_create_field($field); $this->field = field_read_field($this->field_name); + $this->field_definition = $field; $instance = array( 'field_name' => $this->field_name, @@ -71,8 +72,8 @@ function setUp() { function testFieldAvailableLanguages() { // Test 'translatable' fieldable info. field_test_entity_info_translatable('test_entity', FALSE); - $field = $this->field; - $field['field_name'] .= '_untranslatable'; + $field = clone($this->field); + $field->field_name .= '_untranslatable'; // Enable field translations for the entity. field_test_entity_info_translatable('test_entity', TRUE); @@ -90,7 +91,7 @@ function testFieldAvailableLanguages() { $this->assertFalse(in_array('en', $available_langcodes), format_string('%language was made unavailable.', array('%language' => 'en'))); // Test field_available_languages() behavior for untranslatable fields. - $this->field['translatable'] = FALSE; + $this->field->translatable = FALSE; field_update_field($this->field); $available_langcodes = field_available_languages($this->entity_type, $this->field); $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === LANGUAGE_NOT_SPECIFIED, 'For untranslatable fields only LANGUAGE_NOT_SPECIFIED is available.'); @@ -117,7 +118,7 @@ function testFieldInvoke() { // For each given language provide some random values. foreach ($langcodes as $langcode) { - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { $values[$langcode][$delta]['value'] = mt_rand(1, 127); } } @@ -167,7 +168,7 @@ function testFieldInvokeMultiple() { // per-entity language suggestions work even when available field values // are different for each language. if ($i !== $id) { - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field->cardinality; $delta++) { $values[$id][$langcode][$delta]['value'] = mt_rand(1, 127); } } @@ -225,7 +226,7 @@ function testTranslatableFieldSaveLoad() { $available_langcodes = field_available_languages($entity_type, $this->field); $this->assertTrue(count($available_langcodes) > 1, 'Field is translatable.'); foreach ($available_langcodes as $langcode) { - $field_translations[$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $field_translations[$langcode] = $this->_generateTestFieldValues($this->field->cardinality); } // Save and reload the field translations. @@ -245,7 +246,7 @@ function testTranslatableFieldSaveLoad() { // Test default values. $field_name_default = drupal_strtolower($this->randomName() . '_field_name'); - $field = $this->field; + $field = $this->field_definition; $field['field_name'] = $field_name_default; $instance = $this->instance; $instance['field_name'] = $field_name_default; @@ -261,7 +262,7 @@ function testTranslatableFieldSaveLoad() { $evid++; $values = array('eid' => $eid, 'evid' => $evid, 'fttype' => $instance['bundle'], 'langcode' => $translation_langcodes[0]); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field->cardinality); } $entity = entity_create($entity_type, $values); @@ -279,7 +280,7 @@ function testTranslatableFieldSaveLoad() { $evid++; $values = array('eid' => $eid, 'evid' => $evid, 'fttype' => $instance['bundle'], 'langcode' => $translation_langcodes[0]); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field->cardinality); $values[$field_name_default][$langcode] = $empty_items; } $entity = entity_create($entity_type, $values); @@ -335,7 +336,7 @@ function testFieldDisplayLanguage() { } while (isset($langcodes[$langcode])); $langcodes[$langcode] = TRUE; - $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues($field['cardinality']); + $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues($field->cardinality); // If the langcode is one of the locked languages, then that one // will also be used for display. Otherwise, the default one should be // used, which is LANGUAGE_NOT_SPECIFIED. @@ -396,7 +397,7 @@ function testFieldFormTranslationRevisions() { $entity = field_test_create_entity($eid, $eid, $this->instance['bundle']); $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field)); unset($available_langcodes[LANGUAGE_NOT_SPECIFIED]); - $field_name = $this->field['field_name']; + $field_name = $this->field->field_name; // Store the field translations. $entity->enforceIsNew(); @@ -420,7 +421,7 @@ function testFieldFormTranslationRevisions() { * by the passed arguments were correctly stored. */ private function checkTranslationRevisions($eid, $evid, $available_langcodes) { - $field_name = $this->field['field_name']; + $field_name = $this->field->field_name; $entity = field_test_entity_test_load($eid, $evid); foreach ($available_langcodes as $langcode => $value) { $passed = isset($entity->{$field_name}[$langcode]) && $entity->{$field_name}[$langcode][0]['value'] == $value + 1; diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php index c0f500b..5e3bf52 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php @@ -66,7 +66,7 @@ function setUpFields($amount = 3) { function setUpInstances($bundle = 'page') { foreach ($this->fields as $key => $field) { $instance = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => 'node', 'bundle' => 'page', ); diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php index 27504eb..afd2e26 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -59,13 +59,13 @@ protected function setUp() { for ($key = 0; $key < 3; $key++) { $field = $this->fields[$key]; - $edit[$field['field_name']][LANGUAGE_NOT_SPECIFIED][0]['value'] = $this->randomName(8); + $edit[$field->field_name][LANGUAGE_NOT_SPECIFIED][0]['value'] = $this->randomName(8); } for ($j = 0; $j < 5; $j++) { - $edit[$this->fields[3]['field_name']][LANGUAGE_NOT_SPECIFIED][$j]['value'] = $this->randomName(8); + $edit[$this->fields[3]->field_name][LANGUAGE_NOT_SPECIFIED][$j]['value'] = $this->randomName(8); } // Set this field to be empty. - $edit[$this->fields[4]['field_name']] = array(LANGUAGE_NOT_SPECIFIED => array(0 => array('value' => NULL))); + $edit[$this->fields[4]->field_name] = array(LANGUAGE_NOT_SPECIFIED => array(0 => array('value' => NULL))); $this->nodes[$i] = $this->drupalCreateNode($edit); } @@ -80,9 +80,9 @@ protected function setUp() { protected function prepareView(ViewExecutable $view) { $view->initDisplay(); foreach ($this->fields as $key => $field) { - $view->display_handler->options['fields'][$field['field_name']]['id'] = $field['field_name']; - $view->display_handler->options['fields'][$field['field_name']]['table'] = 'field_data_' . $field['field_name']; - $view->display_handler->options['fields'][$field['field_name']]['field'] = $field['field_name']; + $view->display_handler->options['fields'][$field->field_name]['id'] = $field->field_name; + $view->display_handler->options['fields'][$field->field_name]['table'] = 'field_data_' . $field->field_name; + $view->display_handler->options['fields'][$field->field_name]['field'] = $field->field_name; } } @@ -101,8 +101,8 @@ public function _testSimpleFieldRender() { for ($i = 0; $i < 3; $i++) { for ($key = 0; $key < 2; $key++) { $field = $this->fields[$key]; - $rendered_field = $view->style_plugin->get_field($i, $field['field_name']); - $expected_field = $this->nodes[$i]->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED][0]['value']; + $rendered_field = $view->style_plugin->get_field($i, $field->field_name); + $expected_field = $this->nodes[$i]->{$field->field_name}[LANGUAGE_NOT_SPECIFIED][0]['value']; $this->assertEqual($rendered_field, $expected_field); } } @@ -114,8 +114,8 @@ public function _testSimpleFieldRender() { public function _testFormatterSimpleFieldRender() { $view = views_get_view('test_view_fieldapi'); $this->prepareView($view); - $view->displayHandlers->get('default')->options['fields'][$this->fields[0]['field_name']]['type'] = 'text_trimmed'; - $view->displayHandlers->get('default')->options['fields'][$this->fields[0]['field_name']]['settings'] = array( + $view->displayHandlers->get('default')->options['fields'][$this->fields[0]->field_name]['type'] = 'text_trimmed'; + $view->displayHandlers->get('default')->options['fields'][$this->fields[0]->field_name]['settings'] = array( 'trim_length' => 3, ); $this->executeView($view); @@ -123,14 +123,14 @@ public function _testFormatterSimpleFieldRender() { // Take sure that the formatter works as expected. // @TODO: actually there should be a specific formatter. for ($i = 0; $i < 2; $i++) { - $rendered_field = $view->style_plugin->get_field($i, $this->fields[0]['field_name']); + $rendered_field = $view->style_plugin->get_field($i, $this->fields[0]->field_name); $this->assertEqual(strlen($rendered_field), 3); } } public function _testMultipleFieldRender() { $view = views_get_view('test_view_fieldapi'); - $field_name = $this->fields[3]['field_name']; + $field_name = $this->fields[3]->field_name; // Test delta limit. $this->prepareView($view); @@ -150,7 +150,7 @@ public function _testMultipleFieldRender() { } // Test that an empty field is rendered without error. - $rendered_field = $view->style_plugin->get_field(4, $this->fields[4]['field_name']); + $rendered_field = $view->style_plugin->get_field(4, $this->fields[4]->field_name); $view->destroy(); diff --git a/core/modules/field/tests/modules/field_test/field_test.field.inc b/core/modules/field/tests/modules/field_test/field_test.field.inc index 7166f4b..acf7043 100644 --- a/core/modules/field/tests/modules/field_test/field_test.field.inc +++ b/core/modules/field/tests/modules/field_test/field_test.field.inc @@ -62,7 +62,7 @@ function field_test_field_widget_info_alter(&$info) { * Implements hook_field_update_forbid(). */ function field_test_field_update_forbid($field, $prior_field, $has_data) { - if ($field['type'] == 'test_field' && $field['settings']['unchangeable'] != $prior_field['settings']['unchangeable']) { + if ($field->type == 'test_field' && $field->settings['unchangeable'] != $prior_field->settings['unchangeable']) { throw new FieldException("field_test 'unchangeable' setting cannot be changed'"); } } @@ -124,7 +124,7 @@ function field_test_field_validate(EntityInterface $entity = NULL, $field, $inst foreach ($items as $delta => $item) { if ($item['value'] == -1) { - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$field->field_name][$langcode][$delta][] = array( 'error' => 'field_test_invalid', 'message' => t('%name does not accept the value -1.', array('%name' => $instance['label'])), ); @@ -143,7 +143,7 @@ function field_test_field_is_empty($item, $field) { * Implements hook_field_settings_form(). */ function field_test_field_settings_form($field, $instance, $has_data) { - $settings = $field['settings']; + $settings = $field->settings; $form['test_field_setting'] = array( '#type' => 'textfield', @@ -196,13 +196,13 @@ function field_test_default_value(EntityInterface $entity, $field, $instance) { * Implements hook_field_access(). */ function field_test_field_access($op, $field, $entity_type, $entity, $account) { - if ($field['field_name'] == "field_no_{$op}_access") { + if ($field->field_name == "field_no_{$op}_access") { return FALSE; } // Only grant view access to test_view_field fields when the user has // 'view test_view_field content' permission. - if ($field['field_name'] == 'test_view_field' && $op == 'view' && !user_access('view test_view_field content')) { + if ($field->field_name == 'test_view_field' && $op == 'view' && !user_access('view test_view_field content')) { return FALSE; } diff --git a/core/modules/field/tests/modules/field_test/field_test.install b/core/modules/field/tests/modules/field_test/field_test.install index 5355e9b..96f606a 100644 --- a/core/modules/field/tests/modules/field_test/field_test.install +++ b/core/modules/field/tests/modules/field_test/field_test.install @@ -114,7 +114,7 @@ function field_test_schema() { * Implements hook_field_schema(). */ function field_test_field_schema($field) { - if ($field['type'] == 'test_field') { + if ($field->type == 'test_field') { return array( 'columns' => array( 'value' => array( diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 03094dd..3ed0ce5 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -80,7 +80,7 @@ function field_test_menu() { * This simulates a field operation callback to be invoked by _field_invoke(). */ function field_test_field_test_op(EntityInterface $entity, $field, $instance, $langcode, &$items) { - return array($langcode => hash('sha256', serialize(array($entity, $field['field_name'], $langcode, $items)))); + return array($langcode => hash('sha256', serialize(array($entity, $field->field_name, $langcode, $items)))); } /** @@ -217,7 +217,7 @@ function field_test_field_attach_view_alter(&$output, $context) { */ function field_test_field_widget_properties_alter(&$widget, $context) { // Make the alter_test_text field 42 characters for nodes and comments. - if (in_array($context['entity_type'], array('node', 'comment')) && ($context['field']['field_name'] == 'alter_test_text')) { + if (in_array($context['entity_type'], array('node', 'comment')) && ($context['field']->field_name == 'alter_test_text')) { $widget['settings']['size'] = 42; } } @@ -227,7 +227,7 @@ function field_test_field_widget_properties_alter(&$widget, $context) { */ function field_test_field_widget_properties_user_alter(&$widget, $context) { // Always use buttons for the alter_test_options field on user forms. - if ($context['field']['field_name'] == 'alter_test_options') { + if ($context['field']->field_name == 'alter_test_options') { $widget['type'] = 'options_buttons'; } } @@ -236,7 +236,7 @@ function field_test_field_widget_properties_user_alter(&$widget, $context) { * Implements hook_field_widget_form_alter(). */ function field_test_field_widget_form_alter(&$element, &$form_state, $context) { - switch ($context['field']['field_name']) { + switch ($context['field']->field_name) { case 'alter_test_text': drupal_set_message('Field size: ' . $context['instance']->getWidget()->getSetting('size')); break; diff --git a/core/modules/field/tests/modules/field_test/field_test.storage.inc b/core/modules/field/tests/modules/field_test/field_test.storage.inc index a53b941..f0593b1 100644 --- a/core/modules/field/tests/modules/field_test/field_test.storage.inc +++ b/core/modules/field/tests/modules/field_test/field_test.storage.inc @@ -31,7 +31,7 @@ function field_test_field_storage_details($field) { // Add field columns. $columns = array(); - foreach ((array) $field['columns'] as $column_name => $attributes) { + foreach ((array) $field->columns as $column_name => $attributes) { $columns[$column_name] = $column_name; } return array( @@ -50,9 +50,9 @@ function field_test_field_storage_details($field) { function field_test_field_storage_details_alter(&$details, $field) { // For testing, storage details are changed only because of the field name. - if ($field['field_name'] == 'field_test_change_my_details') { + if ($field->field_name == 'field_test_change_my_details') { $columns = array(); - foreach ((array) $field['columns'] as $column_name => $attributes) { + foreach ((array) $field->columns as $column_name => $attributes) { $columns[$column_name] = $column_name; } $details['drupal_variables'] = array( @@ -88,8 +88,8 @@ function field_test_field_storage_load($entity_type, $entities, $age, $fields, $ foreach ($fields as $field_id => $ids) { $field = field_info_field_by_id($field_id); - $field_name = $field['field_name']; - $field_data = $data[$field['id']]; + $field_name = $field->field_name; + $field_data = $data[$field->id()]; $sub_table = $load_current ? 'current' : 'revisions'; $delta_count = array(); foreach ($field_data[$sub_table] as $row) { @@ -99,9 +99,9 @@ function field_test_field_storage_load($entity_type, $entities, $age, $fields, $ if (!isset($delta_count[$row->entity_id][$row->langcode])) { $delta_count[$row->entity_id][$row->langcode] = 0; } - if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field['cardinality']) { + if ($field->cardinality == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->cardinality) { $item = array(); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $item[$column] = $row->{$column}; } $entities[$row->entity_id]->{$field_name}[$row->langcode][] = $item; @@ -126,7 +126,7 @@ function field_test_field_storage_write(EntityInterface $entity, $op, $fields) { foreach ($fields as $field_id) { $field = field_info_field_by_id($field_id); - $field_name = $field['field_name']; + $field_name = $field->field_name; $field_data = &$data[$field_id]; $all_langcodes = field_available_languages($entity->entityType(), $field); @@ -167,7 +167,7 @@ function field_test_field_storage_write(EntityInterface $entity, $op, $fields) { 'deleted' => FALSE, 'langcode' => $langcode, ); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $row->{$column} = isset($item[$column]) ? $item[$column] : NULL; } @@ -176,7 +176,7 @@ function field_test_field_storage_write(EntityInterface $entity, $op, $fields) { $field_data['revisions'][] = $row; } - if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) { + if ($field->cardinality != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field->cardinality) { break; } } @@ -206,7 +206,7 @@ function field_test_field_storage_delete(EntityInterface $entity, $fields) { function field_test_field_storage_purge(EntityInterface $entity, $field, $instance) { $data = _field_test_storage_data(); - $field_data = &$data[$field['id']]; + $field_data = &$data[$field->id()]; foreach (array('current', 'revisions') as $sub_table) { foreach ($field_data[$sub_table] as $key => $row) { if ($row->type == $entity->entityType() && $row->entity_id == $entity->id()) { @@ -247,9 +247,9 @@ function field_test_field_storage_query($field_id, $conditions, $count, &$cursor $load_current = $age == FIELD_LOAD_CURRENT; $field = field_info_field_by_id($field_id); - $field_columns = array_keys($field['columns']); + $field_columns = array_keys($field->columns); - $field_data = $data[$field['id']]; + $field_data = $data[$field->id()]; $sub_table = $load_current ? 'current' : 'revisions'; // We need to sort records by entity type and entity id. usort($field_data[$sub_table], '_field_test_field_storage_query_sort_helper'); @@ -267,7 +267,7 @@ function field_test_field_storage_query($field_id, $conditions, $count, &$cursor break; } - if ($row->field_id == $field['id']) { + if ($row->field_id == $field->id()) { $match = TRUE; $condition_deleted = FALSE; // Add conditions. @@ -366,13 +366,13 @@ function _field_test_field_storage_query_sort_helper($a, $b) { * Implements hook_field_storage_create_field(). */ function field_test_field_storage_create_field($field) { - if ($field['storage']['type'] == 'field_test_storage_failure') { + if ($field->storage['type'] == 'field_test_storage_failure') { throw new Exception('field_test_storage_failure engine always fails to create fields'); } $data = _field_test_storage_data(); - $data[$field['id']] = array( + $data[$field->id()] = array( 'current' => array(), 'revisions' => array(), ); @@ -386,7 +386,7 @@ function field_test_field_storage_create_field($field) { function field_test_field_storage_delete_field($field) { $data = _field_test_storage_data(); - $field_data = &$data[$field['id']]; + $field_data = &$data[$field->id()]; foreach (array('current', 'revisions') as $sub_table) { foreach ($field_data[$sub_table] as &$row) { $row->deleted = TRUE; @@ -403,7 +403,7 @@ function field_test_field_storage_delete_instance($instance) { $data = _field_test_storage_data(); $field = field_info_field($instance['field_name']); - $field_data = &$data[$field['id']]; + $field_data = &$data[$field->id()]; foreach (array('current', 'revisions') as $sub_table) { foreach ($field_data[$sub_table] as &$row) { if ($row->bundle == $instance['bundle']) { @@ -432,8 +432,8 @@ function field_test_field_attach_rename_bundle($bundle_old, $bundle_new) { $instances = field_read_instances(array('bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); foreach ($instances as $field_name => $instance) { $field = field_info_field_by_id($instance['field_id']); - if ($field['storage']['type'] == 'field_test_storage') { - $field_data = &$data[$field['id']]; + if ($field->storage['type'] == 'field_test_storage') { + $field_data = &$data[$field->id()]; foreach (array('current', 'revisions') as $sub_table) { foreach ($field_data[$sub_table] as &$row) { if ($row->bundle == $bundle_old) { @@ -454,9 +454,9 @@ function field_test_field_attach_delete_bundle($entity_type, $bundle, $instances $data = _field_test_storage_data(); foreach ($instances as $field_name => $instance) { - $field = field_info_field($field_name); - if ($field['storage']['type'] == 'field_test_storage') { - $field_data = &$data[$field['id']]; + $field = field_info_field($instance['field_name']); + if ($field && $field->storage['type'] == 'field_test_storage') { + $field_data = &$data[$field->id()]; foreach (array('current', 'revisions') as $sub_table) { foreach ($field_data[$sub_table] as &$row) { if ($row->bundle == $bundle_old) { diff --git a/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml new file mode 100644 index 0000000..45afef5 --- /dev/null +++ b/core/modules/field/tests/modules/field_test_config/config/field.field.field_test_import.yml @@ -0,0 +1,49 @@ +id: field_test_import +uuid: fb38277f-1fd4-49d5-8d09-9d7037fdcce9 +field_name: field_test_import +type: text +translatable: false +entity_types: { } +cardinality: '1' +locked: false +settings: + max_length: '255' +module: text +active: 1 +deleted: 0 +storage_type: field_sql_storage +storage_module: field_sql_storage +storage_active: 1 +storage: + type: field_sql_storage + settings: { } + module: field_sql_storage + active: 1 + details: + sql: + FIELD_LOAD_CURRENT: + field_data_field_test_import: + value: field_test_import_value + format: field_test_import_format + FIELD_LOAD_REVISION: + field_revision_field_test_import: + value: field_test_import_value + format: field_test_import_format +columns: + value: + type: varchar + length: '255' + 'not null': false + format: + type: varchar + length: 255 + 'not null': false +'foreign_keys': + format: + table: filter_format + columns: + format: format +indexes: + format: + - format +langcode: und diff --git a/core/modules/field/tests/modules/field_test_config/config/field.instance.node.test_import.field_test_import.yml b/core/modules/field/tests/modules/field_test_config/config/field.instance.node.test_import.field_test_import.yml new file mode 100644 index 0000000..d2690db --- /dev/null +++ b/core/modules/field/tests/modules/field_test_config/config/field.instance.node.test_import.field_test_import.yml @@ -0,0 +1,33 @@ +id: node.test_import.field_test_import +uuid: 392b4e9d-6157-412e-9603-3d622512f498 +name: '' +label: node.test_import.field_test_import +data: + field_name: field_test_import + entity_type: node + bundle: test_import + label: 'Test import field' + widget: + weight: '-2' + type: text_textfield + module: text + active: 0 + settings: + size: '60' + field_id: fb38277f-1fd4-49d5-8d09-9d7037fdcce9 + id: 948dff + settings: + text_processing: '0' + user_register_form: false + required: 0 + description: '' + deleted: 0 + active: 1 + locked: false + type: text + module: text + storage_type: field_sql_storage + storage_active: 1 + storage_module: field_sql_storage + default_value: null +langcode: und diff --git a/core/modules/field/tests/modules/field_test_config/field_test_config.info b/core/modules/field/tests/modules/field_test_config/field_test_config.info new file mode 100644 index 0000000..49b0509 --- /dev/null +++ b/core/modules/field/tests/modules/field_test_config/field_test_config.info @@ -0,0 +1,6 @@ +name = "Field API configuration tests" +description = "Support module for the Field API configuration tests." +core = 8.x +package = Testing +version = VERSION +hidden = TRUE diff --git a/core/modules/field/tests/modules/field_test_config/field_test_config.module b/core/modules/field/tests/modules/field_test_config/field_test_config.module new file mode 100644 index 0000000..e208464 --- /dev/null +++ b/core/modules/field/tests/modules/field_test_config/field_test_config.module @@ -0,0 +1,6 @@ + TRUE, 'include_inactive' => TRUE)); - drupal_load('module', 'field_sql_storage'); - foreach ($fields as $field) { + // During a Drupal 7 to Drupal 8 upgrade it is only safe to call + // field configurations once field_update_8002() has finished. + if (drupal_get_installed_schema_version('field') >= 8002) { + // We don't call field_read_fields() as this will cause endless loops + // in entity_get_info(). + // @todo verify now that bundle info and view modes are moved out. + $fields = config_get_storage_names_with_prefix('field.field'); + foreach ($fields as $name) { + $field = config($name)->get(); if ($field['storage']['type'] == 'field_sql_storage') { - $schema += _field_sql_storage_schema($field); + $schema += _field_sql_storage_schema((object) $field); } } } + return $schema; } @@ -113,8 +119,8 @@ function field_sql_storage_update_8000(&$sandbox) { // Update schema. foreach ($fields as $field) { - $data_table = _field_sql_storage_tablename($field); - $revision_table = _field_sql_storage_revision_tablename($field); + $data_table = _field_sql_storage_tablename((object) $field); + $revision_table = _field_sql_storage_revision_tablename((object) $field); $table_info = array($data_table => $primary_key_data, $revision_table => $primary_key_revision); foreach ($table_info as $table => $primary_key) { diff --git a/core/modules/field_sql_storage/field_sql_storage.module b/core/modules/field_sql_storage/field_sql_storage.module index accca35..9803528 100644 --- a/core/modules/field_sql_storage/field_sql_storage.module +++ b/core/modules/field_sql_storage/field_sql_storage.module @@ -44,11 +44,11 @@ function field_sql_storage_field_storage_info() { * A string containing the generated name for the database table. */ function _field_sql_storage_tablename($field) { - if ($field['deleted']) { - return "field_deleted_data_{$field['id']}"; + if ($field->deleted) { + return "field_deleted_data_" . field_generate_id($field->id()); } else { - return "field_data_{$field['field_name']}"; + return "field_data_{$field->field_name}"; } } @@ -62,11 +62,11 @@ function _field_sql_storage_tablename($field) { * A string containing the generated name for the database table. */ function _field_sql_storage_revision_tablename($field) { - if ($field['deleted']) { - return "field_deleted_revision_{$field['id']}"; + if ($field->deleted) { + return "field_deleted_revision_" . field_generate_id($field->id()); } else { - return "field_revision_{$field['field_name']}"; + return "field_revision_{$field->field_name}"; } } @@ -115,9 +115,9 @@ function _field_sql_storage_indexname($name, $index) { * One or more tables representing the schema for the field. */ function _field_sql_storage_schema($field) { - $deleted = $field['deleted'] ? 'deleted ' : ''; + $deleted = $field->deleted ? 'deleted ' : ''; $current = array( - 'description' => "Data storage for {$deleted}field {$field['id']} ({$field['field_name']})", + 'description' => "Data storage for {$deleted}field {$field->id} ({$field->field_name})", 'fields' => array( 'entity_type' => array( 'type' => 'varchar', @@ -178,44 +178,50 @@ function _field_sql_storage_schema($field) { ), ); - $field += array('columns' => array(), 'indexes' => array(), 'foreign keys' => array()); + $schema_properties = array('columns' => array(), 'indexes' => array(), 'foreign keys' => array()); + foreach ($schema_properties as $key => $value) { + if (!isset($field->data[$key])) { + $field->data[$key] = $value; + } + } + // Add field columns. - foreach ($field['columns'] as $column_name => $attributes) { - $real_name = _field_sql_storage_columnname($field['field_name'], $column_name); + foreach ($field->columns as $column_name => $attributes) { + $real_name = _field_sql_storage_columnname($field->field_name, $column_name); $current['fields'][$real_name] = $attributes; } // Add indexes. - foreach ($field['indexes'] as $index_name => $columns) { - $real_name = _field_sql_storage_indexname($field['field_name'], $index_name); + foreach ($field->indexes as $index_name => $columns) { + $real_name = _field_sql_storage_indexname($field->field_name, $index_name); foreach ($columns as $column_name) { // Indexes can be specified as either a column name or an array with // column name and length. Allow for either case. if (is_array($column_name)) { $current['indexes'][$real_name][] = array( - _field_sql_storage_columnname($field['field_name'], $column_name[0]), + _field_sql_storage_columnname($field->field_name, $column_name[0]), $column_name[1], ); } else { - $current['indexes'][$real_name][] = _field_sql_storage_columnname($field['field_name'], $column_name); + $current['indexes'][$real_name][] = _field_sql_storage_columnname($field->field_name, $column_name); } } } // Add foreign keys. - foreach ($field['foreign keys'] as $specifier => $specification) { - $real_name = _field_sql_storage_indexname($field['field_name'], $specifier); + foreach ($field->foreign_keys as $specifier => $specification) { + $real_name = _field_sql_storage_indexname($field->field_name, $specifier); $current['foreign keys'][$real_name]['table'] = $specification['table']; foreach ($specification['columns'] as $column => $referenced) { - $sql_storage_column = _field_sql_storage_columnname($field['field_name'], $column_name); + $sql_storage_column = _field_sql_storage_columnname($field->field_name, $column_name); $current['foreign keys'][$real_name]['columns'][$sql_storage_column] = $referenced; } } // Construct the revision table. $revision = $current; - $revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})"; + $revision['description'] = "Revision archive storage for {$deleted}field {$field->id} ({$field->field_name})"; $revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'langcode'); $revision['fields']['revision_id']['not null'] = TRUE; $revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to'; @@ -244,7 +250,7 @@ function field_sql_storage_field_storage_create_field($field) { * data. */ function field_sql_storage_field_update_forbid($field, $prior_field, $has_data) { - if ($has_data && $field['columns'] != $prior_field['columns']) { + if ($has_data && $field->columns != $prior_field->columns) { throw new FieldUpdateForbiddenException("field_sql_storage cannot change the schema for an existing field with data."); } } @@ -294,30 +300,30 @@ function field_sql_storage_field_storage_update_field($field, $prior_field, $has // priors that exist unchanged. $table = _field_sql_storage_tablename($prior_field); $revision_table = _field_sql_storage_revision_tablename($prior_field); - foreach ($prior_field['indexes'] as $name => $columns) { - if (!isset($field['indexes'][$name]) || $columns != $field['indexes'][$name]) { - $real_name = _field_sql_storage_indexname($field['field_name'], $name); + foreach ($prior_field->indexes as $name => $columns) { + if (!isset($field->indexes[$name]) || $columns != $field->indexes[$name]) { + $real_name = _field_sql_storage_indexname($field->field_name, $name); db_drop_index($table, $real_name); db_drop_index($revision_table, $real_name); } } $table = _field_sql_storage_tablename($field); $revision_table = _field_sql_storage_revision_tablename($field); - foreach ($field['indexes'] as $name => $columns) { - if (!isset($prior_field['indexes'][$name]) || $columns != $prior_field['indexes'][$name]) { - $real_name = _field_sql_storage_indexname($field['field_name'], $name); + foreach ($field->indexes as $name => $columns) { + if (!isset($prior_field->indexes[$name]) || $columns != $prior_field->indexes[$name]) { + $real_name = _field_sql_storage_indexname($field->field_name, $name); $real_columns = array(); foreach ($columns as $column_name) { // Indexes can be specified as either a column name or an array with // column name and length. Allow for either case. if (is_array($column_name)) { $real_columns[] = array( - _field_sql_storage_columnname($field['field_name'], $column_name[0]), + _field_sql_storage_columnname($field->field_name, $column_name[0]), $column_name[1], ); } else { - $real_columns[] = _field_sql_storage_columnname($field['field_name'], $column_name); + $real_columns[] = _field_sql_storage_columnname($field->field_name, $column_name); } } db_add_index($table, $real_name, $real_columns); @@ -333,7 +339,7 @@ function field_sql_storage_field_storage_update_field($field, $prior_field, $has */ function field_sql_storage_field_storage_delete_field($field) { // Mark all data associated with the field for deletion. - $field['deleted'] = 0; + $field->deleted = 0; $table = _field_sql_storage_tablename($field); $revision_table = _field_sql_storage_revision_tablename($field); db_update($table) @@ -341,7 +347,7 @@ function field_sql_storage_field_storage_delete_field($field) { ->execute(); // Move the table to a unique name while the table contents are being deleted. - $field['deleted'] = 1; + $field->deleted = 1; $new_table = _field_sql_storage_tablename($field); $revision_new_table = _field_sql_storage_revision_tablename($field); db_rename_table($table, $new_table); @@ -357,7 +363,7 @@ function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fi foreach ($fields as $field_id => $ids) { $field = field_info_field_by_id($field_id); - $field_name = $field['field_name']; + $field_name = $field->field_name; $table = $load_current ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field); $query = db_select($table, 't') @@ -379,11 +385,11 @@ function field_sql_storage_field_storage_load($entity_type, $entities, $age, $fi $delta_count[$row->entity_id][$row->langcode] = 0; } - if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field['cardinality']) { + if ($field->cardinality == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->cardinality) { $item = array(); // For each column declared by the field, populate the item // from the prefixed database column. - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $column_name = _field_sql_storage_columnname($field_name, $column); $item[$column] = $row->$column_name; } @@ -410,7 +416,7 @@ function field_sql_storage_field_storage_write(EntityInterface $entity, $op, $fi foreach ($fields as $field_id) { $field = field_info_field_by_id($field_id); - $field_name = $field['field_name']; + $field_name = $field->field_name; $table_name = _field_sql_storage_tablename($field); $revision_name = _field_sql_storage_revision_tablename($field); @@ -444,7 +450,7 @@ function field_sql_storage_field_storage_write(EntityInterface $entity, $op, $fi // Prepare the multi-insert query. $do_insert = FALSE; $columns = array('entity_type', 'entity_id', 'revision_id', 'bundle', 'delta', 'langcode'); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $columns[] = _field_sql_storage_columnname($field_name, $column); } $query = db_insert($table_name)->fields($columns); @@ -464,7 +470,7 @@ function field_sql_storage_field_storage_write(EntityInterface $entity, $op, $fi 'delta' => $delta, 'langcode' => $langcode, ); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->columns as $column => $attributes) { $record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL; } $query->values($record); @@ -472,7 +478,7 @@ function field_sql_storage_field_storage_write(EntityInterface $entity, $op, $fi $revision_query->values($record); } - if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) { + if ($field->cardinality != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field->cardinality) { break; } } @@ -572,7 +578,7 @@ function field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $instances = field_read_instances(array('entity_type' => $entity_type, 'bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); foreach ($instances as $instance) { $field = field_info_field_by_id($instance['field_id']); - if ($field['storage']['type'] == 'field_sql_storage') { + if ($field->storage['type'] == 'field_sql_storage') { $table_name = _field_sql_storage_tablename($field); $revision_name = _field_sql_storage_revision_tablename($field); db_update($table_name) @@ -607,10 +613,10 @@ function field_sql_storage_field_storage_purge_field($field) { */ function field_sql_storage_field_storage_details($field) { $details = array(); - if (!empty($field['columns'])) { + if (!empty($field->columns)) { // Add field columns. - foreach ($field['columns'] as $column_name => $attributes) { - $real_name = _field_sql_storage_columnname($field['field_name'], $column_name); + foreach ($field->columns as $column_name => $attributes) { + $real_name = _field_sql_storage_columnname($field->field_name, $column_name); $columns[$column_name] = $real_name; } return array( diff --git a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php index 09c8fda..2760cb8 100644 --- a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php +++ b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Entity/Tables.php @@ -110,7 +110,7 @@ function addField($field, $type, $langcode) { if ($key < $count) { $next = $specifiers[$key + 1]; // Is this a field column? - if (isset($field['columns'][$next]) || in_array($next, field_reserved_columns())) { + if (isset($field->columns[$next]) || in_array($next, field_reserved_columns())) { // Use it. $column = $next; // Do not process it again. @@ -128,7 +128,7 @@ function addField($field, $type, $langcode) { // Get the field definitions form a mocked entity. $entity = entity_create($entity_type, array()); - $propertyDefinitions = $entity->{$field['field_name']}->getPropertyDefinitions(); + $propertyDefinitions = $entity->{$field->field_name}->getPropertyDefinitions(); // If the column is not yet known, ie. the // $node->field_image->entity case then use the id source as the @@ -148,7 +148,7 @@ function addField($field, $type, $langcode) { $column = 'value'; } $table = $this->ensureFieldTable($index_prefix, $field, $type, $langcode, $base_table, $entity_id_field, $field_id_field); - $sql_column = _field_sql_storage_columnname($field['field_name'], $column); + $sql_column = _field_sql_storage_columnname($field->field_name, $column); } // This is an entity property (non-configurable field). else { @@ -231,10 +231,10 @@ protected function ensureEntityTable($index_prefix, $property, $type, $langcode, * @throws \Drupal\Core\Entity\Query\QueryException */ protected function ensureFieldTable($index_prefix, &$field, $type, $langcode, $base_table, $entity_id_field, $field_id_field) { - $field_name = $field['field_name']; + $field_name = $field->field_name; if (!isset($this->fieldTables[$index_prefix . $field_name])) { $table = $this->sqlQuery->getMetaData('age') == FIELD_LOAD_CURRENT ? _field_sql_storage_tablename($field) : _field_sql_storage_revision_tablename($field); - if ($field['cardinality'] != 1) { + if ($field->cardinality != 1) { $this->sqlQuery->addMetaData('simple_query', FALSE); } $entity_type = $this->sqlQuery->getMetaData('entity_type'); diff --git a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php index e79757e..10bcf86 100644 --- a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php +++ b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php @@ -68,7 +68,7 @@ function testFieldAttachLoad() { for ($evid = 0; $evid < 4; ++$evid) { $values[$evid] = array(); // Note: we insert one extra value ('<=' instead of '<'). - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field->cardinality; $delta++) { $value = mt_rand(1, 127); $values[$evid][] = $value; $query->values(array($entity_type, $eid, $evid, $delta, $langcode, $value)); @@ -87,7 +87,7 @@ function testFieldAttachLoad() { $entity = field_test_create_entity($eid, 0, $this->instance['bundle']); field_attach_load($entity_type, array($eid => $entity)); foreach ($values[0] as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field->cardinality) { $this->assertEqual($entity->{$this->field_name}[$langcode][$delta]['value'], $value, "Value $delta is loaded correctly for current revision"); } else { @@ -100,7 +100,7 @@ function testFieldAttachLoad() { $entity = field_test_create_entity($eid, $evid, $this->instance['bundle']); field_attach_load_revision($entity_type, array($eid => $entity)); foreach ($values[$evid] as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field->cardinality) { $this->assertEqual($entity->{$this->field_name}[$langcode][$delta]['value'], $value, "Value $delta for revision $evid is loaded correctly"); } else { @@ -134,7 +134,7 @@ function testFieldAttachInsertAndUpdate() { $values = array(); // Note: we try to insert one extra value ('<=' instead of '<'). // TODO : test empty values filtering and "compression" (store consecutive deltas). - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field->cardinality; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name}[$langcode] = $rev_values[0] = $values; @@ -142,7 +142,7 @@ function testFieldAttachInsertAndUpdate() { $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', PDO::FETCH_ASSOC); foreach ($values as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field->cardinality) { $this->assertEqual($rows[$delta][$this->field_name . '_value'], $value['value'], t("Value $delta is inserted correctly")); } else { @@ -154,14 +154,14 @@ function testFieldAttachInsertAndUpdate() { $entity = field_test_create_entity(0, 1, $this->instance['bundle']); $values = array(); // Note: we try to update one extra value ('<=' instead of '<'). - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field->cardinality; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name}[$langcode] = $rev_values[1] = $values; field_attach_update($entity); $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', PDO::FETCH_ASSOC); foreach ($values as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field->cardinality) { $this->assertEqual($rows[$delta][$this->field_name . '_value'], $value['value'], t("Value $delta is updated correctly")); } else { @@ -191,7 +191,7 @@ function testFieldAttachInsertAndUpdate() { field_attach_update($entity); $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', PDO::FETCH_ASSOC); foreach ($values as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field->cardinality) { $this->assertEqual($rows[$delta][$this->field_name . '_value'], $value['value'], t("Update with no field_name entry leaves value $delta untouched")); } } @@ -312,7 +312,7 @@ function testUpdateFieldSchemaWithData() { $entity->save(); // Attempt to update the field in a way that would work without data. - $field['settings']['scale'] = 3; + $field->settings['scale'] = 3; try { field_update_field($field); $this->fail(t('Cannot update field schema with data.')); @@ -332,7 +332,7 @@ function testFieldUpdateFailure() { // Attempt to update the field in a way that would break the storage. $prior_field = $field; - $field['settings']['max_length'] = -1; + $field->settings['max_length'] = -1; try { field_update_field($field); $this->fail(t('Update succeeded.')); @@ -400,21 +400,21 @@ function testFieldStorageDetails() { $revision = _field_sql_storage_revision_tablename($this->field); // Retrieve the field and instance with field_info so the storage details are attached. - $field = field_info_field($this->field['field_name']); + $field = field_info_field($this->field->field_name); $instance = field_info_instance($this->instance['entity_type'], $this->instance['field_name'], $this->instance['bundle']); // The storage details are indexed by a storage engine type. - $this->assertTrue(array_key_exists('sql', $field['storage']['details']), 'The storage type is SQL.'); + $this->assertTrue(array_key_exists('sql', $field->storage['details']), 'The storage type is SQL.'); // The SQL details are indexed by table name. - $details = $field['storage']['details']['sql']; + $details = $field->storage['details']['sql']; $this->assertTrue(array_key_exists($current, $details[FIELD_LOAD_CURRENT]), 'Table name is available in the instance array.'); $this->assertTrue(array_key_exists($revision, $details[FIELD_LOAD_REVISION]), 'Revision table name is available in the instance array.'); // Test current and revision storage details together because the columns // are the same. - foreach ((array) $this->field['columns'] as $column_name => $attributes) { - $storage_column_name = _field_sql_storage_columnname($this->field['field_name'], $column_name); + foreach ($this->field->columns as $column_name => $attributes) { + $storage_column_name = _field_sql_storage_columnname($this->field->field_name, $column_name); $this->assertEqual($details[FIELD_LOAD_CURRENT][$current][$column_name], $storage_column_name, t('Column name %value matches the definition in %bin.', array('%value' => $column_name, '%bin' => $current))); $this->assertEqual($details[FIELD_LOAD_REVISION][$revision][$column_name], $storage_column_name, t('Column name %value matches the definition in %bin.', array('%value' => $column_name, '%bin' => $revision))); } @@ -431,13 +431,13 @@ function testFieldSqlStorageForeignKeys() { // Retrieve the field and instance with field_info and verify the foreign // keys are in place. $field = field_info_field($field_name); - $this->assertEqual($field['foreign keys']['format']['table'], 'filter_format', 'Foreign key table name preserved through CRUD'); - $this->assertEqual($field['foreign keys']['format']['columns']['format'], 'format', 'Foreign key column name preserved through CRUD'); + $this->assertEqual($field->foreign_keys['format']['table'], 'filter_format', 'Foreign key table name preserved through CRUD'); + $this->assertEqual($field->foreign_keys['format']['columns']['format'], 'format', 'Foreign key column name preserved through CRUD'); // Now grab the SQL schema and verify that too. $schema = drupal_get_schema(_field_sql_storage_tablename($field)); $this->assertEqual(count($schema['foreign keys']), 1, t("There is 1 foreign key in the schema")); $foreign_key = reset($schema['foreign keys']); - $filter_column = _field_sql_storage_columnname($field['field_name'], 'format'); + $filter_column = _field_sql_storage_columnname($field->field_name, 'format'); $this->assertEqual($foreign_key['table'], 'filter_format', 'Foreign key table name preserved in the schema'); $this->assertEqual($foreign_key['columns'][$filter_column], 'format', 'Foreign key column name preserved in the schema'); } diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 4056e4a..95292c7 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -34,10 +34,10 @@ function field_ui_fields_list() { // Initialize the row if we encounter the field for the first time. if (!isset($rows[$field_name])) { - $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array(''); - $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name; - $module_name = $field_types[$field['type']]['module']; - $rows[$field_name]['data'][1] = $field_types[$field['type']]['label'] . ' ' . t('(module: !module)', array('!module' => $modules[$module_name]->info['name'])); + $rows[$field_name]['class'] = $field->locked ? array('menu-disabled') : array(''); + $rows[$field_name]['data'][0] = $field->locked ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name; + $module_name = $field_types[$field->type]['module']; + $rows[$field_name]['data'][1] = $field_types[$field->type]['label'] . ' ' . t('(module: !module)', array('!module' => $modules[$module_name]->info['name'])); } // Add the current instance. @@ -472,14 +472,14 @@ function field_ui_existing_field_options($entity_type, $bundle) { // - fields that cannot be added to the entity type, // - fields that should not be added via user interface. - if (empty($field['locked']) - && !field_info_instance($entity_type, $field['field_name'], $bundle) - && (empty($field['entity_types']) || in_array($entity_type, $field['entity_types'])) - && empty($field_types[$field['type']]['no_ui'])) { + if (empty($field->locked) + && !field_info_instance($entity_type, $field->field_name, $bundle) + && (empty($field->entity_types) || in_array($entity_type, $field->entity_types)) + && empty($field_types[$field->type]['no_ui'])) { $info[$instance['field_name']] = array( - 'type' => $field['type'], - 'type_label' => $field_types[$field['type']]['label'], - 'field' => $field['field_name'], + 'type' => $field->type, + 'type_label' => $field_types[$field->type]['label'], + 'field' => $field->field_name, 'label' => $instance['label'], 'widget_type' => $instance['widget']['type'], ); @@ -524,7 +524,7 @@ function field_ui_field_settings_form($form, &$form_state, $instance) { } // Build the configurable field values. - $cardinality = $field['cardinality']; + $cardinality = $field->cardinality; $form['field']['container'] = array( // We can't use the container element because it doesn't support the title // or description properties. @@ -559,10 +559,10 @@ function field_ui_field_settings_form($form, &$form_state, $instance) { } // Build the non-configurable field values. - $form['field']['field_name'] = array('#type' => 'value', '#value' => $field['field_name']); - $form['field']['type'] = array('#type' => 'value', '#value' => $field['type']); - $form['field']['module'] = array('#type' => 'value', '#value' => $field['module']); - $form['field']['active'] = array('#type' => 'value', '#value' => $field['active']); + $form['field']['field_name'] = array('#type' => 'value', '#value' => $field->field_name); + $form['field']['type'] = array('#type' => 'value', '#value' => $field->type); + $form['field']['module'] = array('#type' => 'value', '#value' => $field->module); + $form['field']['active'] = array('#type' => 'value', '#value' => $field->active); // Add settings provided by the field module. The field module is // responsible for not returning settings that cannot be changed if @@ -570,7 +570,7 @@ function field_ui_field_settings_form($form, &$form_state, $instance) { $form['field']['settings'] = array( '#weight' => 10, ); - $additions = module_invoke($field['module'], 'field_settings_form', $field, $instance, $has_data); + $additions = module_invoke($field->module, 'field_settings_form', $field, $instance, $has_data); if (is_array($additions)) { $form['field']['settings'] += $additions; } @@ -616,10 +616,12 @@ function field_ui_field_settings_form_submit($form, &$form_state) { $entity_type = $form['#entity_type']; $bundle = $form['#bundle']; - $instance = field_info_instance($entity_type, $field['field_name'], $bundle); + $instance = field_info_instance($entity_type, $field->field_name, $bundle); // Update the field. - $field = array_merge($field, $field_values); + foreach ($field_values as $key => $value) { + $field->{$key} = $value; + } try { field_update_field($field); @@ -659,7 +661,7 @@ function field_ui_widget_type_form($form, &$form_state, FieldInstance $instance) '#type' => 'select', '#title' => t('Widget type'), '#required' => TRUE, - '#options' => field_ui_widget_type_options($field['type']), + '#options' => field_ui_widget_type_options($field->type), '#default_value' => $instance->getWidget()->getPluginId(), '#description' => t('The type of form element you would like to present to the user when creating this field in the %type type.', array('%type' => $bundle_label)), ); @@ -719,7 +721,7 @@ function field_ui_field_delete_form($form, &$form_state, $instance) { $form['entity_type'] = array('#type' => 'value', '#value' => $entity_type); $form['bundle'] = array('#type' => 'value', '#value' => $bundle); - $form['field_name'] = array('#type' => 'value', '#value' => $field['field_name']); + $form['field_name'] = array('#type' => 'value', '#value' => $field->field_name); $output = confirm_form($form, t('Are you sure you want to delete the field %field?', array('%field' => $instance['label'])), @@ -729,7 +731,7 @@ function field_ui_field_delete_form($form, &$form_state, $instance) { 'confirm' ); - if ($field['locked']) { + if ($field->locked) { unset($output['actions']['submit']); $output['description']['#markup'] = t('This field is locked and cannot be deleted.'); } @@ -754,8 +756,8 @@ function field_ui_field_delete_form_submit($form, &$form_state) { $bundles = entity_get_bundles(); $bundle_label = $bundles[$entity_type][$bundle]['label']; - if (!empty($bundle) && $field && !$field['locked'] && $form_values['confirm']) { - field_delete_instance($instance); + if (!empty($bundle) && $field && !$field->locked && $form_values['confirm']) { + field_delete_instance($instance->getArray()); drupal_set_message(t('The field %field has been deleted from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label))); } else { @@ -801,7 +803,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) { $form['#entity'] = _field_create_entity_from_ids($ids); $form['#entity']->field_ui_default_value = TRUE; - if (!empty($field['locked'])) { + if (!empty($field->locked)) { $form['locked'] = array( '#markup' => t('The field %field is locked and cannot be edited.', array('%field' => $instance['label'])), ); @@ -837,7 +839,7 @@ function field_ui_field_edit_form($form, &$form_state, $instance) { $form['instance']['label'] = array( '#type' => 'textfield', '#title' => t('Label'), - '#default_value' => !empty($instance['label']) ? $instance['label'] : $field['field_name'], + '#default_value' => !empty($instance['label']) ? $instance['label'] : $field->field_name, '#required' => TRUE, '#weight' => -20, ); @@ -869,11 +871,11 @@ function field_ui_field_edit_form($form, &$form_state, $instance) { ); $form['instance']['widget']['active'] = array( '#type' => 'value', - '#value' => !empty($field['instance']['widget']['active']) ? 1 : 0, + '#value' => !empty($instance['widget']['active']) ? 1 : 0, // straight bug ? ); // Add additional field instance settings from the field module. - $additions = module_invoke($field['module'], 'field_instance_settings_form', $field, $instance, $form_state); + $additions = module_invoke($field->module, 'field_instance_settings_form', $field, $instance, $form_state); if (is_array($additions)) { $form['instance']['settings'] = $additions; $form['instance']['settings']['#weight'] = 10; @@ -919,7 +921,7 @@ function field_ui_field_edit_form_delete_submit($form, &$form_state) { * Builds the default value widget for a given field instance. */ function field_ui_default_value_widget($field, $instance, &$form, &$form_state) { - $field_name = $field['field_name']; + $field_name = $field->field_name; $entity = $form['#entity']; $element = array( @@ -971,7 +973,7 @@ function field_ui_field_edit_form_validate($form, &$form_state) { // Validate the value. $errors = array(); - $function = $field['module'] . '_field_validate'; + $function = $field->module . '_field_validate'; if (function_exists($function)) { $function(NULL, $field, $instance, LANGUAGE_NOT_SPECIFIED, $items, $errors); } diff --git a/core/modules/field_ui/field_ui.api.php b/core/modules/field_ui/field_ui.api.php index eb72e04..d3acc14 100644 --- a/core/modules/field_ui/field_ui.api.php +++ b/core/modules/field_ui/field_ui.api.php @@ -36,7 +36,7 @@ * The form definition for the field settings. */ function hook_field_settings_form($field, $instance, $has_data) { - $settings = $field['settings']; + $settings = $field->settings; $form['max_length'] = array( '#type' => 'number', '#title' => t('Maximum length'), @@ -76,7 +76,7 @@ function hook_field_instance_settings_form($field, $instance, $form_state) { t('Filtered text (user selects text format)'), ), ); - if ($field['type'] == 'text_with_summary') { + if ($field->type == 'text_with_summary') { $form['display_summary'] = array( '#type' => 'select', '#title' => t('Display summary'), diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php index 4314fb4..8ba45de 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -110,7 +110,7 @@ public function form(array $form, array &$form_state) { '#region_callback' => 'field_ui_display_overview_row_region', '#js_settings' => array( 'rowHandler' => 'field', - 'defaultFormatter' => $field_types[$field['type']]['default_formatter'], + 'defaultFormatter' => $field_types[$field->type]['default_formatter'], ), 'human_name' => array( '#markup' => check_plain($instance['label']), @@ -148,7 +148,7 @@ public function form(array $form, array &$form_state) { ), ); - $formatter_options = field_ui_formatter_options($field['type']); + $formatter_options = field_ui_formatter_options($field->type); $formatter_options['hidden'] = '<' . t('Hidden') . '>'; $table[$name]['format'] = array( 'type' => array( diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php index a977df9..d1fd53a 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -134,7 +134,7 @@ public function form(array $form, array &$form_state) { ), 'type' => array( '#type' => 'link', - '#title' => t($field_types[$field['type']]['label']), + '#title' => t($field_types[$field->type]['label']), '#href' => $admin_field_path . '/field-settings', '#options' => array('attributes' => array('title' => t('Edit field settings.'))), ), @@ -522,7 +522,7 @@ protected function validateAddExisting(array $form, array &$form_state) { } // Wrong widget type. elseif ($field['field_name'] && ($existing_field = field_info_field($field['field_name']))) { - $widget_types = field_ui_widget_type_options($existing_field['type']); + $widget_types = field_ui_widget_type_options($existing_field->type); if (!isset($widget_types[$field['widget_type']])) { form_set_error('fields][_add_existing_field][widget_type', t('Re-use existing field: invalid widget.')); } @@ -583,23 +583,23 @@ public function submit(array $form, array &$form_state) { // Create the field and instance. try { - field_create_field($field); + $field = field_create_field($field); field_create_instance($instance); // Make sure the field is displayed in the 'default' view mode (using // default formatter and settings). It stays hidden for other view // modes until it is explicitly configured. entity_get_display($this->entity_type, $this->bundle, 'default') - ->setComponent($field['field_name']) + ->setComponent($field->field_name) ->save(); // Always show the field settings step, as the cardinality needs to be // configured for new fields. - $destinations[] = $this->adminPath. '/fields/' . $field['field_name'] . '/field-settings'; - $destinations[] = $this->adminPath . '/fields/' . $field['field_name']; + $destinations[] = $this->adminPath. '/fields/' . $field->field_name . '/field-settings'; + $destinations[] = $this->adminPath . '/fields/' . $field->field_name; // Store new field information for any additional submit handlers. - $form_state['fields_added']['_add_new_field'] = $field['field_name']; + $form_state['fields_added']['_add_new_field'] = $field->field_name; } catch (Exception $e) { drupal_set_message(t('There was a problem creating field %label: !message', array('%label' => $instance['label'], '!message' => $e->getMessage())), 'error'); @@ -610,12 +610,12 @@ public function submit(array $form, array &$form_state) { if (!empty($form_values['_add_existing_field']['field_name'])) { $values = $form_values['_add_existing_field']; $field = field_info_field($values['field_name']); - if (!empty($field['locked'])) { + if (!empty($field->locked)) { drupal_set_message(t('The field %label cannot be added because it is locked.', array('%label' => $values['label'])), 'error'); } else { $instance = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => $this->entity_type, 'bundle' => $this->bundle, 'label' => $values['label'], @@ -632,7 +632,7 @@ public function submit(array $form, array &$form_state) { // default formatter and settings). It stays hidden for other view // modes until it is explicitly configured. entity_get_display($this->entity_type, $this->bundle, 'default') - ->setComponent($field['field_name']) + ->setComponent($field->field_name) ->save(); $destinations[] = $this->adminPath . '/fields/' . $instance['field_name']; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index cbc132f..4dc654a 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -229,7 +229,7 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string' field_info_cache_clear(); // Assert field settings. $field = field_info_field($field_name); - $this->assertTrue($field['settings']['test_field_setting'] == $string, 'Field settings were found.'); + $this->assertTrue($field->settings['test_field_setting'] == $string, 'Field settings were found.'); // Assert instance and widget settings. $instance = field_info_instance($entity_type, $field_name, $bundle); diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index e166b82..15a3531 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -37,8 +37,8 @@ function file_field_info() { * Implements hook_field_settings_form(). */ function file_field_settings_form($field, $instance, $has_data) { - $defaults = field_info_field_settings($field['type']); - $settings = array_merge($defaults, $field['settings']); + $defaults = field_info_field_settings($field->type); + $settings = array_merge($defaults, $field->settings); $form['#attached']['library'][] = array('file', 'drupal.file'); @@ -250,8 +250,8 @@ function file_field_update(EntityInterface $entity, $field, $instance, $langcode // Compare the original field values with the ones that are being saved. $original = $entity->original; $original_fids = array(); - if (!empty($original->{$field['field_name']}[$langcode])) { - foreach ($original->{$field['field_name']}[$langcode] as $original_item) { + if (!empty($original->{$field->field_name}[$langcode])) { + foreach ($original->{$field->field_name}[$langcode] as $original_item) { $original_fids[] = $original_item['fid']; if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids)) { // Decrement the file usage count by 1. @@ -307,7 +307,7 @@ function file_field_is_empty($item, $field) { * Boolean TRUE if the file will be displayed, FALSE if the file is hidden. */ function file_field_displayed($item, $field) { - if (!empty($field['settings']['display_field'])) { + if (!empty($field->settings['display_field'])) { return (bool) $item['display']; } return TRUE; @@ -364,7 +364,7 @@ function file_field_widget_uri($field, $instance, $data = array()) { // Replace tokens. $destination = token_replace($destination, $data); - return $field['settings']['uri_scheme'] . '://' . $destination; + return $field->settings['uri_scheme'] . '://' . $destination; } /** @@ -378,7 +378,7 @@ function file_field_widget_value($element, $input = FALSE, $form_state) { // If the display field is present make sure its unchecked value is saved. $field = field_widget_field($element, $form_state); if (empty($input['display'])) { - $input['display'] = $field['settings']['display_field'] ? 0 : 1; + $input['display'] = $field->settings['display_field'] ? 0 : 1; } } @@ -413,11 +413,11 @@ function file_field_widget_process($element, &$form_state, $form) { $element['#theme'] = 'file_widget'; // Add the display field if enabled. - if (!empty($field['settings']['display_field']) && $item['fid']) { + if (!empty($field->settings['display_field']) && $item['fid']) { $element['display'] = array( '#type' => empty($item['fid']) ? 'hidden' : 'checkbox', '#title' => t('Include file in display'), - '#value' => isset($item['display']) ? $item['display'] : $field['settings']['display_default'], + '#value' => isset($item['display']) ? $item['display'] : $field->settings['display_default'], '#attributes' => array('class' => array('file-display')), ); } @@ -442,7 +442,7 @@ function file_field_widget_process($element, &$form_state, $form) { // Adjust the Ajax settings so that on upload and remove of any individual // file, the entire group of file fields is updated together. - if ($field['cardinality'] != 1) { + if ($field->cardinality != 1) { $parents = array_slice($element['#array_parents'], 0, -1); $new_path = 'file/ajax/' . implode('/', $parents) . '/' . $form['form_build_id']['#value']; $field_element = NestedArray::getValue($form, $parents); @@ -767,7 +767,7 @@ function theme_file_upload_help($variables) { * fid, FALSE if it doesn't. */ function file_field_find_file_reference_column($field) { - foreach ($field['foreign keys'] as $data) { + foreach ($field->foreign_keys as $data) { if ($data['table'] == 'file_managed') { foreach ($data['columns'] as $field_column => $column) { if ($column == 'fid') { diff --git a/core/modules/file/file.install b/core/modules/file/file.install index 27a2438..472f7e5 100644 --- a/core/modules/file/file.install +++ b/core/modules/file/file.install @@ -125,8 +125,8 @@ function file_schema() { ), 'id' => array( 'description' => 'The primary key of the object using the file.', - 'type' => 'int', - 'unsigned' => TRUE, + 'type' => 'varchar', + 'length' => 64, 'not null' => TRUE, 'default' => 0, ), @@ -234,6 +234,21 @@ function file_requirements($phase) { } /** + * Implements hook_update_dependencies(). + */ +function file_update_dependencies() { + // The update hook to convert the id column in the column table needs to be + // the first one because user update hooks will be called during system + // update hooks due to other dependencies and the user picture conversion + // might need to save a default image and the field it's stored in, does + // not have an integer id anymore. + $dependencies['system'][8001] = array( + 'file' => 8001, + ); + return $dependencies; +} + +/** * Converts default_file_main variable to config. * * @ingroup config_upgrade @@ -245,3 +260,17 @@ function file_update_8000() { 'file_icon_directory'=>'icon.directory', )); } + +/** + * Convert the id column in file_usage to store UUID's. + */ +function file_update_8001() { + $spec = array( + 'description' => 'The primary key of the object using the file.', + 'type' => 'varchar', + 'length' => 64, + 'not null' => TRUE, + 'default' => '', + ); + db_change_field('file_usage', 'id', 'id', $spec); +} diff --git a/core/modules/file/file.module b/core/modules/file/file.module index 913f75a..593ff00 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1539,12 +1539,12 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R $current_field = field_info_field($field_name); // If this is the first time this field type is seen, check // whether it references files. - if (!isset($field_columns[$current_field['type']])) { - $field_columns[$current_field['type']] = file_field_find_file_reference_column($current_field); + if (!isset($field_columns[$current_field->type])) { + $field_columns[$current_field->type] = file_field_find_file_reference_column($current_field); } // If the field type does reference files then record it. - if ($field_columns[$current_field['type']]) { - $file_fields[$entity_type][$bundle][$field_name] = $field_columns[$current_field['type']]; + if ($field_columns[$current_field->type]) { + $file_fields[$entity_type][$bundle][$field_name] = $field_columns[$current_field->type]; } } } @@ -1575,7 +1575,7 @@ function file_get_file_references(File $file, $field = NULL, $age = FIELD_LOAD_R if ($field || $field_type) { foreach ($return as $field_name => $data) { $current_field = field_info_field($field_name); - if (($field_type && $current_field['type'] != $field_type) || ($field && $field['id'] != $current_field['id'])) { + if (($field_type && $current_field->type != $field_type) || ($field && $field->id != $current_field['id'])) { unset($return[$field_name]); } } diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc index 6b0fb59..a40b68b 100644 --- a/core/modules/file/file.views.inc +++ b/core/modules/file/file.views.inc @@ -455,12 +455,12 @@ function file_field_views_data($field) { $data = field_views_field_default_views_data($field); foreach ($data as $table_name => $table_data) { // Add the relationship only on the fid field. - $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array( + $data[$table_name][$field->field_name . '_fid']['relationship'] = array( 'id' => 'standard', 'base' => 'file_managed', 'entity type' => 'file', 'base field' => 'fid', - 'label' => t('file from !field_name', array('!field_name' => $field['field_name'])), + 'label' => t('file from !field_name', array('!field_name' => $field->field_name)), ); } @@ -473,11 +473,11 @@ function file_field_views_data($field) { * Views integration to provide reverse relationships on file fields. */ function file_field_views_data_views_data_alter(&$data, $field) { - foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($field->bundles as $entity_type => $bundles) { $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $pseudo_field_name = 'reverse_' . $field->field_name . '_' . $entity_type; - list($label, $all_labels) = field_views_field_label($field['field_name']); + list($label, $all_labels) = field_views_field_label($field->field_name); $entity = $entity_info['label']; if ($entity == t('Node')) { $entity = t('Content'); @@ -487,12 +487,12 @@ function file_field_views_data_views_data_alter(&$data, $field) { 'title' => t('@entity using @field', array('@entity' => $entity, '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the file.', array('@entity' => $entity, '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'field table' => _field_sql_storage_tablename($field), - 'field field' => $field['field_name'] . '_fid', + 'field field' => $field->field_name . '_fid', 'base' => $entity_info['base_table'], 'base field' => $entity_info['entity_keys']['id'], - 'label' => t('!field_name', array('!field_name' => $field['field_name'])), + 'label' => t('!field_name', array('!field_name' => $field->field_name)), 'join_extra' => array( 0 => array( 'field' => 'entity_type', diff --git a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php index 98a7a96..940c896 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/field/widget/FileWidget.php @@ -57,7 +57,7 @@ public function settingsForm(array $form, array &$form_state) { protected function formMultipleElements(EntityInterface $entity, array $items, $langcode, array &$form, array &$form_state) { $field = $this->field; $instance = $this->instance; - $field_name = $field['field_name']; + $field_name = $field->field_name; $parents = $form['#parents']; @@ -70,15 +70,15 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ } // Determine the number of widgets to display. - switch ($field['cardinality']) { + switch ($field->cardinality) { case FIELD_CARDINALITY_UNLIMITED: $max = count($items); $is_multiple = TRUE; break; default: - $max = $field['cardinality'] - 1; - $is_multiple = ($field['cardinality'] > 1); + $max = $field->cardinality - 1; + $is_multiple = ($field->cardinality > 1); break; } @@ -120,8 +120,8 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ } } - $empty_single_allowed = ($this->field['cardinality'] == 1 && $delta == 0); - $empty_multiple_allowed = ($this->field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta < $this->field['cardinality']) && empty($form_state['programmed']); + $empty_single_allowed = ($this->field->cardinality == 1 && $delta == 0); + $empty_multiple_allowed = ($this->field->cardinality == FIELD_CARDINALITY_UNLIMITED || $delta < $this->field->cardinality) && empty($form_state['programmed']); // Add one more empty row for new uploads except when this is a programmed // multiple form as it is not necessary. @@ -149,7 +149,7 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ $elements['#description'] = $description; $elements['#field_name'] = $element['#field_name']; $elements['#language'] = $element['#language']; - $elements['#display_field'] = !empty($this->field['settings']['display_field']); + $elements['#display_field'] = !empty($this->field->settings['display_field']); // Add some properties that will eventually be added to the file upload // field. These are added here so that they may be referenced easily @@ -167,7 +167,7 @@ protected function formMultipleElements(EntityInterface $entity, array $items, $ public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { $defaults = array( 'fid' => 0, - 'display' => !empty($this->field['settings']['display_default']), + 'display' => !empty($this->field->settings['display_default']), 'description' => '', ); diff --git a/core/modules/file/tests/file_module_test.module b/core/modules/file/tests/file_module_test.module index b962e2a..56ce681 100644 --- a/core/modules/file/tests/file_module_test.module +++ b/core/modules/file/tests/file_module_test.module @@ -76,7 +76,7 @@ function file_module_test_form_submit($form, &$form_state) { * Implements hook_file_download_access(). */ function file_module_test_file_download_access($field, EntityInterface $entity, File $file) { - $instance = field_info_instance($entity->entityType(), $field['field_name'], $entity->bundle()); + $instance = field_info_instance($entity->entityType(), $field->field_name, $entity->bundle()); // Allow the file to be downloaded only if the given arguments are correct. // If any are wrong, $instance will be NULL. if (empty($instance)) { diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index b1e63de..3173cfb 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -22,10 +22,6 @@ function forum_install() { * Implements hook_enable(). */ function forum_enable() { - // If we enable forum at the same time as taxonomy we need to call - // field_associate_fields() as otherwise the field won't be enabled until - // hook modules_enabled is called which takes place after hook_enable events. - field_associate_fields('taxonomy'); // Create the forum vocabulary if it does not exist. // @todo Change Forum module so forum.settings can contain the vocabulary's @@ -55,7 +51,7 @@ function forum_enable() { } // Create the 'taxonomy_forums' field if it doesn't already exist. - if (!field_info_field('taxonomy_forums')) { + if (!field_read_field('taxonomy_forums', array('include_inactive' => TRUE))) { $field = array( 'field_name' => 'taxonomy_forums', 'type' => 'taxonomy_term_reference', diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 872eb95..94ab671 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -179,7 +179,7 @@ function forum_menu_local_tasks_alter(&$data, $router_item, $root_path) { $links = array(); // Loop through all bundles for forum taxonomy vocabulary field. $field = field_info_field('taxonomy_forums'); - foreach ($field['bundles']['node'] as $type) { + foreach ($field->bundles['node'] as $type) { if (node_access('create', $type)) { $links[$type] = array( '#theme' => 'menu_local_action', diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index e83d542..6143357 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -42,8 +42,8 @@ function image_field_info() { * Implements hook_field_settings_form(). */ function image_field_settings_form($field, $instance) { - $defaults = field_info_field_settings($field['type']); - $settings = array_merge($defaults, $field['settings']); + $defaults = field_info_field_settings($field->type); + $settings = array_merge($defaults, $field->settings); $scheme_options = array(); foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) { @@ -64,7 +64,7 @@ function image_field_settings_form($field, $instance) { '#title' => t('Default image'), '#type' => 'managed_file', '#description' => t('If no image is uploaded, this image will be shown on display.'), - '#default_value' => $field['settings']['default_image'], + '#default_value' => $field->settings['default_image'], '#upload_location' => $settings['uri_scheme'] . '://default_images/', ); @@ -183,7 +183,7 @@ function image_field_instance_settings_form($field, $instance) { '#type' => 'managed_file', '#description' => t("If no image is uploaded, this image will be shown on display and will override the field's default image."), '#default_value' => $settings['default_image'], - '#upload_location' => $field['settings']['uri_scheme'] . '://default_images/', + '#upload_location' => $field->settings['uri_scheme'] . '://default_images/', ); return $form; @@ -222,8 +222,8 @@ function image_field_prepare_view($entity_type, $entities, $field, $instances, $ $fid = $instances[$id]['settings']['default_image']; } // Otherwise, use the default for the field. - elseif (!empty($field['settings']['default_image'])) { - $fid = $field['settings']['default_image']; + elseif (!empty($field->settings['default_image'])) { + $fid = $field->settings['default_image']; } // Add the default image if one is found. diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 956eafd..087ee3c 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -397,12 +397,12 @@ function image_image_style_delete(ImageStyle $style) { * Implements hook_field_delete_field(). */ function image_field_delete_field($field) { - if ($field['type'] != 'image') { + if ($field->type != 'image') { return; } // The value of a managed_file element can be an array if #extended == TRUE. - $fid = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']); + $fid = (is_array($field->settings['default_image']) ? $field->settings['default_image']['fid'] : $field->settings['default_image']); if ($fid && ($file = file_load($fid))) { file_usage()->delete($file, 'image', 'default_image', $field['id']); } @@ -412,13 +412,13 @@ function image_field_delete_field($field) { * Implements hook_field_update_field(). */ function image_field_update_field($field, $prior_field, $has_data) { - if ($field['type'] != 'image') { + if ($field->type != 'image') { return; } // The value of a managed_file element can be an array if #extended == TRUE. - $fid_new = (is_array($field['settings']['default_image']) ? $field['settings']['default_image']['fid'] : $field['settings']['default_image']); - $fid_old = (is_array($prior_field['settings']['default_image']) ? $prior_field['settings']['default_image']['fid'] : $prior_field['settings']['default_image']); + $fid_new = (is_array($field->settings['default_image']) ? $field->settings['default_image']['fid'] : $field->settings['default_image']); + $fid_old = (is_array($prior_field->settings['default_image']) ? $prior_field->settings['default_image']['fid'] : $prior_field->settings['default_image']); $file_new = $fid_new ? file_load($fid_new) : FALSE; @@ -428,18 +428,18 @@ function image_field_update_field($field, $prior_field, $has_data) { if ($file_new) { $file_new->status = FILE_STATUS_PERMANENT; $file_new->save(); - file_usage()->add($file_new, 'image', 'default_image', $field['id']); + file_usage()->add($file_new, 'image', 'default_image', $field->id()); } // Is there an old file? if ($fid_old && ($file_old = file_load($fid_old))) { - file_usage()->delete($file_old, 'image', 'default_image', $field['id']); + file_usage()->delete($file_old, 'image', 'default_image', $field->id()); } } // If the upload destination changed, then move the file. - if ($file_new && (file_uri_scheme($file_new->uri) != $field['settings']['uri_scheme'])) { - $directory = $field['settings']['uri_scheme'] . '://default_images/'; + if ($file_new && (file_uri_scheme($file_new->uri) != $field->settings['uri_scheme'])) { + $directory = $field->settings['uri_scheme'] . '://default_images/'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY); file_move($file_new, $directory . $file_new->filename); } @@ -451,7 +451,7 @@ function image_field_update_field($field, $prior_field, $has_data) { function image_field_delete_instance($instance) { // Only act on image fields. $field = field_read_field($instance['field_name']); - if ($field['type'] != 'image') { + if ($field->type != 'image') { return; } @@ -474,7 +474,7 @@ function image_field_delete_instance($instance) { function image_field_update_instance($instance, $prior_instance) { // Only act on image fields. $field = field_read_field($instance['field_name']); - if ($field['type'] != 'image') { + if ($field->type != 'image') { return; } @@ -505,8 +505,8 @@ function image_field_update_instance($instance, $prior_instance) { } // If the upload destination changed, then move the file. - if ($file_new && (file_uri_scheme($file_new->uri) != $field['settings']['uri_scheme'])) { - $directory = $field['settings']['uri_scheme'] . '://default_images/'; + if ($file_new && (file_uri_scheme($file_new->uri) != $field->settings['uri_scheme'])) { + $directory = $field->settings['uri_scheme'] . '://default_images/'; file_prepare_directory($directory, FILE_CREATE_DIRECTORY); file_move($file_new, $directory . $file_new->filename); } diff --git a/core/modules/image/image.views.inc b/core/modules/image/image.views.inc index 77c4ea3..2402a9c 100644 --- a/core/modules/image/image.views.inc +++ b/core/modules/image/image.views.inc @@ -19,11 +19,11 @@ function image_field_views_data($field) { $data = field_views_field_default_views_data($field); foreach ($data as $table_name => $table_data) { // Add the relationship only on the fid field. - $data[$table_name][$field['field_name'] . '_fid']['relationship'] = array( + $data[$table_name][$field->field_name . '_fid']['relationship'] = array( 'id' => 'standard', 'base' => 'file_managed', 'base field' => 'fid', - 'label' => t('image from !field_name', array('!field_name' => $field['field_name'])), + 'label' => t('image from !field_name', array('!field_name' => $field->field_name)), ); } @@ -36,11 +36,11 @@ function image_field_views_data($field) { * Views integration to provide reverse relationships on image fields. */ function image_field_views_data_views_data_alter(&$data, $field) { - foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($field->bundles as $entity_type => $bundles) { $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $pseudo_field_name = 'reverse_' . $field->field_name . '_' . $entity_type; - list($label, $all_labels) = field_views_field_label($field['field_name']); + list($label, $all_labels) = field_views_field_label($field->field_name); $entity = $entity_info['label']; if ($entity == t('Node')) { $entity = t('Content'); @@ -50,12 +50,12 @@ function image_field_views_data_views_data_alter(&$data, $field) { 'title' => t('@entity using @field', array('@entity' => $entity, '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the image.', array('@entity' => $entity, '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'field table' => _field_sql_storage_tablename($field), - 'field field' => $field['field_name'] . '_fid', + 'field field' => $field->field_name . '_fid', 'base' => $entity_info['base_table'], 'base field' => $entity_info['entity_keys']['id'], - 'label' => t('!field_name', array('!field_name' => $field['field_name'])), + 'label' => t('!field_name', array('!field_name' => $field->field_name)), 'join_extra' => array( 0 => array( 'field' => 'entity_type', diff --git a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php index 35cb3fa..6773aa7 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php +++ b/core/modules/image/lib/Drupal/image/Plugin/field/widget/ImageWidget.php @@ -59,7 +59,7 @@ public function settingsForm(array $form, array &$form_state) { protected function formMultipleElements(EntityInterface $entity, array $items, $langcode, array &$form, array &$form_state) { $elements = parent::formMultipleElements($entity, $items, $langcode, $form, $form_state); - if ($this->field['cardinality'] == 1) { + if ($this->field->cardinality == 1) { // If there's only one field, return it as delta 0. if (empty($elements[0]['#default_value']['fid'])) { $elements[0]['#description'] = theme('file_upload_help', array('description' => $this->instance['description'], 'upload_validators' => $elements[0]['#upload_validators'])); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index 01fa5f4..73a2429 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -57,7 +57,7 @@ function testDefaultImages() { // Add another instance with another default image to the page content type. $instance2 = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => 'node', 'bundle' => 'page', 'label' => $instance['label'], @@ -70,7 +70,7 @@ function testDefaultImages() { field_create_instance($instance2); $instance2 = field_info_instance('node', $field_name, 'page'); entity_get_display('node', 'page', 'default') - ->setComponent($field['field_name']) + ->setComponent($field->field_name) ->save(); // Confirm the defaults are present on the article field settings form. @@ -140,7 +140,7 @@ function testDefaultImages() { ); // Upload a new default for the field. - $field['settings']['default_image'] = $default_images['field_new']->fid; + $field->settings['default_image'] = $default_images['field_new']->fid; field_update_field($field); // Confirm that the new default is used on the article field settings form. diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 7c42a5b..1df0930 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -146,8 +146,8 @@ function testImageFieldSettings() { $widget_settings = array( 'preview_image_style' => 'medium', ); - $field = $this->createImageField($field_name, 'article', array(), $instance_settings, $widget_settings); - $field['deleted'] = 0; + $this->createImageField($field_name, 'article', array(), $instance_settings, $widget_settings); + $field = field_info_field($field_name); $table = _field_sql_storage_tablename($field); $schema = drupal_get_schema($table, TRUE); $instance = field_info_instance('node', $field_name, 'article'); @@ -233,7 +233,7 @@ function testImageFieldDefaultImage() { // Clear field info cache so the new default image is detected. field_info_cache_clear(); $field = field_info_field($field_name); - $image = file_load($field['settings']['default_image']); + $image = file_load($field->settings['default_image']); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); $default_output = theme('image', array('uri' => $image->uri)); $this->drupalGet('node/' . $node->nid); @@ -261,7 +261,7 @@ function testImageFieldDefaultImage() { // Clear field info cache so the new default image is detected. field_info_cache_clear(); $field = field_info_field($field_name); - $this->assertFalse($field['settings']['default_image'], 'Default image removed from field.'); + $this->assertFalse($field->settings['default_image'], 'Default image removed from field.'); // Create an image field that uses the private:// scheme and test that the // default image works as expected. $private_field_name = strtolower($this->randomName()); @@ -275,7 +275,7 @@ function testImageFieldDefaultImage() { field_info_cache_clear(); $private_field = field_info_field($private_field_name); - $image = file_load($private_field['settings']['default_image']); + $image = file_load($private_field->settings['default_image']); $this->assertEqual('private', file_uri_scheme($image->uri), 'Default image uses private:// scheme.'); $this->assertTrue($image->status == FILE_STATUS_PERMANENT, 'The default image status is permanent.'); // Create a new node with no image attached and ensure that default private diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index a608873..8c528cc 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -48,9 +48,9 @@ function testURLValidation() { 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'settings' => array( @@ -65,7 +65,7 @@ function testURLValidation() { ); field_create_instance($this->instance); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->field_name, array( 'type' => 'link', )) ->save(); @@ -74,13 +74,13 @@ function testURLValidation() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'Link URL field is displayed'); + $this->assertFieldByName("{$this->field->field_name}[$langcode][0][url]", '', 'Link URL field is displayed'); $this->assertRaw('placeholder="http://example.com"'); // Verify that a valid URL can be submitted. $value = 'http://www.example.com/'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $value, + "{$this->field->field_name}[$langcode][0][url]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -100,7 +100,7 @@ function testURLValidation() { $this->drupalGet('test-entity/add/test_bundle'); foreach ($wrong_entries as $invalid_value) { $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $invalid_value, + "{$this->field->field_name}[$langcode][0][url]" => $invalid_value, ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertText(t('The URL @url is not valid.', array('@url' => $invalid_value))); @@ -116,9 +116,9 @@ function testLinkTitle() { 'field_name' => drupal_strtolower($this->randomName()), 'type' => 'link', ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'settings' => array( @@ -134,7 +134,7 @@ function testLinkTitle() { ); field_create_instance($this->instance); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->field_name, array( 'type' => 'link', 'label' => 'hidden', )) @@ -150,28 +150,28 @@ function testLinkTitle() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'URL field found.'); + $this->assertFieldByName("{$this->field->field_name}[$langcode][0][url]", '', 'URL field found.'); $this->assertRaw('placeholder="http://example.com"'); if ($title_setting === DRUPAL_DISABLED) { - $this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Title field not found.'); + $this->assertNoFieldByName("{$this->field->field_name}[$langcode][0][title]", '', 'Title field not found.'); $this->assertNoRaw('placeholder="Enter a title for this link"'); } else { $this->assertRaw('placeholder="Enter a title for this link"'); - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][title]", '', 'Title field found.'); + $this->assertFieldByName("{$this->field->field_name}[$langcode][0][title]", '', 'Title field found.'); if ($title_setting === DRUPAL_REQUIRED) { // Verify that the title is required, if the URL is non-empty. $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com', + "{$this->field->field_name}[$langcode][0][url]" => 'http://www.example.com', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertText(t('!name field is required.', array('!name' => t('Title')))); // Verify that the title is not required, if the URL is empty. $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => '', + "{$this->field->field_name}[$langcode][0][url]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertNoText(t('!name field is required.', array('!name' => t('Title')))); @@ -179,8 +179,8 @@ function testLinkTitle() { // Verify that a URL and title meets requirements. $this->drupalGet('test-entity/add/test_bundle'); $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com', - "{$this->field['field_name']}[$langcode][0][title]" => 'Example', + "{$this->field->field_name}[$langcode][0][url]" => 'http://www.example.com', + "{$this->field->field_name}[$langcode][0][title]" => 'Example', ); $this->drupalPost(NULL, $edit, t('Save')); $this->assertNoText(t('!name field is required.', array('!name' => t('Title')))); @@ -191,8 +191,8 @@ function testLinkTitle() { // Verify that a link without title is rendered using the URL as link text. $value = 'http://www.example.com/'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $value, - "{$this->field['field_name']}[$langcode][0][title]" => '', + "{$this->field->field_name}[$langcode][0][url]" => $value, + "{$this->field->field_name}[$langcode][0][title]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -206,7 +206,7 @@ function testLinkTitle() { // Verify that a link with title is rendered using the title as link text. $title = $this->randomName(); $edit = array( - "{$this->field['field_name']}[$langcode][0][title]" => $title, + "{$this->field->field_name}[$langcode][0][title]" => $title, ); $this->drupalPost("test-entity/manage/$id/edit", $edit, t('Save')); $this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id))); @@ -226,9 +226,9 @@ function testLinkFormatter() { 'type' => 'link', 'cardinality' => 2, ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'settings' => array( @@ -244,7 +244,7 @@ function testLinkFormatter() { ); field_create_instance($this->instance); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->field_name, $display_options) ->save(); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -261,11 +261,11 @@ function testLinkFormatter() { // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $url1, + "{$this->field->field_name}[$langcode][0][url]" => $url1, // Note that $title1 is not submitted. - "{$this->field['field_name']}[$langcode][0][title]" => '', - "{$this->field['field_name']}[$langcode][1][url]" => $url2, - "{$this->field['field_name']}[$langcode][1][title]" => $title2, + "{$this->field->field_name}[$langcode][0][title]" => '', + "{$this->field->field_name}[$langcode][1][url]" => $url2, + "{$this->field->field_name}[$langcode][1][title]" => $title2, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -298,7 +298,7 @@ function testLinkFormatter() { $display_options['settings'] = $new_value; } entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->field_name, $display_options) ->save(); $this->renderTestEntity($id); @@ -362,9 +362,9 @@ function testLinkSeparateFormatter() { 'type' => 'link', 'cardinality' => 2, ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'settings' => array( @@ -380,7 +380,7 @@ function testLinkSeparateFormatter() { ); field_create_instance($this->instance); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->field_name, $display_options) ->save(); $langcode = LANGUAGE_NOT_SPECIFIED; @@ -396,9 +396,9 @@ function testLinkSeparateFormatter() { // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( - "{$this->field['field_name']}[$langcode][0][url]" => $url1, - "{$this->field['field_name']}[$langcode][1][url]" => $url2, - "{$this->field['field_name']}[$langcode][1][title]" => $title2, + "{$this->field->field_name}[$langcode][0][url]" => $url1, + "{$this->field->field_name}[$langcode][1][url]" => $url2, + "{$this->field->field_name}[$langcode][1][title]" => $title2, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -416,7 +416,7 @@ function testLinkSeparateFormatter() { // Update the field formatter settings. $display_options['settings'] = array($setting => $new_value); entity_get_display('test_entity', 'test_bundle', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($this->field->field_name, $display_options) ->save(); $this->renderTestEntity($id); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php index 6ea519a..05a8c4d 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php @@ -60,7 +60,7 @@ function setUp() { // Make node body translatable. $field = field_info_field('body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; field_update_field($field); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index f2206a0..9c29324 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -590,13 +590,13 @@ function node_add_body_field($type, $label = 'Body') { // Assign display settings for the 'default' and 'teaser' view modes. entity_get_display('node', $type->type, 'default') - ->setComponent($field['field_name'], array( + ->setComponent($field->field_name, array( 'label' => 'hidden', 'type' => 'text_default', )) ->save(); entity_get_display('node', $type->type, 'teaser') - ->setComponent($field['field_name'], array( + ->setComponent($field->field_name, array( 'label' => 'hidden', 'type' => 'text_summary_or_trimmed', )) diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php b/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php index ec9eaf6..88746fd 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/widget/NumberWidget.php @@ -59,9 +59,9 @@ public function formElement(array $items, $delta, array $element, $langcode, arr ); // Set the step for floating point and decimal numbers. - switch ($field['type']) { + switch ($field->type) { case 'number_decimal': - $element['#step'] = pow(0.1, $field['settings']['scale']); + $element['#step'] = pow(0.1, $field->settings['scale']); break; case 'number_float': diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index 925828c..db9ae72 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -52,9 +52,9 @@ function testNumberDecimalField() { 'precision' => 8, 'scale' => 4, 'decimal_separator' => '.', ) ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -71,19 +71,19 @@ function testNumberDecimalField() { ); field_create_instance($this->instance); entity_get_display('test_entity', 'test_bundle', 'default') - ->setComponent($this->field['field_name']) + ->setComponent($this->field->field_name) ->save(); // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); $langcode = LANGUAGE_NOT_SPECIFIED; - $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget is displayed'); + $this->assertFieldByName("{$this->field->field_name}[$langcode][0][value]", '', 'Widget is displayed'); $this->assertRaw('placeholder="0.00"'); // Submit a signed decimal value within the allowed precision and scale. $value = '-1234.5678'; $edit = array( - "{$this->field['field_name']}[$langcode][0][value]" => $value, + "{$this->field->field_name}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); @@ -103,10 +103,10 @@ function testNumberDecimalField() { foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('test-entity/add/test_bundle'); $edit = array( - "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry, + "{$this->field->field_name}[$langcode][0][value]" => $wrong_entry, ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $this->field['field_name'])), 'Correctly failed to save decimal value with more than one decimal point.'); + $this->assertRaw(t('%name must be a number.', array('%name' => $this->field->field_name)), 'Correctly failed to save decimal value with more than one decimal point.'); } // Try to create entries with minus sign not in the first position. @@ -121,10 +121,10 @@ function testNumberDecimalField() { foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('test-entity/add/test_bundle'); $edit = array( - "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry, + "{$this->field->field_name}[$langcode][0][value]" => $wrong_entry, ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t('%name must be a number.', array('%name' => $this->field['field_name'])), 'Correctly failed to save decimal value with minus sign in the wrong position.'); + $this->assertRaw(t('%name must be a number.', array('%name' => $this->field->field_name)), 'Correctly failed to save decimal value with minus sign in the wrong position.'); } } diff --git a/core/modules/number/number.install b/core/modules/number/number.install index 3c4ae7f..4520c95 100644 --- a/core/modules/number/number.install +++ b/core/modules/number/number.install @@ -9,7 +9,7 @@ * Implements hook_field_schema(). */ function number_field_schema($field) { - switch ($field['type']) { + switch ($field->type) { case 'number_integer' : $columns = array( 'value' => array( @@ -32,8 +32,8 @@ function number_field_schema($field) { $columns = array( 'value' => array( 'type' => 'numeric', - 'precision' => $field['settings']['precision'], - 'scale' => $field['settings']['scale'], + 'precision' => $field->settings['precision'], + 'scale' => $field->settings['scale'], 'not null' => FALSE ), ); diff --git a/core/modules/number/number.module b/core/modules/number/number.module index 4615519..00b242b 100644 --- a/core/modules/number/number.module +++ b/core/modules/number/number.module @@ -57,7 +57,7 @@ function number_field_info() { * Implements hook_field_settings_form(). */ function number_field_settings_form($field, $instance, $has_data) { - $settings = $field['settings']; + $settings = $field->settings; $form = array(); if ($field['type'] == 'number_decimal') { @@ -150,12 +150,12 @@ function number_field_validate(EntityInterface $entity = NULL, $field, $instance * Implements hook_field_presave(). */ function number_field_presave(EntityInterface $entity, $field, $instance, $langcode, &$items) { - if ($field['type'] == 'number_decimal') { + if ($field->type == 'number_decimal') { // Let PHP round the value to ensure consistent behavior across storage // backends. foreach ($items as $delta => $item) { if (isset($item['value'])) { - $items[$delta]['value'] = round($item['value'], $field['settings']['scale']); + $items[$delta]['value'] = round($item['value'], $field->settings['scale']); } } } diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index 1027eb1..d628290 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -73,7 +73,7 @@ function testUpdateAllowedValues() { $entity = field_test_create_entity(); $entity->{$this->field_name}[$langcode][0] = array('value' => 1); field_test_entity_save($entity); - $this->field['settings']['allowed_values'] = array(2 => 'Two'); + $this->field->settings['allowed_values'] = array(2 => 'Two'); try { field_update_field($this->field); $this->fail(t('Cannot update a list field to not include keys with existing data.')); @@ -86,7 +86,7 @@ function testUpdateAllowedValues() { field_test_entity_save($entity); // Removed options do not appear. - $this->field['settings']['allowed_values'] = array(2 => 'Two'); + $this->field->settings['allowed_values'] = array(2 => 'Two'); field_update_field($this->field); $entity = field_test_create_entity(); $form = entity_get_form($entity); @@ -95,7 +95,7 @@ function testUpdateAllowedValues() { $this->assertTrue(empty($form[$this->field_name][$langcode][3]), 'Option 3 does not exist'); // Completely new options appear. - $this->field['settings']['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); + $this->field->settings['allowed_values'] = array(10 => 'Update', 20 => 'Twenty'); field_update_field($this->field); $form = entity_get_form($entity); $this->assertTrue(empty($form[$this->field_name][$langcode][1]), 'Option 1 does not exist'); @@ -106,8 +106,8 @@ function testUpdateAllowedValues() { // Options are reset when a new field with the same name is created. field_delete_field($this->field_name); - unset($this->field['id']); - $this->field['settings']['allowed_values'] = array(1 => 'One', 2 => 'Two', 3 => 'Three'); + unset($this->field->id()); + $this->field->settings['allowed_values'] = array(1 => 'One', 2 => 'Two', 3 => 'Three'); $this->field = field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index 3409185..dfd0fd2 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -220,9 +220,9 @@ function testOptionsAllowedValuesBoolean() { $this->assertFieldByName('on', $on, t("The 'On' value is stored correctly.")); $this->assertFieldByName('off', $off, t("The 'Off' value is stored correctly.")); $field = field_info_field($this->field_name); - $this->assertEqual($field['settings']['allowed_values'], $allowed_values, 'The allowed value is correct'); - $this->assertFalse(isset($field['settings']['on']), 'The on value is not saved into settings'); - $this->assertFalse(isset($field['settings']['off']), 'The off value is not saved into settings'); + $this->assertEqual($field->settings['allowed_values'], $allowed_values, 'The allowed value is correct'); + $this->assertFalse(isset($field->settings['on']), 'The on value is not saved into settings'); + $this->assertFalse(isset($field->settings['off']), 'The off value is not saved into settings'); } /** @@ -269,7 +269,7 @@ protected function createOptionsField($type) { * element. * @param $result * Either an expected resulting array in - * $field['settings']['allowed_values'], or an expected error message. + * $field->settings['allowed_values'], or an expected error message. * @param $message * Message to display. */ @@ -283,7 +283,7 @@ function assertAllowedValuesInput($input_string, $result, $message) { else { field_info_cache_clear(); $field = field_info_field($this->field_name); - $this->assertIdentical($field['settings']['allowed_values'], $result, $message); + $this->assertIdentical($field->settings['allowed_values'], $result, $message); } } } diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index 023f012..dd268a2 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -79,7 +79,7 @@ function setUp() { function testRadioButtons() { // Create an instance of the 'single value' field. $instance = array( - 'field_name' => $this->card_1['field_name'], + 'field_name' => $this->card_1->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -119,7 +119,7 @@ function testRadioButtons() { $this->assertFieldValues($entity_init, 'card_1', $langcode, array()); // Check that required radios with one option is auto-selected. - $this->card_1['settings']['allowed_values'] = array(99 => 'Only allowed value'); + $this->card_1->settings['allowed_values'] = array(99 => 'Only allowed value'); field_update_field($this->card_1); $instance['required'] = TRUE; field_update_instance($instance); @@ -133,7 +133,7 @@ function testRadioButtons() { function testCheckBoxes() { // Create an instance of the 'multiple values' field. $instance = array( - 'field_name' => $this->card_2['field_name'], + 'field_name' => $this->card_2->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -206,7 +206,7 @@ function testCheckBoxes() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array()); // Required checkbox with one option is auto-selected. - $this->card_2['settings']['allowed_values'] = array(99 => 'Only allowed value'); + $this->card_2->settings['allowed_values'] = array(99 => 'Only allowed value'); field_update_field($this->card_2); $instance['required'] = TRUE; field_update_instance($instance); @@ -220,7 +220,7 @@ function testCheckBoxes() { function testSelectListSingle() { // Create an instance of the 'single value' field. $instance = array( - 'field_name' => $this->card_1['field_name'], + 'field_name' => $this->card_1->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'required' => TRUE, @@ -282,8 +282,8 @@ function testSelectListSingle() { // Test optgroups. - $this->card_1['settings']['allowed_values'] = array(); - $this->card_1['settings']['allowed_values_function'] = 'options_test_allowed_values_callback'; + $this->card_1->settings['allowed_values'] = array(); + $this->card_1->settings['allowed_values_function'] = 'options_test_allowed_values_callback'; field_update_field($this->card_1); // Display form: with no field data, nothing is selected @@ -317,7 +317,7 @@ function testSelectListSingle() { function testSelectListMultiple() { // Create an instance of the 'multiple values' field. $instance = array( - 'field_name' => $this->card_2['field_name'], + 'field_name' => $this->card_2->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -397,8 +397,8 @@ function testSelectListMultiple() { // Test optgroups. // Use a callback function defining optgroups. - $this->card_2['settings']['allowed_values'] = array(); - $this->card_2['settings']['allowed_values_function'] = 'options_test_allowed_values_callback'; + $this->card_2->settings['allowed_values'] = array(); + $this->card_2->settings['allowed_values_function'] = 'options_test_allowed_values_callback'; field_update_field($this->card_2); $instance['required'] = FALSE; field_update_instance($instance); @@ -434,7 +434,7 @@ function testSelectListMultiple() { function testOnOffCheckbox() { // Create an instance of the 'boolean' field. $instance = array( - 'field_name' => $this->bool['field_name'], + 'field_name' => $this->bool->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -482,10 +482,10 @@ function testOnOffCheckbox() { // Create a test field instance. $fieldUpdate = $this->bool; - $fieldUpdate['settings']['allowed_values'] = array(0 => 0, 1 => 'MyOnValue'); + $fieldUpdate->settings['allowed_values'] = array(0 => 0, 1 => 'MyOnValue'); field_update_field($fieldUpdate); $instance = array( - 'field_name' => $this->bool['field_name'], + 'field_name' => $this->bool->field_name, 'entity_type' => 'node', 'bundle' => 'page', 'widget' => array( @@ -505,7 +505,7 @@ function testOnOffCheckbox() { ); $this->assertFieldByXPath( - '*//label[@for="edit-' . $this->bool['field_name'] . '-und" and text()="MyOnValue"]', + '*//label[@for="edit-' . $this->bool->field_name . '-und" and text()="MyOnValue"]', TRUE, t('Default case shows "On value"') ); @@ -527,7 +527,7 @@ function testOnOffCheckbox() { t('Display settings checkbox checked') ); $this->assertFieldByXPath( - '*//label[@for="edit-' . $this->bool['field_name'] . '-und" and text()="' . $this->bool['field_name'] . '"]', + '*//label[@for="edit-' . $this->bool->field_name . '-und" and text()="' . $this->bool->field_name . '"]', TRUE, t('Display label changes label of the checkbox') ); diff --git a/core/modules/options/options.api.php b/core/modules/options/options.api.php index 2a303d5..6bdda32 100644 --- a/core/modules/options/options.api.php +++ b/core/modules/options/options.api.php @@ -58,7 +58,7 @@ function hook_options_list($field, $instance, $entity) { // In actual implementations, the array of options will most probably depend // on properties of the field. Example from taxonomy.module: $options = array(); - foreach ($field['settings']['allowed_values'] as $tree) { + foreach ($field->settings['allowed_values'] as $tree) { $terms = taxonomy_get_tree($tree['vid'], $tree['parent'], NULL, TRUE); if ($terms) { foreach ($terms as $term) { diff --git a/core/modules/options/options.install b/core/modules/options/options.install index 6c2c8af..ae08db2 100644 --- a/core/modules/options/options.install +++ b/core/modules/options/options.install @@ -9,7 +9,7 @@ * Implements hook_field_schema(). */ function options_field_schema($field) { - switch ($field['type']) { + switch ($field->type) { case 'list_text': $columns = array( 'value' => array( diff --git a/core/modules/options/options.module b/core/modules/options/options.module index f1639ca..0848b25 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -73,9 +73,9 @@ function options_field_info() { * Implements hook_field_settings_form(). */ function options_field_settings_form($field, $instance, $has_data) { - $settings = $field['settings']; + $settings = $field->settings; - switch ($field['type']) { + switch ($field->type) { case 'list_integer': case 'list_float': case 'list_text': @@ -87,12 +87,12 @@ function options_field_settings_form($field, $instance, $has_data) { '#element_validate' => array('options_field_settings_form_validate_allowed_values'), '#field_has_data' => $has_data, '#field' => $field, - '#field_type' => $field['type'], + '#field_type' => $field->type, '#access' => empty($settings['allowed_values_function']), ); $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - if ($field['type'] == 'list_integer' || $field['type'] == 'list_float') { + if ($field->type == 'list_integer' || $field->type == 'list_float') { $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); @@ -175,10 +175,10 @@ function options_field_settings_form($field, $instance, $has_data) { function options_field_settings_form_validate_allowed_values($element, &$form_state) { $field = $element['#field']; $has_data = $element['#field_has_data']; - $field_type = $field['type']; + $field_type = $field->type; $generate_keys = ($field_type == 'list_integer' || $field_type == 'list_float') && !$has_data; - $values = options_extract_allowed_values($element['#value'], $field['type'], $generate_keys); + $values = options_extract_allowed_values($element['#value'], $field->type, $generate_keys); if (!is_array($values)) { form_error($element, t('Allowed values list: invalid input.')); @@ -202,7 +202,7 @@ function options_field_settings_form_validate_allowed_values($element, &$form_st // Prevent removing values currently in use. if ($has_data) { - $lost_keys = array_diff(array_keys($field['settings']['allowed_values']), array_keys($values)); + $lost_keys = array_diff(array_keys($field->settings['allowed_values']), array_keys($values)); if (_options_values_in_use($field, $lost_keys)) { form_error($element, t('Allowed values list: some values are being removed while currently in use.')); } @@ -248,8 +248,8 @@ function options_field_update_field($field, $prior_field, $has_data) { function options_allowed_values($field, $instance = NULL, EntityInterface $entity = NULL) { $allowed_values = &drupal_static(__FUNCTION__, array()); - if (!isset($allowed_values[$field['id']])) { - $function = $field['settings']['allowed_values_function']; + if (!isset($allowed_values[$field->id()])) { + $function = $field->settings['allowed_values_function']; // If $cacheable is FALSE, then the allowed values are not statically // cached. See options_test_dynamic_values_callback() for an example of // generating dynamic and uncached values. @@ -258,18 +258,18 @@ function options_allowed_values($field, $instance = NULL, EntityInterface $entit $values = $function($field, $instance, $entity, $cacheable); } else { - $values = $field['settings']['allowed_values']; + $values = $field->settings['allowed_values']; } if ($cacheable) { - $allowed_values[$field['id']] = $values; + $allowed_values[$field->id()] = $values; } else { return $values; } } - return $allowed_values[$field['id']]; + return $allowed_values[$field->id()]; } /** @@ -370,11 +370,11 @@ function options_allowed_values_string($values) { * Implements hook_field_update_forbid(). */ function options_field_update_forbid($field, $prior_field, $has_data) { - if ($field['module'] == 'options' && $has_data) { + if ($field->module == 'options' && $has_data) { // Forbid any update that removes allowed values with actual data. - $lost_keys = array_diff(array_keys($prior_field['settings']['allowed_values']), array_keys($field['settings']['allowed_values'])); + $lost_keys = array_diff(array_keys($prior_field->settings['allowed_values']), array_keys($field->settings['allowed_values'])); if (_options_values_in_use($field, $lost_keys)) { - throw new FieldUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field['field_name']))); + throw new FieldUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field->field_name))); } } } @@ -384,11 +384,11 @@ function options_field_update_forbid($field, $prior_field, $has_data) { */ function _options_values_in_use($field, $values) { if ($values) { - $field = field_info_field_by_id($field['id']); + $field = field_info_field_by_id($field->id()); $factory = drupal_container()->get('entity.query'); - foreach ($field['bundles'] as $entity_type => $bundle) { + foreach ($field->bundles as $entity_type => $bundle) { $result = $factory->get($entity_type) - ->condition($field['field_name'] . '.value', $values) + ->condition($field->field_name . '.value', $values) ->count() ->accessCheck(FALSE) ->range(0, 1) @@ -413,7 +413,7 @@ function options_field_validate(EntityInterface $entity = NULL, $field, $instanc foreach ($items as $delta => $item) { if (!empty($item['value'])) { if (!empty($allowed_values) && !isset($allowed_values[$item['value']])) { - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$field->field_name][$langcode][$delta][] = array( 'error' => 'list_illegal_value', 'message' => t('%name: illegal value.', array('%name' => $instance['label'])), ); @@ -473,10 +473,13 @@ function options_field_widget_info() { function options_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) { // Abstract over the actual field columns, to allow different field types to // reuse those widgets. - $value_key = key($field['columns']); + + // Reset internal pointer since we're dealing with objects now. + reset($field->columns); + $value_key = key($field->columns); $type = str_replace('options_', '', $instance['widget']['type']); - $multiple = $field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED; + $multiple = $field->cardinality > 1 || $field->cardinality == FIELD_CARDINALITY_UNLIMITED; $required = $element['#required']; $has_value = isset($items[0][$value_key]); $properties = _options_properties($type, $multiple, $required, $has_value); @@ -656,7 +659,7 @@ function _options_properties($type, $multiple, $required, $has_value) { */ function _options_get_options($field, $instance, $properties, EntityInterface $entity) { // Get the list of options. - $options = (array) module_invoke($field['module'], 'options_list', $field, $instance, $entity); + $options = (array) module_invoke($field->module, 'options_list', $field, $instance, $entity); // Sanitize the options. _options_prepare_options($options, $properties); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php index e534971..1ef20ff 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchMultilingualEntityTest.php @@ -49,7 +49,7 @@ function setUp() { // Make the body field translatable. // The parent class has already created the article and page content types. $field = field_info_field('body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; field_update_field($field); // Create a few page nodes with multilingual body values. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index 1882e6f..093af8a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -75,7 +75,7 @@ function setUp() { field_test_create_bundle($bundle); foreach ($fields as $field) { $instance = array( - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'entity_type' => 'test_entity', 'bundle' => $bundle, ); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php index bb3ac2c..a176f5b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -106,10 +106,10 @@ function testEntityFormLanguage() { // Make body translatable. $field = field_info_field('body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; field_update_field($field); $field = field_info_field('body'); - $this->assertTrue($field['translatable'], 'Field body is translatable.'); + $this->assertTrue($field->translatable, 'Field body is translatable.'); // Create a body translation and check the form language. $langcode2 = $this->langcodes[1]; diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php index c0de21b..89cac76 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -87,4 +87,16 @@ public function testEntityDisplayUpgrade() { $this->assertEqual($displays['teaser']['content']['language'], $expected['teaser']); } + /** + * Tests upgrade of fields and instances to config. + */ + function testFieldUpgradeToConfig() { + $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.')); + + // Assert the body field and instance on the article are converted. + $body_field = field_info_field('body'); + $this->assertNotNull($body_field, 'The body field has been found.'); + $body_field_instance = field_info_instance('node', 'body', 'article'); + $this->assertNotNull($body_field, 'The body field instance on the article content type has been found.'); + } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php index 04070c9..1314ecd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php @@ -51,7 +51,7 @@ public function testUserPictureUpgrade() { // Check file usage for the default image. $usage = file_usage()->listUsage($file); $field = field_info_field('user_picture'); - $this->assertEqual(1, $usage['image']['default_image'][$field['id']]); + $this->assertTrue(isset($usage['image']['default_image'][$field->id()])); $this->assertEqual($instance['settings']['max_resolution'], '800x800', 'User picture maximum resolution has been migrated.'); $this->assertEqual($instance['settings']['max_filesize'], '700 KB', 'User picture maximum filesize has been migrated.'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php index 0d5dfd4..ea2019d 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php @@ -57,7 +57,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr $element += array( '#type' => 'textfield', '#default_value' => taxonomy_implode_tags($tags), - '#autocomplete_path' => $this->getSetting('autocomplete_path') . '/' . $field['field_name'], + '#autocomplete_path' => $this->getSetting('autocomplete_path') . '/' . $field->field_name, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), '#maxlength' => 1024, @@ -77,7 +77,7 @@ public function massageFormValues(array $values, array $form, array &$form_state $field = $this->field; // Collect candidate vocabularies. - foreach ($field['settings']['allowed_values'] as $tree) { + foreach ($field->settings['allowed_values'] as $tree) { if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { $vocabularies[$vocabulary->id()] = $vocabulary; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 8c5571c..aab02ff 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -123,7 +123,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { // Verify that field and instance settings are correct. $field_info = field_info_field($this->field_name); - $this->assertEqual(count($field_info['settings']['allowed_values']), 1, 'Only one vocabulary is allowed for the field.'); + $this->assertEqual(count($field_info->settings['allowed_values']), 1, 'Only one vocabulary is allowed for the field.'); // The widget should still be displayed. $this->drupalGet('test-entity/add/test_bundle'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index d5de5fa..13a6534 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -53,7 +53,7 @@ function setUp() { ), ) ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, 'entity_type' => 'test_entity', @@ -141,7 +141,7 @@ function testTaxonomyTermFieldWidgets() { function testTaxonomyTermFieldChangeMachineName() { // Add several entries in the 'allowed_values' setting, to make sure that // they all get updated. - $this->field['settings']['allowed_values'] = array( + $this->field->settings['allowed_values'] = array( array( 'vocabulary' => $this->vocabulary->id(), 'parent' => '0', @@ -163,7 +163,7 @@ function testTaxonomyTermFieldChangeMachineName() { // Check that the field instance is still attached to the vocabulary. $field = field_info_field($this->field_name); - $allowed_values = $field['settings']['allowed_values']; + $allowed_values = $field->settings['allowed_values']; $this->assertEqual($allowed_values[0]['vocabulary'], $new_name, 'Index 0: Machine name was updated correctly.'); $this->assertEqual($allowed_values[1]['vocabulary'], $new_name, 'Index 1: Machine name was updated correctly.'); $this->assertEqual($allowed_values[2]['vocabulary'], 'foo', 'Index 2: Machine name was left untouched.'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index d73302b..e969c15 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -176,7 +176,7 @@ function testUninstallReinstall() { // removed when the module is uninstalled. $this->field_name = drupal_strtolower($this->randomName() . '_field_name'); $this->field = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4); - $this->field = field_create_field($this->field); + field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, 'entity_type' => 'taxonomy_term', @@ -196,7 +196,6 @@ function testUninstallReinstall() { // an instance of this field on the same bundle name should be successful. $this->vocabulary->enforceIsNew(); taxonomy_vocabulary_save($this->vocabulary); - unset($this->field['id']); field_create_field($this->field); field_create_instance($this->instance); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php index b14fc2f..8cb9a58 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyStorageController.php @@ -28,8 +28,8 @@ protected function postSave(EntityInterface $entity, $update) { $fields = field_read_fields(); foreach ($fields as $field_name => $field) { $update_field = FALSE; - if ($field['type'] == 'taxonomy_term_reference') { - foreach ($field['settings']['allowed_values'] as $key => &$value) { + if ($field->type == 'taxonomy_term_reference') { + foreach ($field->settings['allowed_values'] as $key => &$value) { if ($value['vocabulary'] == $entity->getOriginalID()) { $value['vocabulary'] = $entity->id(); $update_field = TRUE; @@ -74,14 +74,14 @@ protected function postDelete($entities) { $modified_field = FALSE; // Term reference fields may reference terms from more than one // vocabulary. - foreach ($taxonomy_field['settings']['allowed_values'] as $key => $allowed_value) { + foreach ($taxonomy_field->settings['allowed_values'] as $key => $allowed_value) { if (isset($vocabularies[$allowed_value['vocabulary']])) { - unset($taxonomy_field['settings']['allowed_values'][$key]); + unset($taxonomy_field->settings['allowed_values'][$key]); $modified_field = TRUE; } } if ($modified_field) { - if (empty($taxonomy_field['settings']['allowed_values'])) { + if (empty($taxonomy_field->settings['allowed_values'])) { field_delete_field($field_name); } else { diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 4b1a2b1..39fe8f7 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -1004,7 +1004,7 @@ function taxonomy_field_widget_info_alter(&$info) { * Implements hook_options_list(). */ function taxonomy_options_list($field, $instance, $entity) { - $function = !empty($field['settings']['options_list_callback']) ? $field['settings']['options_list_callback'] : 'taxonomy_allowed_values'; + $function = !empty($field->settings['options_list_callback']) ? $field->settings['options_list_callback'] : 'taxonomy_allowed_values'; return $function($field, $instance, $entity); } @@ -1036,7 +1036,7 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan $validate = TRUE; if (!empty($item['tid']) && $item['tid'] != 'autocreate') { $validate = FALSE; - foreach ($field['settings']['allowed_values'] as $settings) { + foreach ($field->settings['allowed_values'] as $settings) { // If no parent is specified, check if the term is in the vocabulary. if (isset($settings['vocabulary']) && empty($settings['parent'])) { if ($settings['vocabulary'] == $terms[$item['tid']]->bundle()) { @@ -1058,7 +1058,7 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan } } if (!$validate) { - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$field->field_name][$langcode][$delta][] = array( 'error' => 'taxonomy_term_reference_illegal_value', 'message' => t('%name: illegal value.', array('%name' => $instance['label'])), ); @@ -1171,7 +1171,7 @@ function taxonomy_field_formatter_view(EntityInterface $entity, $field, $instanc */ function taxonomy_allowed_values($field, $instance, EntityInterface $entity) { $options = array(); - foreach ($field['settings']['allowed_values'] as $tree) { + foreach ($field->settings['allowed_values'] as $tree) { if ($vocabulary = taxonomy_vocabulary_load($tree['vocabulary'])) { if ($terms = taxonomy_get_tree($vocabulary->id(), $tree['parent'], NULL, TRUE)) { foreach ($terms as $term) { @@ -1273,7 +1273,7 @@ function taxonomy_field_settings_form($field, $instance, $has_data) { '#tree' => TRUE, ); - foreach ($field['settings']['allowed_values'] as $delta => $tree) { + foreach ($field->settings['allowed_values'] as $delta => $tree) { $form['allowed_values'][$delta]['vocabulary'] = array( '#type' => 'select', '#title' => t('Vocabulary'), @@ -1412,7 +1412,7 @@ function taxonomy_build_node_index($node) { foreach (field_info_instances('node', $node->type) as $instance) { $field_name = $instance['field_name']; $field = field_info_field($field_name); - if ($field['module'] == 'taxonomy' && $field['storage']['type'] == 'field_sql_storage') { + if ($field->module == 'taxonomy' && $field->storage['type'] == 'field_sql_storage') { // If a field value is not set in the node object when node_save() is // called, the old value from $node->original is used. if (isset($node->{$field_name})) { diff --git a/core/modules/taxonomy/taxonomy.pages.inc b/core/modules/taxonomy/taxonomy.pages.inc index fbd29f1..01df0ef 100644 --- a/core/modules/taxonomy/taxonomy.pages.inc +++ b/core/modules/taxonomy/taxonomy.pages.inc @@ -109,7 +109,7 @@ function taxonomy_autocomplete($field_name) { $tags_typed = drupal_container()->get('request')->query->get('q'); // Make sure the field exists and is a taxonomy field. - if (!($field = field_info_field($field_name)) || $field['type'] !== 'taxonomy_term_reference') { + if (!($field = field_info_field($field_name)) || $field->type !== 'taxonomy_term_reference') { // Error string. The JavaScript handler will realize this is not JSON and // will display it as debugging information. print t('Taxonomy field @field_name not found.', array('@field_name' => $field_name)); @@ -125,7 +125,7 @@ function taxonomy_autocomplete($field_name) { // Part of the criteria for the query come from the field's own settings. $vids = array(); - foreach ($field['settings']['allowed_values'] as $tree) { + foreach ($field->settings['allowed_values'] as $tree) { $vids[] = $tree['vocabulary']; } diff --git a/core/modules/taxonomy/taxonomy.views.inc b/core/modules/taxonomy/taxonomy.views.inc index 0644f82..8bbe7ee 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -341,16 +341,16 @@ function taxonomy_field_views_data($field) { foreach ($table_data as $field_name => $field_data) { if (isset($field_data['filter']) && $field_name != 'delta') { $data[$table_name][$field_name]['filter']['id'] = 'taxonomy_index_tid'; - $data[$table_name][$field_name]['filter']['vocabulary'] = $field['settings']['allowed_values'][0]['vocabulary']; + $data[$table_name][$field_name]['filter']['vocabulary'] = $field->settings['allowed_values'][0]['vocabulary']; } } // Add the relationship only on the tid field. - $data[$table_name][$field['field_name'] . '_tid']['relationship'] = array( + $data[$table_name][$field->field_name . '_tid']['relationship'] = array( 'id' => 'standard', 'base' => 'taxonomy_term_data', 'base field' => 'tid', - 'label' => t('term from !field_name', array('!field_name' => $field['field_name'])), + 'label' => t('term from !field_name', array('!field_name' => $field->field_name)), ); } @@ -364,11 +364,11 @@ function taxonomy_field_views_data($field) { * Views integration to provide reverse relationships on term references. */ function taxonomy_field_views_data_views_data_alter(&$data, $field) { - foreach ($field['bundles'] as $entity_type => $bundles) { + foreach ($field->bundles as $entity_type => $bundles) { $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $pseudo_field_name = 'reverse_' . $field->field_name . '_' . $entity_type; - list($label, $all_labels) = field_views_field_label($field['field_name']); + list($label, $all_labels) = field_views_field_label($field->field_name); $entity = $entity_info['label']; if ($entity == t('Node')) { $entity = t('Content'); @@ -378,12 +378,12 @@ function taxonomy_field_views_data_views_data_alter(&$data, $field) { 'title' => t('@entity using @field', array('@entity' => $entity, '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the term.', array('@entity' => $entity, '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'field table' => _field_sql_storage_tablename($field), - 'field field' => $field['field_name'] . '_tid', + 'field field' => $field->field_name . '_tid', 'base' => $entity_info['base_table'], 'base field' => $entity_info['entity_keys']['id'], - 'label' => t('!field_name', array('!field_name' => $field['field_name'])), + 'label' => t('!field_name', array('!field_name' => $field->field_name)), 'join_extra' => array( 0 => array( 'field' => 'entity_type', diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php index 00396ae..427b24c 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/widget/TextfieldWidget.php @@ -58,7 +58,7 @@ public function formElement(array $items, $delta, array $element, $langcode, arr '#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL, '#size' => $this->getSetting('size'), '#placeholder' => $this->getSetting('placeholder'), - '#maxlength' => $this->field['settings']['max_length'], + '#maxlength' => $this->field->settings['max_length'], '#attributes' => array('class' => array('text-full')), ); diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index f8c585b..d6e6eeb 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -57,9 +57,9 @@ function testTextFieldValidation() { 'max_length' => $max_length, ) ); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->field_name, 'entity_type' => 'test_entity', 'bundle' => 'test_bundle', 'widget' => array( @@ -68,14 +68,14 @@ function testTextFieldValidation() { ); field_create_instance($this->instance); entity_get_display('test_entity', 'test_bundle', 'default') - ->setComponent($this->field['field_name']) + ->setComponent($this->field->field_name) ->save(); // Test valid and invalid values with field_attach_validate(). $entity = field_test_create_entity(); $langcode = LANGUAGE_NOT_SPECIFIED; for ($i = 0; $i <= $max_length + 2; $i++) { - $entity->{$this->field['field_name']}[$langcode][0]['value'] = str_repeat('x', $i); + $entity->{$this->field->field_name}[$langcode][0]['value'] = str_repeat('x', $i); try { field_attach_validate($entity); $this->assertTrue($i <= $max_length, "Length $i does not cause validation error when max_length is $max_length"); @@ -102,7 +102,7 @@ function _testTextfieldWidgets($field_type, $widget_type) { $entity_type = 'test_entity'; $this->field_name = drupal_strtolower($this->randomName()); $this->field = array('field_name' => $this->field_name, 'type' => $field_type); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, 'entity_type' => 'test_entity', @@ -165,7 +165,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { $entity_type = 'test_entity'; $this->field_name = drupal_strtolower($this->randomName()); $this->field = array('field_name' => $this->field_name, 'type' => $field_type); - field_create_field($this->field); + $this->field = field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, 'entity_type' => 'test_entity', diff --git a/core/modules/text/text.install b/core/modules/text/text.install index 72d879f..d87d7f7 100644 --- a/core/modules/text/text.install +++ b/core/modules/text/text.install @@ -9,12 +9,12 @@ * Implements hook_field_schema(). */ function text_field_schema($field) { - switch ($field['type']) { + switch ($field->type) { case 'text': $columns = array( 'value' => array( 'type' => 'varchar', - 'length' => $field['settings']['max_length'], + 'length' => $field->settings['max_length'], 'not null' => FALSE, ), ); diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 07c962e..3022fac 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -85,11 +85,11 @@ function text_field_info() { * Implements hook_field_settings_form(). */ function text_field_settings_form($field, $instance, $has_data) { - $settings = $field['settings']; + $settings = $field->settings; $form = array(); - if ($field['type'] == 'text') { + if ($field->type == 'text') { $form['max_length'] = array( '#type' => 'number', '#title' => t('Maximum length'), @@ -121,7 +121,7 @@ function text_field_instance_settings_form($field, $instance) { t('Filtered text (user selects text format)'), ), ); - if ($field['type'] == 'text_with_summary') { + if ($field->type == 'text_with_summary') { $form['display_summary'] = array( '#type' => 'checkbox', '#title' => t('Summary input'), @@ -146,17 +146,17 @@ function text_field_validate(EntityInterface $entity = NULL, $field, $instance, // length can be exceeded very easily. foreach (array('value', 'summary') as $column) { if (!empty($item[$column])) { - if (!empty($field['settings']['max_length']) && drupal_strlen($item[$column]) > $field['settings']['max_length']) { + if (!empty($field->settings['max_length']) && drupal_strlen($item[$column]) > $field->settings['max_length']) { switch ($column) { case 'value': - $message = t('%name: the text may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])); + $message = t('%name: the text may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field->settings['max_length'])); break; case 'summary': - $message = t('%name: the summary may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field['settings']['max_length'])); + $message = t('%name: the summary may not be longer than %max characters.', array('%name' => $instance['label'], '%max' => $field->settings['max_length'])); break; } - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$field->field_name][$langcode][$delta][] = array( 'error' => "text_{$column}_length", 'message' => $message, ); @@ -180,7 +180,7 @@ function text_field_load($entity_type, $entities, $field, $instances, $langcode, // by formatters if needed. if (empty($instances[$id]['settings']['text_processing']) || filter_format_allowcache($item['format'])) { $items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : ''; - if ($field['type'] == 'text_with_summary') { + if ($field->type == 'text_with_summary') { $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : ''; } } @@ -352,7 +352,7 @@ function text_summary($text, $format = NULL, $size = NULL) { function text_field_prepare_translation(EntityInterface $entity, $field, $instance, $langcode, &$items, EntityInterface $source_entity, $source_langcode) { // If the translating user is not permitted to use the assigned text format, // we must not expose the source values. - $field_name = $field['field_name']; + $field_name = $field->field_name; if (!empty($source_entity->{$field_name}[$source_langcode])) { $formats = filter_formats(); foreach ($source_entity->{$field_name}[$source_langcode] as $delta => $item) { diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php index 1dcbc35..7ee8b9f 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php @@ -51,7 +51,7 @@ public function removeTranslation(EntityInterface $entity, $langcode) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field_name = $instance['field_name']; $field = field_info_field($field_name); - if ($field['translatable']) { + if ($field->translatable) { $entity->{$field_name}[$langcode] = array(); } } diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php index 41600ac..9a95330 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php @@ -88,7 +88,7 @@ function testSettingsUI() { ); $this->assertSettings('comment', 'comment_node_article', TRUE, $edit); $field = field_info_field('comment_body'); - $this->assertTrue($field['translatable'], 'Comment body is translatable.'); + $this->assertTrue($field->translatable, 'Comment body is translatable.'); // Test that language settings are correctly stored. $language_configuration = language_get_default_configuration('comment', 'comment_node_article'); diff --git a/core/modules/translation_entity/translation_entity.admin.inc b/core/modules/translation_entity/translation_entity.admin.inc index aca0dd0..6b64995 100644 --- a/core/modules/translation_entity/translation_entity.admin.inc +++ b/core/modules/translation_entity/translation_entity.admin.inc @@ -46,7 +46,7 @@ function _translation_entity_form_language_content_settings_form_alter(array &$f $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array( '#label' => $instance['label'], '#type' => 'checkbox', - '#default_value' => $field['translatable'], + '#default_value' => $field->translatable, ); } } @@ -150,7 +150,7 @@ function _translation_entity_update_field_translatability($settings) { $operations = array(); foreach ($fields as $field_name => $translatable) { $field = field_info_field($field_name); - if ($field['translatable'] != $translatable) { + if ($field->translatable != $translatable) { // If a field is untranslatable, it can have no data except under // LANGUAGE_NOT_SPECIFIED. Thus we need a field to be translatable before // we convert data to the entity language. Conversely we need to switch @@ -187,7 +187,7 @@ function translation_entity_translatable_form(array $form, array &$form_state, $ $t_args = array('%name' => $field_name); $warning = t('By submitting this form these changes will apply to the %name field everywhere it is used.', $t_args); - if ($field['translatable']) { + if ($field->translatable) { $title = t('Are you sure you want to disable translation for the %name field?', $t_args); $warning .= "
" . t("All the existing translations of this field will be deleted.
This action cannot be undone."); } @@ -202,7 +202,7 @@ function translation_entity_translatable_form(array $form, array &$form_state, $ // submits from toggling translatability. $form['translatable'] = array( '#type' => 'hidden', - '#default_value' => $field['translatable'], + '#default_value' => $field->translatable, ); return confirm_form($form, $title, '', $warning); @@ -226,7 +226,7 @@ function translation_entity_translatable_form_submit(array $form, array $form_st $field_name = $form_state['field']['field_name']; $field = field_info_field($field_name); - if ($field['translatable'] !== $translatable) { + if ($field->translatable !== $translatable) { // Field translatability has changed since form creation, abort. $t_args = array('%field_name'); $msg = $translatable ? @@ -273,8 +273,8 @@ function translation_entity_translatable_form_submit(array $form, array $form_st */ function translation_entity_translatable_switch($translatable, $field_name) { $field = field_info_field($field_name); - if ($field['translatable'] !== $translatable) { - $field['translatable'] = $translatable; + if ($field->translatable !== $translatable) { + $field->translatable = $translatable; field_update_field($field); } } @@ -290,7 +290,7 @@ function translation_entity_translatable_switch($translatable, $field_name) { */ function translation_entity_translatable_batch($translatable, $field_name, &$context) { $field = field_info_field($field_name); - $column = isset($field['columns']['value']) ? 'value' : key($field['columns']); + $column = isset($field->columns['value']) ? 'value' : key($field->columns); $query_field = "$field_name.$column"; // Determine the entity types to act on. diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index 0167180..dcbfffe 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -608,7 +608,7 @@ function translation_entity_form_alter(array &$form, array &$form_state) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field_name = $instance['field_name']; $field = field_info_field($field_name); - $form[$field_name]['#multilingual'] = !empty($field['translatable']); + $form[$field_name]['#multilingual'] = !empty($field->translatable); } } } @@ -735,8 +735,8 @@ function translation_entity_field_extra_fields() { */ function translation_entity_form_field_ui_field_settings_form_alter(array &$form, array &$form_state, $form_id) { $field = $form['#field']; - $field_name = $field['field_name']; - $translatable = $field['translatable']; + $field_name = $field->field_name; + $translatable = $field->translatable; $label = t('Field translation'); if (field_has_data($field)) { diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index 11e85e6..30785ff 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -41,7 +41,7 @@ function translation_entity_overview(EntityInterface $entity) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field_name = $instance['field_name']; $field = field_info_field($field_name); - if ($field['translatable']) { + if ($field->translatable) { $translatable = TRUE; break; } @@ -255,7 +255,7 @@ function translation_entity_prepare_translation(EntityInterface $entity, Languag else { foreach ($instances as $field_name => $instance) { $field = field_info_field($field_name); - if (!empty($field['translatable'])) { + if (!empty($field->translatable)) { $value = $entity->get($field_name); $value[$target->langcode] = isset($value[$source->langcode]) ? $value[$source->langcode] : array(); $entity->set($field_name, $value); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 38ca376..8361997 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -199,7 +199,7 @@ function testRegistrationWithUserFields() { 'field_name' => 'test_user_field', 'cardinality' => 1, ); - field_create_field($field); + $field = field_create_field($field); $instance = array( 'field_name' => 'test_user_field', 'entity_type' => 'user', @@ -243,7 +243,7 @@ function testRegistrationWithUserFields() { $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, 'The field value was correclty saved.'); // Check that the 'add more' button works. - $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED; + $field->cardinality = FIELD_CARDINALITY_UNLIMITED; field_update_field($field); foreach (array('js', 'nojs') as $js) { $this->drupalGet('user/register'); diff --git a/core/modules/user/user.install b/core/modules/user/user.install index 9a0b663..afee54b 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -315,10 +315,6 @@ function user_install_picture_field() { 'uri_scheme' => 'public', 'default_image' => FALSE, ), - 'storage' => array( - 'type' => 'field_sql_storage', - 'settings' => array(), - ), ); $field = field_create_field($field); @@ -706,7 +702,7 @@ function user_update_8011() { 'settings' => array(), ), ); - _update_7000_field_create_field($field); + $field = _update_7000_field_create_field($field); $instance = array( 'field_name' => 'user_picture', diff --git a/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php b/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php index 5a6b770..866afc7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php +++ b/core/modules/views/lib/Drupal/views/Plugin/entity_reference/selection/ViewsSelection.php @@ -50,7 +50,7 @@ public static function settingsForm(&$field, &$instance) { $displays = views_get_applicable_views('entity_reference_display'); // Filter views that list the entity type we want, and group the separate // displays by view. - $entity_info = entity_get_info($field['settings']['target_type']); + $entity_info = entity_get_info($field->settings['target_type']); $options = array(); foreach ($displays as $data) { list($view, $display_id) = $data; diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php index 6416193..b14f3c4 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -66,7 +66,7 @@ function setUp() { ), ), ); - field_create_field($this->tag_field); + $this->tag_field = field_create_field($this->tag_field); // Create an instance of the tag field on one of the content types, and // configure it to display an autocomplete widget. @@ -103,7 +103,7 @@ function testTaggedWith() { $node_add_path = 'node/add/' . $this->node_type_with_tags->type; // Create three nodes, with different tags. - $tag_field = $this->tag_field['field_name'] . '[' . LANGUAGE_NOT_SPECIFIED . ']'; + $tag_field = $this->tag_field->field_name . '[' . LANGUAGE_NOT_SPECIFIED . ']'; $edit = array(); $edit['title'] = $node_tag1_title = $this->randomName(); $edit[$tag_field] = 'tag1'; diff --git a/core/modules/views/views_ui/admin.inc b/core/modules/views/views_ui/admin.inc index 4014831..ec4b749 100644 --- a/core/modules/views/views_ui/admin.inc +++ b/core/modules/views/views_ui/admin.inc @@ -255,8 +255,8 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { // vocabulary IDs. $field = field_info_field($element['#field_name']); $vocabularies = array(); - if (!empty($field['settings']['allowed_values'])) { - foreach ($field['settings']['allowed_values'] as $tree) { + if (!empty($field->settings['allowed_values'])) { + foreach ($field->settings['allowed_values'] as $tree) { if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { $vocabularies[$vocabulary->id()] = $tree['vocabulary']; } diff --git a/core/profiles/standard/standard.install b/core/profiles/standard/standard.install index 8802bbc..1e483b2 100644 --- a/core/profiles/standard/standard.install +++ b/core/profiles/standard/standard.install @@ -155,14 +155,16 @@ function standard_install() { 'type' => 'image', 'cardinality' => 1, 'locked' => FALSE, - 'indexes' => array('fid' => array('fid')), 'settings' => array( 'uri_scheme' => 'public', 'default_image' => FALSE, ), - 'storage' => array( - 'type' => 'field_sql_storage', - 'settings' => array(), + 'data' => array( + 'indexes' => array('fid' => array('fid')), + 'storage' => array( + 'type' => 'field_sql_storage', + 'settings' => array(), + ), ), ); field_create_field($field); diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index a19d329..de3a8b0 100644 --- a/core/scripts/generate-d7-content.sh +++ b/core/scripts/generate-d7-content.sh @@ -98,7 +98,7 @@ foreach ($node_types as $bundle) { $instance = array( 'label' => $vocabulary->name, - 'field_name' => $field['field_name'], + 'field_name' => $field->field_name, 'bundle' => $bundle, 'entity_type' => 'node', 'settings' => array(),