diff --git a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php index c12683b9dfc5a990888bb22125b3103bfb234699..2103fc2b938cb51152e042cf37e223096a128a9c 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityFormController.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityFormController.php @@ -53,7 +53,6 @@ public function validate(array $form, array &$form_state) { // Map errors back to form elements. if ($violations) { foreach ($violations as $field_name => $field_violations) { - $langcode = field_is_translatable($entity_type, field_info_field($entity_type, $field_name)) ? $entity_langcode : Language::LANGCODE_NOT_SPECIFIED; $field_state = field_form_get_state($form['#parents'], $field_name, $form_state); $field_state['constraint_violations'] = $field_violations; field_form_set_state($form['#parents'], $field_name, $form_state, $field_state); diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index cae434fdccb9a19d1445bda3609dc77628773ea8..60c078c321771551e7aea47782a78eb533c21fc6 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -588,7 +588,7 @@ protected function doLoadFieldItems($entities, $age) { // If the field is translatable ensure that only values having valid // languages are retrieved. Since we are loading values for multiple // entities, we cannot limit the query to the available translations. - $langcodes = $field['translatable'] ? $all_langcodes : array(Language::LANGCODE_NOT_SPECIFIED); + $langcodes = $field->isFieldTranslatable() ? $all_langcodes : array(Language::LANGCODE_NOT_SPECIFIED); $results = $this->database->select($table, 't') ->fields('t') ->condition($load_current ? 'entity_id' : 'revision_id', $ids, 'IN') @@ -603,11 +603,11 @@ protected function doLoadFieldItems($entities, $age) { $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->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->getFieldCardinality()) { $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->getColumns() as $column => $attributes) { $column_name = static::_fieldColumnName($field, $column); // Unserialize the value if specified in the column schema. $item[$column] = (!empty($attributes['serialize'])) ? unserialize($row->$column_name) : $row->$column_name; @@ -656,13 +656,13 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) { // Prepare the multi-insert query. $do_insert = FALSE; $columns = array('entity_id', 'revision_id', 'bundle', 'delta', 'langcode'); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->getColumns() as $column => $attributes) { $columns[] = static::_fieldColumnName($field, $column); } $query = $this->database->insert($table_name)->fields($columns); $revision_query = $this->database->insert($revision_name)->fields($columns); - $langcodes = $field['translatable'] ? array_keys($entity->getTranslationLanguages()) : array(Language::LANGCODE_NOT_SPECIFIED); + $langcodes = $field->isFieldTranslatable() ? array_keys($entity->getTranslationLanguages()) : array(Language::LANGCODE_NOT_SPECIFIED); foreach ($langcodes as $langcode) { $delta_count = 0; $items = $entity->getTranslation($langcode)->get($field_name); @@ -677,7 +677,7 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) { 'delta' => $delta, 'langcode' => $langcode, ); - foreach ($field['columns'] as $column => $attributes) { + foreach ($field->getColumns() as $column => $attributes) { $column_name = static::_fieldColumnName($field, $column); // Serialize the value if specified in the column schema. $record[$column_name] = !empty($attributes['serialize']) ? serialize($item->$column) : $item->$column; @@ -685,7 +685,7 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) { $query->values($record); $revision_query->values($record); - if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) { + if ($field->getFieldCardinality() != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field->getFieldCardinality()) { break; } } @@ -788,7 +788,7 @@ public function onFieldUpdate(FieldInterface $field) { } } else { - if ($field['columns'] != $original['columns']) { + if ($field->getColumns() != $original->getColumns()) { throw new FieldUpdateForbiddenException("The SQL storage cannot change the schema for an existing field with data."); } // There is data, so there are no column changes. Drop all the prior @@ -838,7 +838,7 @@ public function onFieldUpdate(FieldInterface $field) { */ public function onFieldDelete(FieldInterface $field) { // Mark all data associated with the field for deletion. - $field['deleted'] = FALSE; + $field->deleted = FALSE; $table = static::_fieldTableName($field); $revision_table = static::_fieldRevisionTableName($field); $this->database->update($table) @@ -847,7 +847,7 @@ public function onFieldDelete(FieldInterface $field) { // Move the table to a unique name while the table contents are being // deleted. - $field['deleted'] = TRUE; + $field->deleted = TRUE; $new_table = static::_fieldTableName($field); $revision_new_table = static::_fieldRevisionTableName($field); $this->database->schema()->renameTable($table, $new_table); @@ -863,11 +863,11 @@ public function onInstanceDelete(FieldInstanceInterface $instance) { $revision_name = static::_fieldRevisionTableName($field); $this->database->update($table_name) ->fields(array('deleted' => 1)) - ->condition('bundle', $instance['bundle']) + ->condition('bundle', $instance->bundle) ->execute(); $this->database->update($revision_name) ->fields(array('deleted' => 1)) - ->condition('bundle', $instance['bundle']) + ->condition('bundle', $instance->bundle) ->execute(); } @@ -953,13 +953,13 @@ public function onFieldPurge(FieldInterface $field) { * @see hook_schema() */ public static function _fieldSqlSchema(FieldInterface $field, array $schema = NULL) { - if ($field['deleted']) { - $description_current = "Data storage for deleted field {$field['id']} ({$field['entity_type']}, {$field['field_name']})."; - $description_revision = "Revision archive storage for deleted field {$field['id']} ({$field['entity_type']}, {$field['field_name']})."; + if ($field->deleted) { + $description_current = "Data storage for deleted field {$field->uuid()} ({$field->entity_type}, {$field->getFieldName()})."; + $description_revision = "Revision archive storage for deleted field {$field->uuid()} ({$field->entity_type}, {$field->getFieldName()})."; } else { - $description_current = "Data storage for {$field['entity_type']} field {$field['field_name']}."; - $description_revision = "Revision archive storage for {$field['entity_type']} field {$field['field_name']}."; + $description_current = "Data storage for {$field->entity_type} field {$field->getFieldName()}."; + $description_revision = "Revision archive storage for {$field->entity_type} field {$field->getFieldName()}."; } $current = array( @@ -1084,12 +1084,12 @@ public static function _fieldSqlSchema(FieldInterface $field, array $schema = NU * */ static public function _fieldTableName(FieldInterface $field) { - if ($field['deleted']) { + if ($field->deleted) { // When a field is a deleted, the table is renamed to // {field_deleted_data_FIELD_UUID}. To make sure we don't end up with // table names longer than 64 characters, we hash the uuid and return the // first 10 characters so we end up with a short unique ID. - return "field_deleted_data_" . substr(hash('sha256', $field['uuid']), 0, 10); + return "field_deleted_data_" . substr(hash('sha256', $field->uuid()), 0, 10); } else { return static::_generateFieldTableName($field, FALSE); @@ -1113,12 +1113,12 @@ static public function _fieldTableName(FieldInterface $field) { * A string containing the generated name for the database table. */ static public function _fieldRevisionTableName(FieldInterface $field) { - if ($field['deleted']) { + if ($field->deleted) { // When a field is a deleted, the table is renamed to // {field_deleted_revision_FIELD_UUID}. To make sure we don't end up with // table names longer than 64 characters, we hash the uuid and return the // first 10 characters so we end up with a short unique ID. - return "field_deleted_revision_" . substr(hash('sha256', $field['uuid']), 0, 10); + return "field_deleted_revision_" . substr(hash('sha256', $field->uuid()), 0, 10); } else { return static::_generateFieldTableName($field, TRUE); @@ -1139,7 +1139,7 @@ static public function _fieldRevisionTableName(FieldInterface $field) { * @return string * The final table name. */ - static protected function _generateFieldTableName($field, $revision) { + static protected function _generateFieldTableName(FieldInterface $field, $revision) { $separator = $revision ? '_revision__' : '__'; $table_name = $field->entity_type . $separator . $field->name; // Limit the string to 48 characters, keeping a 16 characters margin for db diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 9607dd15f4b18e84fd5175e121e94d3cf10eff8a..91cac049789b81d3686ce9bd90a550b2747df6de 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -117,7 +117,8 @@ public 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::getReservedColumns())) { + $columns = $field->getColumns(); + if (isset($columns[$next]) || in_array($next, Field::getReservedColumns())) { // Use it. $column = $next; // Do not process it again. @@ -150,7 +151,7 @@ public function addField($field, $type, $langcode) { // column, i.e. target_id or fid. // Otherwise, the code executing the relationship will throw an // exception anyways so no need to do it here. - if (!$column && isset($propertyDefinitions[$relationship_specifier]) && $entity->{$field['field_name']}->get('entity') instanceof EntityReference) { + if (!$column && isset($propertyDefinitions[$relationship_specifier]) && $entity->{$field->getFieldName()}->get('entity') instanceof EntityReference) { $column = current(array_keys($propertyDefinitions)); } // Prepare the next index prefix. @@ -248,10 +249,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->getFieldName(); if (!isset($this->fieldTables[$index_prefix . $field_name])) { $table = $this->sqlQuery->getMetaData('age') == EntityStorageControllerInterface::FIELD_LOAD_CURRENT ? DatabaseStorageController::_fieldTableName($field) : DatabaseStorageController::_fieldRevisionTableName($field); - if ($field['cardinality'] != 1) { + if ($field->getFieldCardinality() != 1) { $this->sqlQuery->addMetaData('simple_query', FALSE); } $entity_type = $this->sqlQuery->getMetaData('entity_type'); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php index 092e584d8676e9188bf112df085869499f7498a9..c51be016f5e5bfcd4d93a26548f7fa8d0cff88d0 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockFieldTest.php @@ -72,7 +72,7 @@ public function testBlockFields() { )); $this->field->save(); $this->instance = entity_create('field_instance', array( - 'field_name' => $this->field->name, + 'field_name' => $this->field->getFieldName(), 'entity_type' => 'custom_block', 'bundle' => 'link', 'settings' => array( @@ -81,12 +81,12 @@ public function testBlockFields() { )); $this->instance->save(); entity_get_form_display('custom_block', 'link', 'default') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->getFieldName(), array( 'type' => 'link_default', )) ->save(); entity_get_display('custom_block', 'link', 'default') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->getFieldName(), array( 'type' => 'link', 'label' => 'hidden', )) @@ -96,8 +96,8 @@ public function testBlockFields() { $this->drupalGet('block/add/link'); $edit = array( 'info' => $this->randomName(8), - $this->field['field_name'] . '[0][url]' => 'http://example.com', - $this->field['field_name'] . '[0][title]' => 'Example.com' + $this->field->getFieldName() . '[0][url]' => 'http://example.com', + $this->field->getFieldName() . '[0][title]' => 'Example.com' ); $this->drupalPostForm(NULL, $edit, t('Save')); $block = entity_load('custom_block', 1); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php index ec2d72d32f80ac10b1594299300785786c25fafe..18e55df7111dfc06a0d2d4f360e7abf295b1c58e 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php @@ -79,7 +79,7 @@ public function testCustomBlockTypeEditing() { $this->createCustomBlockType('other'); $instance = field_info_instance('custom_block', 'body', 'basic'); - $this->assertEqual($instance['label'], 'Block body', 'Body field was found.'); + $this->assertEqual($instance->getFieldLabel(), 'Block body', 'Body field was found.'); // Verify that title and body fields are displayed. $this->drupalGet('block/add/basic'); diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index e72a9648ef2037a02409e71392d774f86b2d6130..2034cdae8b1dd06481d36cc90b2882e2882e9768 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -923,7 +923,7 @@ function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) * Implements hook_form_FORM_ID_alter(). */ function comment_form_field_ui_field_instance_edit_form_alter(&$form, $form_state) { - if ($form['#field']['type'] == 'comment') { + if ($form['#field']->getFieldType() == 'comment') { // Collect translation settings. if (\Drupal::moduleHandler()->moduleExists('content_translation')) { array_unshift($form['#submit'], 'comment_translation_configuration_element_submit'); @@ -965,7 +965,7 @@ function comment_form_field_ui_display_overview_form_alter(&$form, $form_state) * Implements hook_form_FORM_ID_alter(). */ function comment_form_field_ui_field_edit_form_alter(&$form, $form_state) { - if ($form['#field']['type'] == 'comment') { + if ($form['#field']->getFieldType() == 'comment') { // We only support posting one comment at the time so it doesn't make sense // to let the site builder choose anything else. $form['field']['cardinality_container']['cardinality']['#options'] = drupal_map_assoc(array(1)); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 6b8a9489f62e6944cf3b0fab8b8891ca2edccdb2..8b885fe633868e9a17a854f3dac9c2a5ec764632 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -74,7 +74,7 @@ function setUp() { // Make comment body translatable. $field = field_info_field('comment', 'comment_body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; $field->save(); $this->assertTrue(field_is_translatable('comment', $field), 'Comment body is translatable.'); } diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php index 8f999b6049ec579a87f5cbbfa7e50209e33c9094..8069a3fd06ffd20192ffa358f7539cac34cfa971 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php @@ -88,8 +88,8 @@ function postComment(EntityInterface $entity, $comment, $subject = '', $contact $edit['comment_body[0][value]'] = $comment; $instance = $this->container->get('field.info')->getInstance('entity_test_render', 'entity_test_render', 'comment'); - $preview_mode = $instance['settings']['preview']; - $subject_mode = $instance['settings']['subject']; + $preview_mode = $instance->getFieldSetting('preview'); + $subject_mode = $instance->getFieldSetting('subject'); // Must get the page before we test for fields. if ($entity !== NULL) { diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index 979b21953f9c367e999d10c07b3fe7b4ba915650..7944fddda2e203ae98284d8a264d1362ab942585 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -77,7 +77,7 @@ protected function getTranslatorPermissions() { function setupTestFields() { parent::setupTestFields(); $field = field_info_field('comment', 'comment_body'); - $field['translatable'] = TRUE; + $field->translatable = TRUE; $field->save(); } diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 9904ba0dc3f8b6a22544002bb0311fd9ddab8794..d896918f2fda3c088f2a8795ef08f31efd9bb2ff 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -6,40 +6,39 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\Field\FieldDefinitionInterface; use Drupal\Core\Language\Language; -use Drupal\field\Entity\Field; -use Drupal\field\Entity\FieldInstance; /** * Returns a form element to configure field synchronization. * - * @param \Drupal\field\Entity\Field $field - * A field definition array. - * @param \Drupal\field\Entity\FieldInstance $instance - * A field instance definition object. + * @param \Drupal\Core\Entity\Field\FieldDefinitionInterface $field + * A field definition object. * * @return array * A form element to configure field synchronization. */ -function content_translation_field_sync_widget(Field $field, FieldInstance $instance) { +function content_translation_field_sync_widget(FieldDefinitionInterface $field) { $element = array(); - if (!empty($field['settings']['column_groups']) && count($field['settings']['column_groups']) > 1) { + $column_groups = $field->getFieldSetting('column_groups'); + if (!empty($column_groups) && count($column_groups) > 1) { $options = array(); $default = array(); - foreach ($field['settings']['column_groups'] as $group => $info) { + foreach ($column_groups as $group => $info) { $options[$group] = $info['label']; $default[$group] = !empty($info['translatable']) ? $group : FALSE; } $settings = array('dependent_selectors' => array('instance[settings][translation_sync]' => array('file'))); + $translation_sync = $field->getFieldSetting('translation_sync'); $element = array( '#type' => 'checkboxes', '#title' => t('Translatable elements'), '#options' => $options, - '#default_value' => !empty($instance['settings']['translation_sync']) ? $instance['settings']['translation_sync'] : $default, + '#default_value' => !empty($translation_sync) ? $translation_sync : $default, '#attached' => array( 'library' => array( array('content_translation', 'drupal.content_translation.admin'), @@ -85,8 +84,8 @@ function _content_translation_form_language_content_settings_form_alter(array &$ // Only show the checkbox to enable translation if the bundles in the // entity might have fields and if there are fields to translate. if (!empty($entity_info['fieldable'])) { - $fields = field_info_instances($entity_type, $bundle); - if ($fields) { + $instances = field_info_instances($entity_type, $bundle); + if ($instances) { $form['settings'][$entity_type][$bundle]['translatable'] = array( '#type' => 'checkbox', '#title' => $bundle, @@ -95,15 +94,14 @@ function _content_translation_form_language_content_settings_form_alter(array &$ // @todo Exploit field definitions once all core entities and field // types are migrated to the Entity Field API. - foreach ($fields as $field_name => $instance) { - $field = $instance->getField(); + foreach ($instances as $field_name => $instance) { $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array( - '#label' => $instance['label'], + '#label' => $instance->getFieldLabel(), '#type' => 'checkbox', - '#title' => $instance['label'], - '#default_value' => $field['translatable'], + '#title' => $instance->getFieldLabel(), + '#default_value' => $instance->isFieldTranslatable(), ); - $column_element = content_translation_field_sync_widget($field, $instance); + $column_element = content_translation_field_sync_widget($instance); if ($column_element) { $form['settings'][$entity_type][$bundle]['columns'][$field_name] = $column_element; @@ -340,7 +338,7 @@ function _content_translation_update_field_translatability($settings) { foreach ($fields as $entity_type => $entity_type_fields) { foreach ($entity_type_fields as $field_name => $translatable) { $field = field_info_field($entity_type, $field_name); - if ($field['translatable'] != $translatable) { + if ($field->isFieldTranslatable() != $translatable) { // If a field is untranslatable, it can have no data except under // Language::LANGCODE_NOT_SPECIFIED. Thus we need a field to be translatable before // we convert data to the entity language. Conversely we need to switch @@ -385,8 +383,8 @@ function _content_translation_update_field_translatability($settings) { */ function content_translation_translatable_switch($translatable, $entity_type, $field_name) { $field = field_info_field($entity_type, $field_name); - if ($field['translatable'] !== $translatable) { - $field['translatable'] = $translatable; + if ($field->isFieldTranslatable() !== $translatable) { + $field->translatable = $translatable; $field->save(); } } @@ -420,7 +418,8 @@ function content_translation_translatable_batch($translatable, $field_name, &$co foreach ($entity_types as $entity_type) { $field = field_info_field($entity_type, $field_name); - $column = isset($field['columns']['value']) ? 'value' : key($field['columns']); + $columns = $field->getColumns(); + $column = isset($columns['value']) ? 'value' : key($columns); $query_field = "$field_name.$column"; // How many entities will need processing? @@ -451,7 +450,8 @@ function content_translation_translatable_batch($translatable, $field_name, &$co $offset = $context['sandbox']['progress_entity_type'][$entity_type]; $query = \Drupal::entityQuery($entity_type); $field = field_info_field($entity_type, $field_name); - $column = isset($field['columns']['value']) ? 'value' : key($field['columns']); + $columns = $field->getColumns(); + $column = isset($columns['value']) ? 'value' : key($columns); $query_field = "$field_name.$column"; $result = $query ->exists($query_field) diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 2b6a6113b4794ab4a10dcf392f79c9b37c5c3ae7..c8bd7bb72640109f6c4d3cb34d70ed77d074b71a 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -775,9 +775,9 @@ function content_translation_field_extra_fields() { */ function content_translation_form_field_ui_field_edit_form_alter(array &$form, array &$form_state, $form_id) { $field = $form['#field']; - $entity_type = $field['entity_type']; - $field_name = $field['field_name']; - $translatable = $field['translatable']; + $field_name = $field->getFieldName(); + $translatable = $field->isFieldTranslatable(); + $entity_type = $field->entity_type; $label = t('Field translation'); if ($field->hasData()) { @@ -810,9 +810,9 @@ function content_translation_form_field_ui_field_edit_form_alter(array &$form, a * Implements hook_form_FORM_ID_alter() for 'field_ui_field_instance_edit_form'. */ function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, array &$form_state, $form_id) { - if ($form['#field']['translatable']) { + if ($form['#instance']->isFieldTranslatable()) { module_load_include('inc', 'content_translation', 'content_translation.admin'); - $element = content_translation_field_sync_widget($form['#field'], $form['#instance']); + $element = content_translation_field_sync_widget($form['#instance']); if ($element) { $form['instance']['settings']['translation_sync'] = $element; } @@ -990,10 +990,9 @@ function content_translation_save_settings($settings) { // Store whether fields have translation enabled or not. if (!empty($bundle_settings['columns'])) { foreach ($bundle_settings['columns'] as $field_name => $column_settings) { - $field = field_info_field($entity_type, $field_name); $instance = field_info_instance($entity_type, $field_name, $bundle); - if ($field['translatable']) { - $instance['settings']['translation_sync'] = $column_settings; + if ($instance->isFieldTranslatable()) { + $instance->settings['translation_sync'] = $column_settings; } // If the field does not have translatable enabled we need to reset // the sync settings to their defaults. diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc index f4eba85ecb9d08562d8b111265f0d624c1014935..f6e6698f700c8c8c5c3ed3c7295a94419498789f 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -42,8 +42,7 @@ function content_translation_overview(EntityInterface $entity) { // Determine whether the current entity is translatable. $translatable = FALSE; foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field = $instance->getField(); - if ($field['translatable']) { + if ($instance->isFieldTranslatable()) { $translatable = TRUE; break; } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php index 64bacdca8d8dcc92cb85cbf191be89b95ba5e87b..c4b75bfdc0460fe70169927db986e1749b73b69e 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php @@ -60,14 +60,16 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode // Sync when the field is not empty, when the synchronization translations // setting is set, and the field is translatable. - if (!$entity->get($field_name)->isEmpty() && !empty($instance['settings']['translation_sync']) && field_is_translatable($entity_type, $field)) { + $translation_sync = $instance->getFieldSetting('translation_sync'); + if (!$entity->get($field_name)->isEmpty() && !empty($translation_sync) && field_is_translatable($entity_type, $field)) { // Retrieve all the untranslatable column groups and merge them into // single list. - $groups = array_keys(array_diff($instance['settings']['translation_sync'], array_filter($instance['settings']['translation_sync']))); + $groups = array_keys(array_diff($translation_sync, array_filter($translation_sync))); if (!empty($groups)) { $columns = array(); foreach ($groups as $group) { - $info = $field['settings']['column_groups'][$group]; + $column_groups = $field->getFieldSetting('column_groups'); + $info = $column_groups[$group]; // A missing 'columns' key indicates we have a single-column group. $columns = array_merge($columns, isset($info['columns']) ? $info['columns'] : array($group)); } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php b/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php index 6ab01af3ba1bdaec55eba1a1f98e063e7e134784..2907e471f6d31294182a04d211d4a5820a3f2cfc 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php @@ -43,7 +43,7 @@ public function getFormID() { * {@inheritdoc} */ public function getQuestion() { - if ($this->field['translatable']) { + if ($this->field->isFieldTranslatable()) { $question = t('Are you sure you want to disable translation for the %name field?', array('%name' => $this->fieldName)); } else { @@ -59,7 +59,7 @@ public function getDescription() { $description = t('By submitting this form these changes will apply to the %name field everywhere it is used.', array('%name' => $this->fieldName) ); - $description .= $this->field['translatable'] ? "<br>" . t("<strong>All the existing translations of this field will be deleted.</strong><br>This action cannot be undone.") : ''; + $description .= $this->field->isFieldTranslatable() ? "<br>" . t("<strong>All the existing translations of this field will be deleted.</strong><br>This action cannot be undone.") : ''; return $description; } @@ -107,7 +107,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, public function submitForm(array &$form, array &$form_state) { // This is the current state that we want to reverse. $translatable = $form_state['values']['translatable']; - if ($this->field['translatable'] !== $translatable) { + if ($this->field->translatable !== $translatable) { // Field translatability has changed since form creation, abort. $t_args = array('%field_name'); $msg = $translatable ? diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php index 0f044d58e2b48d2fb4c76ae9dc685b279fb3ad1f..7e4664f96460828d2fb131138adcc5dd9f851859 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Tests/ContentTranslationSettingsTest.php @@ -91,7 +91,7 @@ function testSettingsUI() { $this->assertSettings('comment', 'node__comment_article', TRUE, $edit); field_info_cache_clear(); $field = field_info_field('comment', 'comment_body'); - $this->assertTrue($field['translatable'], 'Comment body is translatable.'); + $this->assertTrue($field->isFieldTranslatable(), 'Comment body is translatable.'); // Test that language settings are correctly stored. $language_configuration = language_get_default_configuration('comment', 'node__comment_article'); diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index 16efa1362034983c7718402668fcab72b7c44aaf..c6d9af0831dbb8c1fcc42ff606205912bb4988dd 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -191,11 +191,11 @@ function datetime_default_value($entity, $field, $instance, $langcode) { $value = ''; $date = ''; - if ($instance['settings']['default_value'] == 'now') { + if ($instance->getFieldSetting('default_value') == 'now') { // A default value should be in the format and timezone used for date // storage. $date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE); - $storage_format = $field['settings']['datetime_type'] == 'date' ? DATETIME_DATE_STORAGE_FORMAT: DATETIME_DATETIME_STORAGE_FORMAT; + $storage_format = $field->getFieldSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT: DATETIME_DATETIME_STORAGE_FORMAT; $value = $date->format($storage_format); } diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php index d5c6d9eceda4787cbd304eda4e82a511e469171f..ba543483198c7ed327a76012e0de21e7d2e75633 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeItemTest.php @@ -43,7 +43,7 @@ public function setUp() { )); $this->field->save(); $this->instance = entity_create('field_instance', array( - 'field_name' => $this->field['field_name'], + 'field_name' => $this->field->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'settings' => array( diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php index 357abd37a8305365b60caad4f6df5b19f4f463ae..5bee2e3a0560c4f9063616b72f80e45c42b5b669 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php @@ -161,7 +161,7 @@ function testDateField() { function testDatetimeField() { $field_name = $this->field->name; // Change the field to a datetime field. - $this->field['settings']['datetime_type'] = 'datetime'; + $this->field->settings['datetime_type'] = 'datetime'; $this->field->save(); // Display creation form. diff --git a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php index 6a755275894c2dfe5a00ee04c0b5017014c6965b..c767f5a1ea6fbf872301529be96de6d07beab745 100644 --- a/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php +++ b/core/modules/edit/lib/Drupal/edit/Form/EditFieldForm.php @@ -168,7 +168,7 @@ protected function buildEntity(array $form, array &$form_state) { // types: http://drupal.org/node/1678002. if ($entity->entityType() == 'node' && $entity->isNewRevision() && !isset($entity->log)) { $instance = field_info_instance($entity->entityType(), $form_state['field_name'], $entity->bundle()); - $entity->log = t('Updated the %field-name field through in-place editing.', array('%field-name' => $instance['label'])); + $entity->log = t('Updated the %field-name field through in-place editing.', array('%field-name' => $instance->getFieldLabel())); } return $entity; diff --git a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php index eab0b66fb5fdf51f5e79caa6cc39f7c821edb123..14ca3d3e8c4a558e1685021fbca9b0c806cdee6a 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -232,8 +232,7 @@ public function setComponent($name, array $options = array()) { } if ($instance = field_info_instance($this->targetEntityType, $name, $this->bundle)) { - $field = $instance->getField(); - $options = $this->pluginManager->prepareConfiguration($field['type'], $options); + $options = $this->pluginManager->prepareConfiguration($instance->getFieldType(), $options); // Clear the persisted plugin, if any. unset($this->plugins[$name]); diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module index b9e7c58ca0fa2760089a0a7a544843f14c5317aa..7b379e4bd707c795482549bc9298fcf520230915 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -37,15 +37,14 @@ function entity_reference_field_info_alter(&$info) { function entity_reference_entity_field_info_alter(&$info, $entity_type) { foreach (field_info_instances($entity_type) as $bundle_name => $instances) { foreach ($instances as $field_name => $instance) { - $field = $instance->getField(); - if ($field['type'] != 'entity_reference') { + if ($instance->getFieldType() != 'entity_reference') { continue; } if (isset($info['definitions'][$field_name])) { - $info['definitions'][$field_name]['settings']['target_type'] = $field['settings']['target_type']; + $info['definitions'][$field_name]['settings']['target_type'] = $instance->getFieldSetting('target_type'); } elseif (isset($info['optional'][$field_name])) { - $info['optional'][$field_name]['settings']['target_type'] = $field['settings']['target_type']; + $info['optional'][$field_name]['settings']['target_type'] = $instance->getFieldSetting('target_type'); } } } @@ -74,7 +73,7 @@ function entity_reference_field_entity_update(FieldInterface $field) { return; } - if ($field->settings['target_type'] == $field->original->settings['target_type']) { + if ($field->getFieldSetting('target_type') == $field->original->getFieldSetting('target_type')) { // Target type didn't change. return; } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php index 492fa25b9602db56d004aff206fe234341832354..8fa080cbd3ad2393a60978104bde66fa16cbdbf3 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceAutocomplete.php @@ -85,7 +85,7 @@ public function getMatches($field, $instance, $entity_type, $entity_id = '', $pr if (isset($string)) { // Get an array of matching entities. - $widget = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($instance['field_name']); + $widget = entity_get_form_display($instance->entity_type, $instance->bundle, 'default')->getComponent($instance->getFieldName()); $match_operator = !empty($widget['settings']['match_operator']) ? $widget['settings']['match_operator'] : 'CONTAINS'; $entity_labels = $handler->getReferenceableEntities($string, $match_operator, 10); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php index b1dc3cd164deb4db7a8ec5a79574ec6a2ddd214c..611baf017e67f93e675170fd6222bca83a516194 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php @@ -82,16 +82,12 @@ public static function create(ContainerInterface $container) { * The matched labels as json. */ public function handleAutocomplete(Request $request, $type, $field_name, $entity_type, $bundle_name, $entity_id) { - if (!$field = field_info_field($entity_type, $field_name)) { - throw new AccessDeniedHttpException(); - } - if (!$instance = field_info_instance($entity_type, $field_name, $bundle_name)) { throw new AccessDeniedHttpException(); } $access_controller = $this->entityManager->getAccessController($entity_type); - if ($field['type'] != 'entity_reference' || !$access_controller->fieldAccess('edit', $instance)) { + if ($instance->getFieldType() != 'entity_reference' || !$access_controller->fieldAccess('edit', $instance)) { throw new AccessDeniedHttpException(); } @@ -107,7 +103,7 @@ public function handleAutocomplete(Request $request, $type, $field_name, $entity $prefix = count($items_typed) ? drupal_implode_tags($items_typed) . ', ' : ''; } - $matches = $this->entityReferenceAutocomplete->getMatches($field, $instance, $entity_type, $entity_id, $prefix, $last_item); + $matches = $this->entityReferenceAutocomplete->getMatches($instance->getField(), $instance, $entity_type, $entity_id, $prefix, $last_item); return new JsonResponse($matches); } 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 74a1a8ae9de73ba59bcb3eb5dedbeb9e187ccea2..d9419ce7ec39ea916dbd8c974a4beb3fef50fbbf 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 @@ -106,10 +106,9 @@ public static function settingsForm(FieldDefinitionInterface $field_definition) // converted to the new Field API. $fields = drupal_map_assoc(drupal_schema_fields_sql($entity_info['base_table'])); foreach (field_info_instances($target_type) as $bundle_instances) { - foreach ($bundle_instances as $instance_name => $instance_info) { - $field_info = $instance_info->getField(); - 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)); + foreach ($bundle_instances as $instance_name => $instance) { + foreach ($instance->getField()->getColumns() as $column_name => $column_info) { + $fields[$instance_name . '.' . $column_name] = t('@label (@column)', array('@label' => $instance->getFieldLabel(), '@column' => $column_name)); } } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php index ee5e79a872ea461ebc01461bc92ebf66e97ed4fd..96dbdc3e487f90e04b1f925e3fa600b6fa41b882 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/field_type/ConfigurableEntityReferenceItem.php @@ -68,15 +68,13 @@ public static function schema(FieldInterface $field) { // Create a foreign key to the target entity type base type. $entity_manager = \Drupal::service('entity.manager'); - if (is_subclass_of($entity_manager->getControllerClass($field['settings']['target_type'], 'storage'), 'Drupal\Core\Entity\DatabaseStorageController')) { - $entity_info = $entity_manager->getDefinition($field['settings']['target_type']); - + $target_type = $field->getFieldSetting('target_type'); + if (is_subclass_of($entity_manager->getControllerClass($target_type, 'storage'), 'Drupal\Core\Entity\DatabaseStorageController')) { + $entity_info = $entity_manager->getDefinition($target_type); $base_table = $entity_info['base_table']; - $id_column = $entity_info['entity_keys']['id']; - $schema['foreign keys'][$base_table] = array( 'table' => $base_table, - 'columns' => array('target_id' => $id_column), + 'columns' => array('target_id' => $entity_info['entity_keys']['id']), ); } @@ -203,7 +201,7 @@ public function instanceSettingsForm(array $form, array &$form_state) { public static function instanceSettingsFormValidate($form, &$form_state) { if (isset($form_state['values']['instance'])) { unset($form_state['values']['instance']['settings']['handler_submit']); - $form_state['instance']['settings'] = $form_state['values']['instance']['settings']; + $form_state['instance']->settings = $form_state['values']['instance']['settings']; } } 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 6ed2ace22b39c3d76660b6a2d0b6b9238864c60d..a93300e61ead14a730dd91c988944909a17dedd9 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 @@ -134,7 +134,7 @@ public function testSort() { $this->assertIdentical($result['article'], $expected_result, 'Query sorted by field returned expected values.'); // Assert sort by property. - $instance['settings']['handler_settings']['sort'] = array( + $instance->settings['handler_settings']['sort'] = array( 'field' => 'nid', 'direction' => 'ASC', ); diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index abd709ab9695b352a72b55c02eaade4a2142eefc..548cc7415a287361fba82143e8a296a78aeb6046 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -113,7 +113,7 @@ function field_invoke_method($method, $target_function, EntityInterface $entity, if (method_exists($target, $method)) { $field = $instance->getField(); - $field_name = $field['field_name']; + $field_name = $field->getFieldName(); // Determine the list of languages to iterate on. $available_langcodes = field_available_languages($entity_type, $field); @@ -201,19 +201,19 @@ function field_invoke_method_multiple($method, $target_function, array $entities $entity_instances = _field_invoke_get_instances($entity_type, $entity->bundle(), $options); foreach ($entity_instances as $instance) { - $instance_id = $instance['id']; - $field_name = $instance['field_name']; + $instance_uuid = $instance->uuid(); + $field_name = $instance->getFieldName(); // Let the closure determine the target object on which the method should // be called. - if (empty($grouped_targets[$instance_id])) { - $grouped_targets[$instance_id] = call_user_func($target_function, $instance); + if (empty($grouped_targets[$instance_uuid])) { + $grouped_targets[$instance_uuid] = call_user_func($target_function, $instance); } - if (method_exists($grouped_targets[$instance_id], $method)) { + if (method_exists($grouped_targets[$instance_uuid], $method)) { // Add the instance to the list of instances to invoke the hook on. - if (!isset($instances[$instance_id])) { - $instances[$instance_id] = $instance; + if (!isset($instances[$instance_uuid])) { + $instances[$instance_uuid] = $instance; } // Unless a language code suggestion is provided we iterate on all the @@ -226,7 +226,7 @@ function field_invoke_method_multiple($method, $target_function, array $entities // Group the items corresponding to the current field. $items = $entity->getTranslation($langcode)->get($field_name); $items->filterEmptyValues(); - $grouped_items[$instance_id][$langcode][$id] = $items; + $grouped_items[$instance_uuid][$langcode][$id] = $items; } } } @@ -235,10 +235,10 @@ function field_invoke_method_multiple($method, $target_function, array $entities } // For each instance, invoke the method and collect results. - foreach ($instances as $instance_id => $instance) { + foreach ($instances as $instance_uuid => $instance) { // Iterate over all the field translations. - foreach ($grouped_items[$instance_id] as $langcode => $items) { - $results = $grouped_targets[$instance_id]->$method($items, $a, $b); + foreach ($grouped_items[$instance_uuid] as $items) { + $results = $grouped_targets[$instance_uuid]->$method($items, $a, $b); if (isset($results)) { // Collect results by entity. @@ -303,7 +303,7 @@ function _field_invoke_get_instances($entity_type, $bundle, $options) { // Single-field mode by field id: we need to loop on each instance to // find the right one. foreach ($instances as $instance) { - if ($instance['field_id'] == $options['field_id']) { + if ($instance->getField()->uuid() == $options['field_id']) { $instances = array($instance); break; } @@ -327,7 +327,7 @@ function _field_invoke_get_instances($entity_type, $bundle, $options) { */ function _field_invoke_widget_target($form_display) { return function ($instance) use ($form_display) { - return $form_display->getRenderer($instance['field_name']); + return $form_display->getRenderer($instance->getFieldName()); }; } @@ -348,8 +348,7 @@ function _field_invoke_widget_target($form_display) { * values. */ function field_attach_preprocess(EntityInterface $entity, $element, &$variables) { - foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field_name = $instance['field_name']; + foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $field_name => $instance) { if (isset($element[$field_name]['#language'])) { $langcode = $element[$field_name]['#language']; $variables[$field_name] = $entity->getTranslation($langcode)->{$field_name}->getValue(); diff --git a/core/modules/field/field.deprecated.inc b/core/modules/field/field.deprecated.inc index 2f1c50d769983a4238e099f6ddae4efec978a78d..6f4a64330abcb583226cb17f50c00bf461b39792 100644 --- a/core/modules/field/field.deprecated.inc +++ b/core/modules/field/field.deprecated.inc @@ -719,8 +719,8 @@ function field_attach_prepare_view($entity_type, array $entities, array $display // instance, call the prepareView() method on the formatter object handed by // the entity display. $target_function = function ($instance) use ($displays) { - if (isset($displays[$instance['bundle']])) { - return $displays[$instance['bundle']]->getRenderer($instance['field_name']); + if (isset($displays[$instance->bundle])) { + return $displays[$instance->bundle]->getRenderer($instance->getFieldName()); } }; $null = NULL; @@ -763,7 +763,7 @@ function field_attach_view(EntityInterface $entity, EntityDisplay $display, $lan // For each instance, call the view() method on the formatter object handed // by the entity display. $target_function = function ($instance) use ($display) { - return $display->getRenderer($instance['field_name']); + return $display->getRenderer($instance->getFieldName()); }; $null = NULL; $output = field_invoke_method('view', $target_function, $entity, $null, $null, $options); diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index 3c6bfde97c5a8221c36931912e71785d2a417842..94b036e666160574a081d814e5ba7a9bbeec2e32 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -8,6 +8,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Language\Language; use Drupal\field\Field; +use Drupal\field\FieldInstanceInterface; /** * @defgroup field_info Field Info API diff --git a/core/modules/field/field.module b/core/modules/field/field.module index c3e056d652a3460f09477ebecd34edcd81173021..619d34a9c639df2c63e7a77633733f41334c60c0 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -192,7 +192,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; } @@ -288,7 +288,7 @@ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { $instances = field_read_instances(); foreach ($instances as $instance) { if ($instance->entity_type == $entity_type && $instance->bundle == $bundle_old) { - $id_new = $instance['entity_type'] . '.' . $bundle_new . '.' . $instance['field_name']; + $id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->getFieldName(); $instance->id = $id_new; $instance->bundle = $bundle_new; $instance->allowBundleRename(); @@ -560,7 +560,7 @@ function field_view_field(EntityInterface $entity, $field_name, $display_options // $display_options, so we cannot let preparation happen internally. $field = field_info_field($entity_type, $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->getFieldType(), $display_options); $formatter = $formatter_manager->getInstance(array( 'field_definition' => $instance, 'view_mode' => $view_mode, diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index 17b065a053a95a5875462625ddcc5ec4c5210986..96ecabbf90a370da46c22d2dd9fbab1b5de23e17 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -7,6 +7,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; +use Drupal\field\FieldInterface; /** * @defgroup field_language Field Language API @@ -124,13 +125,13 @@ function field_language_fallback(&$field_langcodes, EntityInterface $entity, $la * @return * An array of valid language codes. */ -function field_available_languages($entity_type, $field) { +function field_available_languages($entity_type, FieldInterface $field) { static $drupal_static_fast; if (!isset($drupal_static_fast)) { $drupal_static_fast['field_langcodes'] = &drupal_static(__FUNCTION__); } $field_langcodes = &$drupal_static_fast['field_langcodes']; - $field_name = $field['field_name']; + $field_name = $field->getFieldName(); if (!isset($field_langcodes[$entity_type][$field_name])) { // If the field has language support enabled we retrieve an (alterable) list @@ -215,8 +216,8 @@ function field_language_fallback_enabled() { * @return * TRUE if the field can be translated. */ -function field_is_translatable($entity_type, $field) { - return $field['translatable'] && field_has_translation_handler($entity_type); +function field_is_translatable($entity_type, FieldInterface $field) { + return $field->isFieldTranslatable() && field_has_translation_handler($entity_type); } /** @@ -296,7 +297,7 @@ function field_valid_language($langcode, $default = TRUE) { * A language code if a field name is specified, an array of language codes * keyed by field name otherwise. */ -function field_language(EntityInterface $entity, $field_name = NULL, $langcode = NULL) { +function field_language(EntityInterface $entity, $displayed_field_name = NULL, $langcode = NULL) { $display_langcodes = &drupal_static(__FUNCTION__, array()); $id = $entity->id(); $bundle = $entity->bundle(); @@ -308,18 +309,18 @@ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = // By default, display language is set to one of the locked languages // if the field translation is not available. It is up to translation // handlers to implement language fallback rules. - foreach (field_info_instances($entity_type, $bundle) as $instance) { - if (_field_translated_value_exists($entity, $langcode, $instance['field_name'])) { - $display_langcode[$instance['field_name']] = $langcode; + foreach (field_info_instances($entity_type, $bundle) as $field_name => $instance) { + if (_field_translated_value_exists($entity, $langcode, $field_name)) { + $display_langcode[$field_name] = $langcode; } else { // If the field has a value for one of the locked languages, then use // that language for display. If not, the default one will be // Language::LANGCODE_NOT_SPECIFIED. - $display_langcode[$instance['field_name']] = Language::LANGCODE_NOT_SPECIFIED; + $display_langcode[$field_name] = Language::LANGCODE_NOT_SPECIFIED; foreach (language_list(Language::STATE_LOCKED) as $language_locked) { - if (isset($entity->{$instance['field_name']}[$language_locked->id])) { - $display_langcode[$instance['field_name']] = $language_locked->id; + if (isset($entity->{$field_name}[$language_locked->id])) { + $display_langcode[$field_name] = $language_locked->id; break; } } @@ -345,8 +346,8 @@ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = $display_langcode = $display_langcodes[$entity_type][$id][$langcode]; // Single-field mode. - if (isset($field_name)) { - return isset($display_langcode[$field_name]) ? $display_langcode[$field_name] : FALSE; + if (isset($displayed_field_name)) { + return isset($display_langcode[$displayed_field_name]) ? $display_langcode[$displayed_field_name] : FALSE; } return $display_langcode; diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index 25db6869ead56d1da32afc554c63c186c95589c0..a061b5fab6a1922e6496328350b584d2dde270ea 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -76,7 +76,7 @@ function field_purge_batch($batch_size) { $factory = \Drupal::service('entity.query'); $info = entity_get_info(); foreach ($instances as $instance) { - $entity_type = $instance['entity_type']; + $entity_type = $instance->entity_type; // We cannot purge anything if the entity type is unknown (e.g. the // providing module was uninstalled). @@ -93,13 +93,11 @@ function field_purge_batch($batch_size) { $ids = (object) array( 'entity_type' => $entity_type, - 'bundle' => $instance['bundle'], + 'bundle' => $instance->bundle, ); - // field_purge_data() will need the field array. - $field = $instance->getField(); // Retrieve some entities. $query = $factory->get($entity_type) - ->condition('id:' . $field['uuid'] . '.deleted', 1) + ->condition('id:' . $instance->getField()->uuid() . '.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'])) { @@ -132,7 +130,7 @@ function field_purge_batch($batch_size) { continue; } - $instances = field_read_instances(array('field_id' => $field['uuid']), array('include_deleted' => 1)); + $instances = field_read_instances(array('field_id' => $field->uuid()), array('include_deleted' => 1)); if (empty($instances)) { field_purge_field($field); } @@ -151,7 +149,7 @@ function field_purge_batch($batch_size) { function field_purge_instance($instance) { $state = \Drupal::state(); $deleted_instances = $state->get('field.instance.deleted'); - unset($deleted_instances[$instance['uuid']]); + unset($deleted_instances[$instance->uuid()]); $state->set('field.instance.deleted', $deleted_instances); // Clear the cache. @@ -171,14 +169,14 @@ function field_purge_instance($instance) { * The field record to purge. */ function field_purge_field($field) { - $instances = field_read_instances(array('field_id' => $field['uuid']), array('include_deleted' => 1)); + $instances = field_read_instances(array('field_id' => $field->uuid()), 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->getFieldName()))); } $state = \Drupal::state(); $deleted_fields = $state->get('field.field.deleted'); - unset($deleted_fields[$field['uuid']]); + unset($deleted_fields[$field->uuid()]); $state->set('field.field.deleted', $deleted_fields); // Notify the storage layer. diff --git a/core/modules/field/field.views.inc b/core/modules/field/field.views.inc index 62799dd37f55b6321dcf6443cf9e4cda157da376..517da7405394e6c8801dab5efbecc6b3404de0f8 100644 --- a/core/modules/field/field.views.inc +++ b/core/modules/field/field.views.inc @@ -24,7 +24,7 @@ function field_views_data() { foreach (field_info_fields() as $field) { if (_field_views_is_sql_entity_type($field)) { - $result = (array) $module_handler->invoke($field['module'], 'field_views_data', array($field)); + $result = (array) $module_handler->invoke($field->module, 'field_views_data', array($field)); if (empty($result)) { $result = field_views_field_default_views_data($field); } @@ -50,7 +50,7 @@ function field_views_data() { function field_views_data_alter(&$data) { foreach (field_info_fields() as $field) { if (_field_views_is_sql_entity_type($field)) { - $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); } @@ -92,8 +92,9 @@ function field_views_field_label($entity_type, $field_name) { foreach ($instances as $bundle => $bundle_instances) { if (isset($bundle_instances[$field_name])) { $instance = $bundle_instances[$field_name]; - $label_counter[$instance->label] = isset($label_counter[$instance->label]) ? ++$label_counter[$instance->label] : 1; - $all_labels[$instance->label] = TRUE; + $label = $instance->getFieldLabel(); + $label_counter[$label] = isset($label_counter[$label]) ? ++$label_counter[$label] : 1; + $all_labels[$label] = TRUE; } } if (empty($label_counter)) { @@ -118,15 +119,16 @@ function field_views_field_default_views_data(FieldInterface $field) { $data = array(); // Check the field type is available. - if (!\Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field['type'])) { + if (!\Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->getFieldType())) { return $data; } // Check the field has instances. - if (empty($field['bundles'])) { + if (!$field->getBundles()) { return $data; } - $field_name = $field['field_name']; + $field_name = $field->getFieldName(); + $field_columns = $field->getColumns(); // Grab information about the entity type tables. $entity_manager = \Drupal::entityManager(); @@ -147,13 +149,13 @@ function field_views_field_default_views_data(FieldInterface $field) { $field_tables = array( EntityStorageControllerInterface::FIELD_LOAD_CURRENT => array( 'table' => DatabaseStorageController::_fieldTableName($field), - 'alias' => "{$entity_type}__{$field->name}", + 'alias' => "{$entity_type}__{$field_name}", ), ); if ($supports_revisions) { $field_tables[EntityStorageControllerInterface::FIELD_LOAD_REVISION] = array( 'table' => DatabaseStorageController::_fieldRevisionTableName($field), - 'alias' => "{$entity_type}_revision__{$field->name}", + 'alias' => "{$entity_type}_revision__{$field_name}", ); } @@ -182,7 +184,7 @@ function field_views_field_default_views_data(FieldInterface $field) { $bundles_names = $field->getBundles(); // Build the list of additional fields to add to queries. $add_fields = array('delta', 'langcode', 'bundle'); - foreach (array_keys($field['columns']) as $column) { + foreach (array_keys($field_columns) as $column) { $add_fields[] = DatabaseStorageController::_fieldColumnName($field, $column); } // Determine the label to use for the field. We don't have a label available @@ -242,7 +244,7 @@ function field_views_field_default_views_data(FieldInterface $field) { $data[$table_alias][$field_alias]['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_alias][$field_alias]['field'] = array( 'table' => $table, @@ -260,7 +262,7 @@ function field_views_field_default_views_data(FieldInterface $field) { } // Expose data for each field property individually. - 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. @@ -287,7 +289,7 @@ function field_views_field_default_views_data(FieldInterface $field) { break; } - if (count($field['columns']) == 1 || $column == 'value') { + if (count($field_columns) == 1 || $column == 'value') { $title = t('@label (!name)', array('@label' => $label, '!name' => $field_name)); $title_short = $label; } @@ -326,7 +328,7 @@ function field_views_field_default_views_data(FieldInterface $field) { $also_known = array(); foreach ($all_labels as $label_name => $true) { if ($label != $label_name) { - if (count($field['columns']) == 1 || $column == 'value') { + if (count($field_columns) == 1 || $column == 'value') { $alias_title = t('@label (!name)', array('@label' => $label_name, '!name' => $field_name)); } else { @@ -375,7 +377,7 @@ function field_views_field_default_views_data(FieldInterface $field) { } // Expose additional delta column for multiple value fields. - if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) { + if ($field->getFieldCardinality() > 1 || $field->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED) { $title_delta = t('@label (!name:delta)', array('@label' => $label, '!name' => $field_name)); $title_short_delta = t('@label:delta', array('@label' => $label)); @@ -417,7 +419,7 @@ function field_views_field_default_views_data(FieldInterface $field) { } // Expose additional language column for translatable fields. - if (!empty($field['translatable'])) { + if ($field->isFieldTranslatable()) { $title_language = t('@label (!name:language)', array('@label' => $label, '!name' => $field_name)); $title_short_language = t('@label:language', array('@label' => $label)); @@ -474,7 +476,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->getFieldType() == 'list_text') { $data[$table_name][$field_name]['argument']['id'] = 'field_list_string'; } else { diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/Field.php index 1b763b39647bfbca4c3b801111fbe927fcbfc6f8..463f5cb3a9893a5f4f6bdf8e57d1541ac7572cf9 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -548,9 +548,12 @@ public function getFieldSetting($setting_name) { elseif (array_key_exists($setting_name, $field_type_info['settings'])) { return $field_type_info['settings'][$setting_name]; } - else { + elseif (array_key_exists($setting_name, $field_type_info['instance_settings'])) { return $field_type_info['instance_settings'][$setting_name]; } + else { + return NULL; + } } /** @@ -601,58 +604,6 @@ public function isFieldRequired() { */ public function getFieldDefaultValue(EntityInterface $entity) { } - /** - * {@inheritdoc} - */ - public function offsetExists($offset) { - return isset($this->{$offset}) || in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details')); - } - - /** - * {@inheritdoc} - */ - public function &offsetGet($offset) { - switch ($offset) { - case 'id': - return $this->uuid; - - case 'field_name': - return $this->name; - - case 'columns': - $this->getSchema(); - return $this->schema['columns']; - - case 'foreign keys': - $this->getSchema(); - return $this->schema['foreign keys']; - - case 'bundles': - $bundles = $this->getBundles(); - return $bundles; - } - - return $this->{$offset}; - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value) { - if (!in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details'))) { - $this->{$offset} = $value; - } - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset) { - if (!in_array($offset, array('columns', 'foreign keys', 'bundles', 'storage_details'))) { - unset($this->{$offset}); - } - } - /** * A list of columns that can not be used as field type columns. * diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php index 412bae2616bb5bfea0b7981d4466d643d47f495c..d03897793b30667c9ca56689e9938d91bf67e2cf 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php @@ -614,47 +614,7 @@ public function isFieldConfigurable() { return TRUE; } - /** - * {@inheritdoc} - */ - public function offsetExists($offset) { - return (isset($this->{$offset}) || $offset == 'field_id' || $offset == 'field_name'); - } - - /** - * {@inheritdoc} - */ - public function &offsetGet($offset) { - if ($offset == 'field_id') { - return $this->field_uuid; - } - if ($offset == 'field_name') { - return $this->field->name; - } - return $this->{$offset}; - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value) { - if ($offset == 'field_id') { - $offset = 'field_uuid'; - } - $this->{$offset} = $value; - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset) { - if ($offset == 'field_id') { - $offset = 'field_uuid'; - } - unset($this->{$offset}); - } - - /** + /* * Implements the magic __sleep() method. * * Using the Serialize interface and serialize() / unserialize() methods diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 4113239020dd4422c91e5df401984ed18f4a2368..240bd48175e2fc244ea37bf175408641c11c202e 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -11,6 +11,8 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Entity\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\field\FieldInterface; +use Drupal\field\FieldInstanceInterface; /** * Provides field and instance definitions for the current runtime environment. @@ -234,7 +236,7 @@ public function getFields() { else { // Collect and prepare fields. foreach (field_read_fields(array(), array('include_deleted' => TRUE)) as $field) { - $this->fieldsById[$field['uuid']] = $this->prepareField($field); + $this->fieldsById[$field->uuid()] = $this->prepareField($field); } // Store in persistent cache. @@ -243,8 +245,8 @@ public function getFields() { // Fill the name/ID map. foreach ($this->fieldsById as $field) { - if (!$field['deleted']) { - $this->fieldIdsByName[$field->entity_type][$field->name] = $field['uuid']; + if (!$field->deleted) { + $this->fieldIdsByName[$field->entity_type][$field->getFieldName()] = $field->uuid(); } } @@ -280,9 +282,8 @@ public function getInstances($entity_type = NULL) { $this->getFields(); foreach (field_read_instances() as $instance) { - $field = $this->getField($instance['entity_type'], $instance['field_name']); - $instance = $this->prepareInstance($instance, $field['type']); - $this->bundleInstances[$instance['entity_type']][$instance['bundle']][$instance['field_name']] = $instance; + $instance = $this->prepareInstance($instance); + $this->bundleInstances[$instance->entity_type][$instance->bundle][$instance->getFieldName()] = $instance; } // Store in persistent cache. @@ -330,8 +331,8 @@ public function getField($entity_type, $field_name) { $field = $this->prepareField($field); // Save in the "static" cache. - $this->fieldsById[$field['uuid']] = $field; - $this->fieldIdsByName[$entity_type][$field_name] = $field['uuid']; + $this->fieldsById[$field->uuid()] = $field; + $this->fieldIdsByName[$entity_type][$field_name] = $field->uuid(); return $field; } @@ -369,9 +370,9 @@ public function getFieldById($field_id) { $field = $this->prepareField($field); // Store in the static cache. - $this->fieldsById[$field['uuid']] = $field; - if (!$field['deleted']) { - $this->fieldIdsByName[$field->entity_type][$field->name] = $field['uuid']; + $this->fieldsById[$field->uuid()] = $field; + if (!$field->deleted) { + $this->fieldIdsByName[$field->entity_type][$field->getFieldName()] = $field->uuid(); } return $field; @@ -412,10 +413,10 @@ public function getBundleInstances($entity_type, $bundle) { // Extract the field definitions and save them in the "static" cache. foreach ($fields as $field) { - if (!isset($this->fieldsById[$field['uuid']])) { - $this->fieldsById[$field['uuid']] = $field; - if (!$field['deleted']) { - $this->fieldIdsByName[$field->entity_type][$field->name] = $field['uuid']; + if (!isset($this->fieldsById[$field->uuid()])) { + $this->fieldsById[$field->uuid()] = $field; + if (!$field->deleted) { + $this->fieldIdsByName[$field->entity_type][$field->getFieldName()] = $field->uuid(); } } } @@ -459,23 +460,21 @@ public function getBundleInstances($entity_type, $bundle) { // Place the fields in our global "static". $loaded_fields = entity_load_multiple('field_entity', array_keys($config_ids)); foreach ($loaded_fields as $field) { - if (!isset($this->fieldsById[$field['uuid']])) { + if (!isset($this->fieldsById[$field->uuid()])) { $field = $this->prepareField($field); - $this->fieldsById[$field['uuid']] = $field; - $this->fieldIdsByName[$field->entity_type][$field->name] = $field['uuid']; + $this->fieldsById[$field->uuid()] = $field; + $this->fieldIdsByName[$field->entity_type][$field->getFieldName()] = $field->uuid(); } - $fields[] = $this->fieldsById[$field['uuid']]; + $fields[] = $this->fieldsById[$field->uuid()]; } // Then collect the instances. $loaded_instances = entity_load_multiple('field_instance', array_values($config_ids)); foreach ($loaded_instances as $instance) { - $field = $instance->getField(); - - $instance = $this->prepareInstance($instance, $field['type']); - $instances[$field['field_name']] = $instance; + $instance = $this->prepareInstance($instance); + $instances[$instance->getFieldName()] = $instance; } } } @@ -566,9 +565,9 @@ public function getBundleExtraFields($entity_type, $bundle) { * @return * The field definition completed for the current runtime context. */ - public function prepareField($field) { + public function prepareField(FieldInterface $field) { // Make sure all expected field settings are present. - $field['settings'] += $this->fieldTypeManager->getDefaultSettings($field['type']); + $field->settings += $this->fieldTypeManager->getDefaultSettings($field->getFieldType()); return $field; } @@ -576,17 +575,15 @@ public function prepareField($field) { /** * Prepares an instance definition for the current run-time context. * - * @param $instance - * The raw instance structure as read from the database. - * @param $field_type - * The field type. + * @param \Drupal\field\FieldInstanceInterface $instance + * The instance definition. * * @return * The field instance array completed for the current runtime context. */ - public function prepareInstance($instance, $field_type) { + public function prepareInstance(FieldInstanceInterface $instance) { // Make sure all expected instance settings are present. - $instance['settings'] += $this->fieldTypeManager->getDefaultInstanceSettings($field_type); + $instance->settings += $this->fieldTypeManager->getDefaultInstanceSettings($instance->getFieldType()); return $instance; } diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceInterface.php b/core/modules/field/lib/Drupal/field/FieldInstanceInterface.php index 318bf4f18382530d284d2a90d5df76768943fe71..6c57fa655d872cbd989ebaab754b104645afd007 100644 --- a/core/modules/field/lib/Drupal/field/FieldInstanceInterface.php +++ b/core/modules/field/lib/Drupal/field/FieldInstanceInterface.php @@ -13,7 +13,7 @@ /** * Provides an interface defining a field instance entity. */ -interface FieldInstanceInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess { +interface FieldInstanceInterface extends ConfigEntityInterface, FieldDefinitionInterface { /** * Returns the field entity for this instance. diff --git a/core/modules/field/lib/Drupal/field/FieldInterface.php b/core/modules/field/lib/Drupal/field/FieldInterface.php index 2a03aabd2e0c41af7be1cad8927f48a61a1a0046..7905026c272e7d9ffb3a2c8f35a25c669706fe32 100644 --- a/core/modules/field/lib/Drupal/field/FieldInterface.php +++ b/core/modules/field/lib/Drupal/field/FieldInterface.php @@ -13,7 +13,7 @@ /** * Provides an interface defining a field entity. */ -interface FieldInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess { +interface FieldInterface extends ConfigEntityInterface, FieldDefinitionInterface { /** * Returns the field schema. 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 7dd0000d33e2aeb529a2799e41bbf204989ae501..564ec205173f480ad6153f32feaead94d0f00e54 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 @@ -47,7 +47,6 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface */ public function __construct($plugin_id, array $plugin_definition, FieldDefinitionInterface $field_definition, array $settings) { parent::__construct(array(), $plugin_id, $plugin_definition); - $this->fieldDefinition = $field_definition; $this->settings = $settings; } 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 5b91aaa11285bd7b8707d8dbb1a0281e30546218..bc16c8391e64a7b6bae49ecceca4f10a0b5c28a7 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 @@ -129,7 +129,8 @@ 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) { + $cardinality = $field->getFieldCardinality(); + if ($cardinality > 1 || $cardinality == FIELD_CARDINALITY_UNLIMITED) { $this->multiple = TRUE; // If "Display all values in the same row" is FALSE, then we always limit @@ -145,7 +146,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'] != $cardinality)) || intval($this->options['delta_offset'])) { $this->limit_values = TRUE; } } @@ -315,8 +316,8 @@ protected function defineOptions() { // defineOptions runs before init/construct, so no $this->field_info $field = field_info_field($this->definition['entity_type'], $this->definition['field_name']); - $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field['type']); - $column_names = array_keys($field['columns']); + $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field->getFieldType()); + $column_names = array_keys($field->getColumns()); $default_column = ''; // Try to determine a sensible default. if (count($column_names) == 1) { @@ -351,7 +352,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->getFieldCardinality() > 1) ? $field->getFieldCardinality() : 'all', ); $options['delta_offset'] = array( 'default' => 0, @@ -387,8 +388,8 @@ public function buildOptionsForm(&$form, &$form_state) { parent::buildOptionsForm($form, $form_state); $field = $this->field_info; - $formatters = $this->formatterPluginManager->getOptions($field['type']); - $column_names = array_keys($field['columns']); + $formatters = $this->formatterPluginManager->getOptions($field->getFieldType()); + $column_names = array_keys($field->getColumns()); // If this is a multiple value field, add its options. if ($this->multiple) { @@ -396,7 +397,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->getColumns()) == 1) { $form['click_sort_column'] = array( '#type' => 'value', '#value' => isset($column_names[0]) ? $column_names[0] : '', @@ -486,14 +487,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->getFieldCardinality() == 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->getFieldCardinality())); $size = 1; } $form['multi_type'] = array( @@ -812,14 +813,14 @@ function render_item($count, $item) { protected function documentSelfTokens(&$tokens) { $field = $this->field_info; - foreach ($field['columns'] as $id => $column) { + foreach ($field->getColumns() as $id => $column) { $tokens['[' . $this->options['id'] . '-' . $id . ']'] = t('Raw @column', array('@column' => $id)); } } protected function addSelfTokens(&$tokens, $item) { $field = $this->field_info; - foreach ($field['columns'] as $id => $column) { + foreach ($field->getColumns() 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 0baa9513a26da0341c2b09e792917059f099563a..d015ffa79f935a1bc2ece35689fef8f72d407ea9 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -143,7 +143,7 @@ function setUp() { for ($i = 0; $i < 10; $i++) { $entity = entity_create($this->entity_type, array('type' => $bundle)); foreach ($this->fields as $field) { - $entity->{$field['field_name']}->setValue($this->_generateTestFieldValues($field->cardinality)); + $entity->{$field->getFieldName()}->setValue($this->_generateTestFieldValues($field->getFieldCardinality())); } $entity->save(); } @@ -183,7 +183,7 @@ function testDeleteFieldInstance() { $instances = field_read_instances(array('field_id' => $field->uuid, 'deleted' => TRUE), array('include_deleted' => TRUE, 'include_inactive' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); $instance = $instances[0]; - $this->assertEqual($instance['bundle'], $bundle, 'The deleted instance is for the correct bundle'); + $this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle'); // Check that the actual stored content did not change during delete. $schema = DatabaseStorageController::_fieldSqlSchema($field); diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index 7578ed2a636e22d6077263eac42e53b72d684d14..d050f5950169189a2ce06603d32e9e2278da6241 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -44,8 +44,8 @@ function testCreateField() { $field = entity_create('field_entity', $field_definition); $field->save(); $mem = field_test_memorize(); - $this->assertIdentical($mem['field_test_field_entity_create'][0][0]['field_name'], $field_definition['name'], 'hook_entity_create() called with correct arguments.'); - $this->assertIdentical($mem['field_test_field_entity_create'][0][0]['type'], $field_definition['type'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_entity_create'][0][0]->getFieldName(), $field_definition['name'], 'hook_entity_create() called with correct arguments.'); + $this->assertIdentical($mem['field_test_field_entity_create'][0][0]->getFieldType(), $field_definition['type'], 'hook_entity_create() called with correct arguments.'); // Read the configuration. Check against raw configuration data rather than // the loaded ConfigEntity, to be sure we check that the defaults are @@ -310,18 +310,18 @@ function testDeleteField() { // Test that the first field is not deleted, and then delete it. $field = field_read_field('entity_test', $this->field['name'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field is not marked for deletion.'); + $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); field_info_field('entity_test', $this->field['name'])->delete(); // Make sure that the field is marked as deleted when it is specifically // loaded. $field = field_read_field('entity_test', $this->field['name'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($field['deleted']), 'A deleted field is marked for deletion.'); + $this->assertTrue(!empty($field->deleted), 'A deleted field is marked for deletion.'); // Make sure that this field's instance is marked as deleted when it is // specifically loaded. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($instance['deleted']), 'An instance for a deleted field is marked for deletion.'); + $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('entity_test', $this->field['name']); @@ -333,29 +333,29 @@ function testDeleteField() { // Make sure the other field (and its field instance) are not deleted. $another_field = field_read_field('entity_test', $this->another_field['name']); - $this->assertTrue(!empty($another_field) && empty($another_field['deleted']), 'A non-deleted field is not marked for deletion.'); + $this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A non-deleted field is not marked for deletion.'); $another_instance = field_read_instance('entity_test', $another_instance_definition['field_name'], $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.'); + $this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'An instance of a non-deleted field is not marked for deletion.'); // Try to create a new field the same name as a deleted field and // write data into it. entity_create('field_entity', $this->field)->save(); entity_create('field_instance', $this->instance_definition)->save(); $field = field_read_field('entity_test', $this->field['name']); - $this->assertTrue(!empty($field) && empty($field['deleted']), 'A new field with a previously used name is created.'); + $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field with a previously used name is created.'); $instance = field_read_instance('entity_test', $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.'); + $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new instance for a previously used field name is created.'); // Save an entity with data for the field $entity = entity_create('entity_test', array()); $values[0]['value'] = mt_rand(1, 127); - $entity->{$field['field_name']}->value = $values[0]['value']; + $entity->{$field->getFieldName()}->value = $values[0]['value']; $entity = $this->entitySaveReload($entity); // Verify the field is present on load - $this->assertIdentical(count($entity->{$field['field_name']}), count($values), "Data in previously deleted field saves and loads correctly"); + $this->assertIdentical(count($entity->{$field->getFieldName()}), count($values), "Data in previously deleted field saves and loads correctly"); foreach ($values as $delta => $value) { - $this->assertEqual($entity->{$field['field_name']}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly"); + $this->assertEqual($entity->{$field->getFieldName()}[$delta]->value, $values[$delta]['value'], "Data in previously deleted field saves and loads correctly"); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index c79c6d4d57e4a05de394f963a9c0621bf0f65ab9..23e7fd1ad94236071a34f24ce6e6f4f96bdeddef 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -51,9 +51,9 @@ function testFieldAttachView() { $entity_init = entity_create($entity_type, array()); // Populate values to be displayed. - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity_init->{$this->field_name}->setValue($values); - $values_2 = $this->_generateTestFieldValues($this->field_2['cardinality']); + $values_2 = $this->_generateTestFieldValues($this->field_2->getFieldCardinality()); $entity_init->{$this->field_name_2}->setValue($values_2); // Simple formatter, label displayed. @@ -69,7 +69,7 @@ function testFieldAttachView() { 'test_formatter_setting' => $formatter_setting, ), ); - $display->setComponent($this->field['field_name'], $display_options); + $display->setComponent($this->field->getFieldName(), $display_options); $formatter_setting_2 = $this->randomName(); $display_options_2 = array( @@ -79,19 +79,19 @@ function testFieldAttachView() { 'test_formatter_setting' => $formatter_setting_2, ), ); - $display->setComponent($this->field_2['field_name'], $display_options_2); + $display->setComponent($this->field_2->getFieldName(), $display_options_2); // View all fields. field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays); $content = field_attach_view($entity, $display); $output = drupal_render($content); $this->content = $output; - $this->assertRaw($this->instance['label'], "First field's label is displayed."); + $this->assertRaw($this->instance->getFieldLabel(), "First field's label is displayed."); foreach ($values as $delta => $value) { $this->content = $output; $this->assertRaw("$formatter_setting|{$value['value']}", "Value $delta is displayed, formatter settings are applied."); } - $this->assertRaw($this->instance_2['label'], "Second field's label is displayed."); + $this->assertRaw($this->instance_2->getFieldLabel(), "Second field's label is displayed."); foreach ($values_2 as $delta => $value) { $this->content = $output; $this->assertRaw("$formatter_setting_2|{$value['value']}", "Value $delta is displayed, formatter settings are applied."); @@ -100,21 +100,21 @@ function testFieldAttachView() { // Label hidden. $entity = clone($entity_init); $display_options['label'] = 'hidden'; - $display->setComponent($this->field['field_name'], $display_options); + $display->setComponent($this->field->getFieldName(), $display_options); field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays); $entity->content = field_attach_view($entity, $display); $output = drupal_render($entity->content); $this->content = $output; - $this->assertNoRaw($this->instance['label'], "Hidden label: label is not displayed."); + $this->assertNoRaw($this->instance->getFieldLabel(), "Hidden label: label is not displayed."); // Field hidden. $entity = clone($entity_init); - $display->removeComponent($this->field['field_name']); + $display->removeComponent($this->field->getFieldName()); field_attach_prepare_view($entity_type, array($entity->id() => $entity), $displays); $entity->content = field_attach_view($entity, $display); $output = drupal_render($entity->content); $this->content = $output; - $this->assertNoRaw($this->instance['label'], "Hidden field: label is not displayed."); + $this->assertNoRaw($this->instance->getFieldLabel(), "Hidden field: label is not displayed."); foreach ($values as $delta => $value) { $this->assertNoRaw("$formatter_setting|{$value['value']}", "Hidden field: value $delta is not displayed."); } @@ -122,7 +122,7 @@ function testFieldAttachView() { // Multiple formatter. $entity = clone($entity_init); $formatter_setting = $this->randomName(); - $display->setComponent($this->field['field_name'], array( + $display->setComponent($this->field->getFieldName(), array( 'label' => 'above', 'type' => 'field_test_multiple', 'settings' => array( @@ -142,7 +142,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->getFieldName(), array( 'label' => 'above', 'type' => 'field_test_with_prepare_view', 'settings' => array( @@ -182,7 +182,7 @@ function testFieldAttachPrepareViewMultiple() { // Set the instance to be hidden. $display = entity_get_display('entity_test', 'entity_test', 'full') - ->removeComponent($this->field['field_name']); + ->removeComponent($this->field->getFieldName()); // Set up a second instance on another bundle, with a formatter that uses // hook_field_formatter_prepare_view(). @@ -194,7 +194,7 @@ function testFieldAttachPrepareViewMultiple() { $this->instance2->save(); $display_2 = entity_get_display('entity_test', 'test_bundle_2', 'full') - ->setComponent($this->field['field_name'], array( + ->setComponent($this->field->getFieldName(), array( 'type' => 'field_test_with_prepare_view', 'settings' => array( 'test_formatter_setting_additional' => $formatter_setting, @@ -205,11 +205,11 @@ function testFieldAttachPrepareViewMultiple() { // Create one entity in each bundle. $entity1_init = entity_create('entity_test', array('id' => 1, 'type' => 'entity_test')); - $values1 = $this->_generateTestFieldValues($this->field['cardinality']); + $values1 = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity1_init->{$this->field_name}->setValue($values1); $entity2_init = entity_create('entity_test', array('id' => 2, 'type' => 'test_bundle_2')); - $values2 = $this->_generateTestFieldValues($this->field['cardinality']); + $values2 = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity2_init->{$this->field_name}->setValue($values2); // Run prepare_view, and check that the entities come out as expected. @@ -234,9 +234,9 @@ function testFieldAttachPrepareViewMultiple() { */ function testFieldAttachCache() { // Initialize random values and a test entity. - $entity_init = entity_create('entity_test', array('type' => $this->instance['bundle'])); + $entity_init = entity_create('entity_test', array('type' => $this->instance->bundle)); $langcode = Language::LANGCODE_NOT_SPECIFIED; - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->getFieldCardinality()); // Non-cacheable entity type. $entity_type = 'entity_test'; @@ -327,21 +327,21 @@ function testFieldAttachForm() { $this->createFieldWithInstance('_2'); $entity_type = 'entity_test'; - $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance->bundle)); // When generating form for all fields. $form = array(); $form_state = form_state_defaults(); - $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); + $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance->bundle, 'default'); field_attach_form($entity, $form, $form_state); - $this->assertEqual($form[$this->field_name]['widget']['#title'], $this->instance['label'], "First field's form title is {$this->instance['label']}"); - $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + $this->assertEqual($form[$this->field_name]['widget']['#title'], $this->instance->getFieldLabel(), "First field's form title is {$this->instance->getFieldLabel()}"); + $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2->getFieldLabel(), "Second field's form title is {$this->instance_2->getFieldLabel()}"); + for ($delta = 0; $delta < $this->field->getFieldCardinality(); $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name]['widget'][$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->getFieldCardinality(); $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } @@ -350,12 +350,12 @@ function testFieldAttachForm() { $options = array('field_name' => $this->field_name_2); $form = array(); $form_state = form_state_defaults(); - $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); + $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance->bundle, 'default'); field_attach_form($entity, $form, $form_state, NULL, $options); $this->assertFalse(isset($form[$this->field_name]), 'The first field does not exist in the form'); - $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2['label'], "Second field's form title is {$this->instance_2['label']}"); - for ($delta = 0; $delta < $this->field_2['cardinality']; $delta++) { + $this->assertEqual($form[$this->field_name_2]['widget']['#title'], $this->instance_2->getFieldLabel(), "Second field's form title is {$this->instance_2->getFieldLabel()}"); + for ($delta = 0; $delta < $this->field_2->getFieldCardinality(); $delta++) { // field_test_widget uses 'textfield' $this->assertEqual($form[$this->field_name_2]['widget'][$delta]['value']['#type'], 'textfield', "Second field's form delta $delta widget is textfield"); } @@ -368,23 +368,23 @@ function testFieldAttachExtractFormValues() { $this->createFieldWithInstance('_2'); $entity_type = 'entity_test'; - $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance['bundle'])); + $entity_init = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance->bundle)); // Build the form for all fields. $form = array(); $form_state = form_state_defaults(); - $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance['bundle'], 'default'); + $form_state['form_display'] = entity_get_form_display($entity_type, $this->instance->bundle, 'default'); field_attach_form($entity_init, $form, $form_state); // Simulate incoming values. // First field. $values = array(); $weights = array(); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta < $this->field->getFieldCardinality(); $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->getFieldCardinality()); } while (in_array($weight, $weights)); $weights[$delta] = $weight; $values[$delta]['_weight'] = $weight; @@ -394,11 +394,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->getFieldCardinality(); $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->getFieldCardinality()); } 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 7bccfd8ccd74e99c792c8ff678df3c883a0ea025..5ee57a0784d56306518fe6709261657f0c6d740d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -48,10 +48,11 @@ public function setUp() { function testFieldAttachSaveLoad() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); + $cardinality = $this->field->getFieldCardinality(); // Configure the instance so that we test hook_field_load() (see // field_test_field_load() in field_test.module). - $this->instance['settings']['test_hook_field_load'] = TRUE; + $this->instance->settings['test_hook_field_load'] = TRUE; $this->instance->save(); // TODO : test empty values filtering and "compression" (store consecutive deltas). @@ -60,7 +61,7 @@ function testFieldAttachSaveLoad() { $entity = entity_create($entity_type, array()); for ($revision_id = 0; $revision_id < 3; $revision_id++) { // Note: we try to insert one extra value. - $current_values = $this->_generateTestFieldValues($this->field['cardinality'] + 1); + $current_values = $this->_generateTestFieldValues($cardinality + 1); $entity->{$this->field_name}->setValue($current_values); $entity->setNewRevision(); $entity->save(); @@ -74,8 +75,8 @@ function testFieldAttachSaveLoad() { $entity = $storage_controller->load($entity_id); // Confirm current revision loads the correct data. // Number of values per field loaded equals the field cardinality. - $this->assertEqual(count($entity->{$this->field_name}), $this->field['cardinality'], 'Current revision: expected number of values'); - for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { + $this->assertEqual(count($entity->{$this->field_name}), $cardinality, 'Current revision: expected number of values'); + for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. $this->assertEqual($entity->{$this->field_name}[$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. @@ -86,8 +87,8 @@ function testFieldAttachSaveLoad() { foreach (array_keys($values) as $revision_id) { $entity = $storage_controller->loadRevision($revision_id); // Number of values per field loaded equals the field cardinality. - $this->assertEqual(count($entity->{$this->field_name}), $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}), $cardinality, format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id))); + for ($delta = 0; $delta < $cardinality; $delta++) { // The field value loaded matches the one inserted or updated. $this->assertEqual($entity->{$this->field_name}[$delta]->value, $values[$revision_id][$delta]['value'], format_string('Revision %revision_id: expected value %delta was found.', array('%revision_id' => $revision_id, '%delta' => $delta))); } @@ -124,7 +125,7 @@ function testFieldAttachLoadMultiple() { 'type' => 'test_field', )); $field->save(); - $field_ids[$i] = $field['uuid']; + $field_ids[$i] = $field->uuid(); foreach ($field_bundles_map[$i] as $bundle) { entity_create('field_instance', array( 'field_name' => $field_names[$i], @@ -218,7 +219,7 @@ function testFieldAttachSaveEmptyDataDefaultValue() { $this->createFieldWithInstance('', $entity_type); // Add a default value function. - $this->instance['default_value_function'] = 'field_test_default_value'; + $this->instance->default_value_function = 'field_test_default_value'; $this->instance->save(); // Verify that fields are populated with default values. @@ -245,11 +246,12 @@ function testFieldAttachSaveEmptyDataDefaultValue() { function testFieldAttachDelete() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); - $entity = entity_create($entity_type, array('type' => $this->instance['bundle'])); + $cardinality = $this->field->getFieldCardinality(); + $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); $vids = array(); // Create revision 0 - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($cardinality); $entity->{$this->field_name} = $values; $entity->save(); $vids[] = $entity->getRevisionId(); @@ -269,7 +271,7 @@ function testFieldAttachDelete() { // Confirm each revision loads foreach ($vids as $vid) { $revision = $controller->loadRevision($vid); - $this->assertEqual(count($revision->{$this->field_name}), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); + $this->assertEqual(count($revision->{$this->field_name}), $cardinality, "The test entity revision $vid has $cardinality values."); } // Delete revision 1, confirm the other two still load. @@ -278,13 +280,13 @@ function testFieldAttachDelete() { foreach (array(0, 2) as $key) { $vid = $vids[$key]; $revision = $controller->loadRevision($vid); - $this->assertEqual(count($revision->{$this->field_name}), $this->field['cardinality'], "The test entity revision $vid has {$this->field['cardinality']} values."); + $this->assertEqual(count($revision->{$this->field_name}), $cardinality, "The test entity revision $vid has $cardinality values."); } // Confirm the current revision still loads $controller->resetCache(); $current = $controller->load($entity->id()); - $this->assertEqual(count($current->{$this->field_name}), $this->field['cardinality'], "The test entity current revision has {$this->field['cardinality']} values."); + $this->assertEqual(count($current->{$this->field_name}), $cardinality, "The test entity current revision has $cardinality values."); // Delete all field data, confirm nothing loads $entity->delete(); @@ -302,6 +304,7 @@ function testFieldAttachDelete() { function testEntityCreateRenameBundle() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); + $cardinality = $this->field->getFieldCardinality(); // Create a new bundle. $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); @@ -312,13 +315,13 @@ function testEntityCreateRenameBundle() { entity_create('field_instance', $this->instance_definition)->save(); // Save an entity with data in the field. - $entity = entity_create($entity_type, array('type' => $this->instance['bundle'])); - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); + $values = $this->_generateTestFieldValues($cardinality); $entity->{$this->field_name} = $values; // Verify the field data is present on load. $entity = $this->entitySaveReload($entity); - $this->assertEqual(count($entity->{$this->field_name}), $this->field['cardinality'], "Data is retrieved for the new bundle"); + $this->assertEqual(count($entity->{$this->field_name}), $cardinality, "Data is retrieved for the new bundle"); // Rename the bundle. $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); @@ -326,13 +329,13 @@ function testEntityCreateRenameBundle() { // Check that the instance definition has been updated. $this->instance = field_info_instance($entity_type, $this->field_name, $new_bundle); - $this->assertIdentical($this->instance['bundle'], $new_bundle, "Bundle name has been updated in the instance."); + $this->assertIdentical($this->instance->bundle, $new_bundle, "Bundle name has been updated in the instance."); // Verify the field data is present on load. $controller = $this->container->get('entity.manager')->getStorageController($entity->entityType()); $controller->resetCache(); $entity = $controller->load($entity->id()); - $this->assertEqual(count($entity->{$this->field_name}), $this->field['cardinality'], "Bundle name has been updated in the field storage"); + $this->assertEqual(count($entity->{$this->field_name}), $cardinality, "Bundle name has been updated in the field storage"); } /** @@ -362,7 +365,7 @@ function testEntityDeleteBundle() { $instance = array( 'field_name' => $field_name, 'entity_type' => $entity_type, - 'bundle' => $this->instance['bundle'], + 'bundle' => $this->instance->bundle, 'label' => $this->randomName() . '_label', 'description' => $this->randomName() . '_description', 'weight' => mt_rand(0, 127), @@ -370,8 +373,8 @@ function testEntityDeleteBundle() { entity_create('field_instance', $instance)->save(); // Save an entity with data for both fields - $entity = entity_create($entity_type, array('type' => $this->instance['bundle'])); - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); + $values = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity->{$this->field_name} = $values; $entity->{$field_name} = $this->_generateTestFieldValues(1); $entity = $this->entitySaveReload($entity); @@ -381,7 +384,7 @@ function testEntityDeleteBundle() { $this->assertEqual(count($entity->{$field_name}), 1, 'Second field got loaded'); // Delete the bundle. - entity_test_delete_bundle($this->instance['bundle'], $entity_type); + entity_test_delete_bundle($this->instance->bundle, $entity_type); // Verify no data gets loaded $controller = $this->container->get('entity.manager')->getStorageController($entity->entityType()); @@ -392,8 +395,8 @@ function testEntityDeleteBundle() { $this->assertTrue(empty($entity->{$field_name}), 'No data for second field'); // Verify that the instances are gone - $this->assertFalse(field_read_instance('entity_test', $this->field_name, $this->instance['bundle']), "First field is deleted"); - $this->assertFalse(field_read_instance('entity_test', $field_name, $instance['bundle']), "Second field is deleted"); + $this->assertFalse(field_read_instance('entity_test', $this->field_name, $new_bundle), "First field is deleted"); + $this->assertFalse(field_read_instance('entity_test', $field_name, $new_bundle), "Second field is deleted"); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php index 6e4b8b822eb6d6522f2965fab2d25ab23dc8a730..ca941e98e70638dc776f94c444176760764253e5 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php @@ -52,7 +52,7 @@ function testImportChange() { // Check that the updated config was correctly imported. $instance = entity_load('field_instance', $instance_id); - $this->assertEqual($instance['label'], $new_label, 'Instance label updated'); + $this->assertEqual($instance->getFieldLabel(), $new_label, 'Instance label updated'); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index fe97da2f490eb5a7890afead7ae2642678123ee3..637aacf989c97b4b716ac6b2c0c1b96f386e97bb 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -49,19 +49,19 @@ function testFieldInfo() { $field->save(); $fields = field_info_fields(); $this->assertEqual(count($fields), count($core_fields) + 1, 'One new field exists'); - $this->assertEqual($fields[$field['uuid']]['field_name'], $field['field_name'], 'info fields contains field name'); - $this->assertEqual($fields[$field['uuid']]['type'], $field['type'], 'info fields contains field type'); - $this->assertEqual($fields[$field['uuid']]['module'], 'field_test', 'info fields contains field module'); + $this->assertEqual($fields[$field->uuid]->getFieldName(), $field->getFieldName(), 'info fields contains field name'); + $this->assertEqual($fields[$field->uuid]->getFieldType(), $field->getFieldType(), 'info fields contains field type'); + $this->assertEqual($fields[$field->uuid]->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['uuid']]['settings'][$key], $val, format_string('Field setting %key has correct default value %value', array('%key' => $key, '%value' => $val))); + $this->assertEqual($fields[$field->uuid]->getFieldSetting($key), $val, format_string('Field setting %key has correct default value %value', array('%key' => $key, '%value' => $val))); } - $this->assertEqual($fields[$field['uuid']]['cardinality'], 1, 'info fields contains cardinality 1'); - $this->assertEqual($fields[$field['uuid']]['active'], TRUE, 'info fields contains active 1'); + $this->assertEqual($fields[$field->uuid]->getFieldCardinality(), 1, 'info fields contains cardinality 1'); + $this->assertEqual($fields[$field->uuid]->active, TRUE, 'info fields contains active 1'); // Create an instance, verify that it shows up $instance_definition = array( - 'field_name' => $field['name'], + 'field_name' => $field->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'label' => $this->randomName(), @@ -72,18 +72,18 @@ function testFieldInfo() { $instance->save(); $info = entity_get_info('entity_test'); - $instances = field_info_instances('entity_test', $instance['bundle']); + $instances = field_info_instances('entity_test', $instance->bundle); $this->assertEqual(count($instances), 1, format_string('One instance shows up in info when attached to a bundle on a @label.', array( '@label' => $info['label'] ))); - $this->assertTrue($instance_definition < $instances[$instance['field_name']], 'Instance appears in info correctly'); + $this->assertTrue($instance_definition < $instances[$instance->getFieldName()], 'Instance appears in info correctly'); // Test a valid entity type but an invalid bundle. $instances = field_info_instances('entity_test', 'invalid_bundle'); $this->assertIdentical($instances, array(), "field_info_instances('entity_test', 'invalid_bundle') returns an empty array."); // Test invalid entity type and bundle. - $instances = field_info_instances('invalid_entity', $instance['bundle']); + $instances = field_info_instances('invalid_entity', $instance->bundle); $this->assertIdentical($instances, array(), "field_info_instances('invalid_entity', 'entity_test') returns an empty array."); // Test invalid entity type, no bundle provided. @@ -133,7 +133,7 @@ function testFieldPrepare() { // Check that all expected settings are in place. $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_definition['type']); - $this->assertEqual($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.'); } /** @@ -167,7 +167,7 @@ function testInstancePrepare() { // Check that all expected instance settings are in place. $field_type = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($field_definition['type']); - $this->assertEqual($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.'); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php index 8c4afcc372c58615e0466f3be58d9f573119829a..6c7209edab03cc061a519ed16fb14b69e23c0b72 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInstanceCrudTest.php @@ -51,7 +51,7 @@ function setUp() { $this->field = entity_create('field_entity', $this->field_definition); $this->field->save(); $this->instance_definition = array( - 'field_name' => $this->field->name, + 'field_name' => $this->field->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ); @@ -115,9 +115,9 @@ function testReadFieldInstance() { // Read the instance back. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); - $this->assertTrue($this->instance_definition['field_name'] == $instance['field_name'], '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['field_name'] == $instance->getFieldName(), '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.'); } /** @@ -128,16 +128,16 @@ function testUpdateFieldInstance() { // Check that basic changes are saved. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); - $instance['required'] = !$instance['required']; - $instance['label'] = $this->randomName(); - $instance['description'] = $this->randomName(); - $instance['settings']['test_instance_setting'] = $this->randomName(); + $instance->required = !$instance->isFieldRequired(); + $instance->label = $this->randomName(); + $instance->description = $this->randomName(); + $instance->settings['test_instance_setting'] = $this->randomName(); $instance->save(); $instance_new = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); - $this->assertEqual($instance['required'], $instance_new['required'], '"required" change is saved'); - $this->assertEqual($instance['label'], $instance_new['label'], '"label" change is saved'); - $this->assertEqual($instance['description'], $instance_new['description'], '"description" change is saved'); + $this->assertEqual($instance->isFieldRequired(), $instance_new->isFieldRequired(), '"required" change is saved'); + $this->assertEqual($instance->getFieldLabel(), $instance_new->getFieldLabel(), '"label" change is saved'); + $this->assertEqual($instance->getFieldDescription(), $instance_new->getFieldDescription(), '"description" change is saved'); // TODO: test failures. } @@ -159,13 +159,13 @@ function testDeleteFieldInstance() { // Test that the first instance is not deleted, and then delete it. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($instance) && empty($instance['deleted']), 'A new field instance is not marked for deletion.'); + $this->assertTrue(!empty($instance) && empty($instance->deleted), 'A new field instance is not marked for deletion.'); $instance->delete(); // Make sure the instance is marked as deleted when the instance is // specifically loaded. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE)); - $this->assertTrue(!empty($instance['deleted']), 'A deleted field instance is marked for deletion.'); + $this->assertTrue(!empty($instance->deleted), 'A deleted field instance is marked for deletion.'); // Try to load the instance normally and make sure it does not show up. $instance = field_read_instance('entity_test', $this->instance_definition['field_name'], $this->instance_definition['bundle']); @@ -173,13 +173,13 @@ function testDeleteFieldInstance() { // Make sure the other field instance is not deleted. $another_instance = field_read_instance('entity_test', $another_instance_definition['field_name'], $another_instance_definition['bundle']); - $this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), 'A non-deleted field instance is not marked for deletion.'); + $this->assertTrue(!empty($another_instance) && empty($another_instance->deleted), 'A non-deleted field instance is not marked for deletion.'); // Make sure the field is deleted when its last instance is deleted. $another_instance->delete(); $deleted_fields = \Drupal::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($another_instance['entity_type'], $another_instance['field_name']); + $this->assertTrue(isset($deleted_fields[$another_instance->field_uuid]), 'A deleted field is marked for deletion.'); + $field = field_read_field($another_instance->entity_type, $another_instance->getFieldName()); $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/FieldUnitTestBase.php b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php index cd809a6198e26fd4c9ac8ee34440abf37fd36390..d9a776b87f05f6672e1c3c82dae1f3521c783eac 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldUnitTestBase.php @@ -74,7 +74,7 @@ function createFieldWithInstance($suffix = '', $entity_type = 'entity_test', $bu 'cardinality' => 4, )); $this->$field->save(); - $this->$field_id = $this->{$field}['uuid']; + $this->$field_id = $this->{$field}->uuid(); $this->$instance_definition = array( 'field_name' => $this->$field_name, 'entity_type' => $entity_type, diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldValidationTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldValidationTest.php index 3dd2e32d39b6af6dd671fc801950e58f63c1a0f4..5a740d1c276c5ab5a58bb5419cd6bb4556fa1913 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldValidationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldValidationTest.php @@ -54,14 +54,14 @@ function testCardinalityConstraint() { // Check that the expected constraint violations are reported. $this->assertEqual(count($violations), 1); $this->assertEqual($violations[0]->getPropertyPath(), ''); - $this->assertEqual($violations[0]->getMessage(), t('%name: this field cannot hold more than @count values.', array('%name' => $this->instance['label'], '@count' => $cardinality))); + $this->assertEqual($violations[0]->getMessage(), t('%name: this field cannot hold more than @count values.', array('%name' => $this->instance->getFieldLabel(), '@count' => $cardinality))); } /** * Tests that constraints defined by the field type are validated. */ function testFieldConstraints() { - $cardinality = $this->field->cardinality; + $cardinality = $this->field->getFieldCardinality(); $entity = $this->entity; // The test is only valid if the field cardinality is greater than 2. @@ -76,7 +76,7 @@ function testFieldConstraints() { } else { $value = -1; - $expected_violations[$delta . '.value'][] = t('%name does not accept the value -1.', array('%name' => $this->instance['label'])); + $expected_violations[$delta . '.value'][] = t('%name does not accept the value -1.', array('%name' => $this->instance->getFieldLabel())); } $entity->{$this->field_name}->offsetGet($delta)->set('value', $value); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index d6ed724d0c73ba5e13338512654a6af616bb0c15..f9b37d55cb6ee39625a76d75715f97ce61a62233 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -592,8 +592,8 @@ function testFieldFormHiddenWidget() { entity_create('field_entity', $field)->save(); $this->instance = entity_create('field_instance', $this->instance); $this->instance->save(); - entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') - ->setComponent($this->instance['field_name'], array( + entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') + ->setComponent($this->instance->getFieldName(), array( 'type' => 'hidden', )) ->save(); @@ -613,10 +613,10 @@ function testFieldFormHiddenWidget() { // Update the instance to remove the default value and switch to the // default widget. - $this->instance['default_value'] = NULL; + $this->instance->default_value = NULL; $this->instance->save(); - entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') - ->setComponent($this->instance['field_name'], array( + entity_get_form_display($entity_type, $this->instance->bundle, 'default') + ->setComponent($this->instance->getFieldName(), array( 'type' => 'test_field_widget', )) ->save(); @@ -635,8 +635,8 @@ function testFieldFormHiddenWidget() { $this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated'); // Update the form display and switch to the Hidden widget again. - entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default') - ->setComponent($this->instance['field_name'], array( + entity_get_form_display($entity_type, $this->instance->bundle, 'default') + ->setComponent($this->instance->getFieldName(), array( 'type' => 'hidden', )) ->save(); diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 626414acb7b93d3f51038379e1764535ce725e40..b381cf57c872bdfa8779bd4df59f89ccfd110208 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -118,7 +118,8 @@ function testFieldAvailableLanguages() { // Test 'translatable' fieldable info. field_test_entity_info_translatable('entity_test', FALSE); $field = clone($this->field); - $field['field_name'] .= '_untranslatable'; + $field->field_name .= '_untranslatable'; + $field->save(); // Enable field translations for the entity. field_test_entity_info_translatable('entity_test', TRUE); @@ -136,7 +137,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; $this->field->save(); $available_langcodes = field_available_languages($this->entity_type, $this->field); $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === Language::LANGCODE_NOT_SPECIFIED, 'For untranslatable fields only Language::LANGCODE_NOT_SPECIFIED is available.'); @@ -154,13 +155,13 @@ function testTranslatableFieldSaveLoad() { // Prepare the field translations. $entity_type = 'entity_test'; field_test_entity_info_translatable($entity_type, TRUE); - $entity = entity_create($entity_type, array('type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); $field_translations = array(); $available_langcodes = field_available_languages($entity_type, $this->field); $this->assertTrue(count($available_langcodes) > 1, 'Field is translatable.'); $entity->langcode->value = reset($available_langcodes); foreach ($available_langcodes as $langcode) { - $field_translations[$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $field_translations[$langcode] = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity->getTranslation($langcode)->{$this->field_name}->setValue($field_translations[$langcode]); } @@ -194,10 +195,10 @@ function testTranslatableFieldSaveLoad() { asort($translation_langcodes); $translation_langcodes = array_values($translation_langcodes); - $values = array('type' => $instance['bundle'], 'langcode' => $translation_langcodes[0]); + $values = array('type' => $instance->bundle, 'langcode' => $translation_langcodes[0]); $entity = entity_create($entity_type, $values); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity->getTranslation($langcode, FALSE)->{$this->field_name}->setValue($values[$this->field_name][$langcode]); } @@ -208,14 +209,14 @@ function testTranslatableFieldSaveLoad() { // @todo Test every translation once the Entity Translation API allows for // multilingual defaults. $langcode = $entity->language()->id; - $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $instance['default_value'], format_string('Default value correctly populated for language %language.', array('%language' => $langcode))); + $this->assertEqual($entity->getTranslation($langcode)->{$field_name_default}->getValue(), $instance->default_value, format_string('Default value correctly populated for language %language.', array('%language' => $langcode))); // Check that explicit empty values are not overridden with default values. foreach (array(NULL, array()) as $empty_items) { - $values = array('type' => $instance['bundle'], 'langcode' => $translation_langcodes[0]); + $values = array('type' => $instance->bundle, 'langcode' => $translation_langcodes[0]); $entity = entity_create($entity_type, $values); foreach ($translation_langcodes as $langcode) { - $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field['cardinality']); + $values[$this->field_name][$langcode] = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity->getTranslation($langcode)->{$this->field_name}->setValue($values[$this->field_name][$langcode]); $entity->getTranslation($langcode)->{$field_name_default}->setValue($empty_items); $values[$field_name_default][$langcode] = $empty_items; @@ -233,6 +234,7 @@ function testTranslatableFieldSaveLoad() { function testFieldDisplayLanguage() { $field_name = drupal_strtolower($this->randomName() . '_field_name'); $entity_type = 'entity_test'; + $bundle = 'entity_test'; // We need an additional field here to properly test display language // suggestions. @@ -248,14 +250,14 @@ function testFieldDisplayLanguage() { $instance = array( 'field_name' => $field['name'], 'entity_type' => $entity_type, - 'bundle' => 'entity_test', + 'bundle' => $bundle, ); entity_create('field_instance', $instance)->save(); $enabled_langcodes = field_content_languages(); - $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance['bundle']));; + $entity = entity_create($entity_type, array('id' => 1, 'revision_id' => 1, 'type' => $this->instance->bundle));; $entity->langcode->value = reset($enabled_langcodes); - $instances = field_info_instances($entity_type, $this->instance['bundle']); + $instances = field_info_instances($entity_type, $bundle); $langcodes = array(); // This array is used to store, for each field name, which one of the locked @@ -265,7 +267,7 @@ function testFieldDisplayLanguage() { // Generate field translations for languages different from the first // enabled. foreach ($instances as $instance) { - $field_name = $instance['field_name']; + $field_name = $instance->getFieldName(); $field = $instance->getField(); do { // Index 0 is reserved for the requested language, this way we ensure @@ -274,7 +276,7 @@ function testFieldDisplayLanguage() { } while (isset($langcodes[$langcode])); $langcodes[$langcode] = TRUE; - $entity->getTranslation($langcode)->{$field_name}->setValue($this->_generateTestFieldValues($field['cardinality'])); + $entity->getTranslation($langcode)->{$field_name}->setValue($this->_generateTestFieldValues($field->getFieldCardinality())); // 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::LANGCODE_NOT_SPECIFIED. @@ -292,7 +294,7 @@ function testFieldDisplayLanguage() { $requested_langcode = $enabled_langcodes[0]; $display_langcodes = field_language($entity, NULL, $requested_langcode); foreach ($instances as $instance) { - $field_name = $instance['field_name']; + $field_name = $instance->getFieldName(); $this->assertTrue($display_langcodes[$field_name] == $locked_languages[$field_name], format_string('The display language for field %field_name is %language.', array('%field_name' => $field_name, '%language' => $locked_languages[$field_name]))); } @@ -301,7 +303,7 @@ function testFieldDisplayLanguage() { drupal_static_reset('field_language'); $display_langcodes = field_language($entity, NULL, $requested_langcode); foreach ($instances as $instance) { - $field_name = $instance['field_name']; + $field_name = $instance->getFieldName(); $langcode = $display_langcodes[$field_name]; // As the requested language was not assinged to any field, if the // returned language is defined for the current field, core fallback rules diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index 639b9e280f303a19f1fd74b14a61605655a7fcc8..8ddb73a14b17073766b0c5c9df976a77e38f6df6 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -106,7 +106,7 @@ function testFieldFormTranslationRevisions() { $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field)); unset($available_langcodes[Language::LANGCODE_NOT_SPECIFIED]); unset($available_langcodes[Language::LANGCODE_NOT_APPLICABLE]); - $field_name = $this->field['field_name']; + $field_name = $this->field->getFieldName(); // Store the field translations. $entity->langcode->value = key($available_langcodes); @@ -134,7 +134,7 @@ function testFieldFormTranslationRevisions() { * by the passed arguments were correctly stored. */ private function checkTranslationRevisions($id, $revision_id, $available_langcodes) { - $field_name = $this->field['field_name']; + $field_name = $this->field->getFieldName(); $entity = entity_revision_load($this->entity_type, $revision_id); foreach ($available_langcodes as $langcode => $value) { $passed = $entity->getTranslation($langcode)->{$field_name}->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 947ec8746f09323d64da38172d278e190e0a4042..3d7889902b841a1082a8f298464a5c69d66feb19 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php @@ -74,7 +74,7 @@ function setUpFields($amount = 3) { function setUpInstances($bundle = 'page') { foreach ($this->fields as $key => $field) { $instance = array( - 'field_name' => $field['name'], + 'field_name' => $field->getFieldName(), '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 985dc7f047a9338666d8761524e712a34f6ac74c..7f157e2ed810e2fb2144c0ae2bbcbd7ffc26bedc 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -72,13 +72,13 @@ protected function setUp() { for ($key = 0; $key < 3; $key++) { $field = $this->fields[$key]; - $edit[$field['field_name']][0]['value'] = $this->randomName(8); + $edit[$field->getFieldName()][0]['value'] = $this->randomName(8); } for ($j = 0; $j < 5; $j++) { - $edit[$this->fields[3]['field_name']][$j]['value'] = $this->randomName(8); + $edit[$this->fields[3]->getFieldName()][$j]['value'] = $this->randomName(8); } // Set this field to be empty. - $edit[$this->fields[4]['field_name']] = array(array('value' => NULL)); + $edit[$this->fields[4]->getFieldName()] = array(array('value' => NULL)); $this->nodes[$i] = $this->drupalCreateNode($edit); } @@ -95,9 +95,10 @@ 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'] = 'node__' . $field['field_name']; - $view->display_handler->options['fields'][$field['field_name']]['field'] = $field['field_name']; + $field_name = $field->getFieldName(); + $view->display_handler->options['fields'][$field_name]['id'] = $field_name; + $view->display_handler->options['fields'][$field_name]['table'] = 'node__' . $field_name; + $view->display_handler->options['fields'][$field_name]['field'] = $field_name; } } @@ -115,9 +116,9 @@ public function _testSimpleFieldRender() { // Tests that the rendered fields match the actual value of the fields. for ($i = 0; $i < 3; $i++) { for ($key = 0; $key < 2; $key++) { - $field = $this->fields[$key]; - $rendered_field = $view->style_plugin->getField($i, $field['field_name']); - $expected_field = $this->nodes[$i]->{$field['field_name']}->value; + $field_name = $this->fields[$key]->getFieldName(); + $rendered_field = $view->style_plugin->getField($i, $field_name); + $expected_field = $this->nodes[$i]->$field_name->value; $this->assertEqual($rendered_field, $expected_field); } } @@ -129,8 +130,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]->getFieldName()]['type'] = 'text_trimmed'; + $view->displayHandlers->get('default')->options['fields'][$this->fields[0]->getFieldName()]['settings'] = array( 'trim_length' => 3, ); $this->executeView($view); @@ -138,14 +139,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->getField($i, $this->fields[0]['field_name']); + $rendered_field = $view->style_plugin->getField($i, $this->fields[0]->getFieldName()); $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]->getFieldName(); // Test delta limit. $this->prepareView($view); @@ -165,7 +166,7 @@ public function _testMultipleFieldRender() { } // Test that an empty field is rendered without error. - $rendered_field = $view->style_plugin->getField(4, $this->fields[4]['field_name']); + $rendered_field = $view->style_plugin->getField(4, $this->fields[4]->getFieldName()); $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 5d79d058eecd444dad8d3594b6ddb0e8c0eb6500..270dc0285eeb5f89e87ee452c04ec60f07128471 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 @@ -67,7 +67,7 @@ function field_test_field_widget_info_alter(&$info) { * Implements hook_field_update_forbid(). */ function field_test_field_update_forbid($field, $prior_field) { - if ($field['type'] == 'test_field' && $field['settings']['unchangeable'] != $prior_field['settings']['unchangeable']) { + if ($field->getFieldType() == 'test_field' && $field->getFieldSetting('unchangeable') != $prior_field->getFieldSetting('unchangeable')) { throw new FieldException("field_test 'unchangeable' setting cannot be changed'"); } } @@ -82,7 +82,8 @@ function field_test_field_load($entity_type, $entities, $field, $instances, $lan foreach ($items as $id => $item) { // To keep the test non-intrusive, only act for instances with the // test_hook_field_load setting explicitly set to TRUE. - if (!empty($instances[$id]['settings']['test_hook_field_load'])) { + $test_hook_field_load = $instances[$id]->getFieldSetting('test_hook_field_load'); + if (!empty($test_hook_field_load)) { foreach ($item as $delta => $value) { // Don't add anything on empty values. if ($value) { @@ -129,9 +130,9 @@ 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->getFieldName()][$langcode][$delta][] = array( 'error' => 'field_test_invalid', - 'message' => t('%name does not accept the value -1.', array('%name' => $instance['label'])), + 'message' => t('%name does not accept the value -1.', array('%name' => $instance->getFieldLabel())), ); } } @@ -151,7 +152,7 @@ function field_test_field_is_empty($item, $field_type) { * Implements hook_field_settings_form(). */ function field_test_field_settings_form($field, $instance) { - $settings = $field['settings']; + $settings = $field->getFieldSettings(); $form['test_field_setting'] = array( '#type' => 'textfield', @@ -168,7 +169,7 @@ function field_test_field_settings_form($field, $instance) { * Implements hook_field_instance_settings_form(). */ function field_test_field_instance_settings_form($field, $instance) { - $settings = $instance['settings']; + $settings = $instance->getFieldSettings(); $form['test_instance_setting'] = array( '#type' => 'textfield', 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 a079829e8d06765517edd3fbc4e6c08251a16b6e..ee2e28d3aebacf45cfc800635e1bb1ac60384e1f 100644 --- a/core/modules/field/tests/modules/field_test/field_test.install +++ b/core/modules/field/tests/modules/field_test/field_test.install @@ -17,7 +17,7 @@ function field_test_install() { * Implements hook_field_schema(). */ function field_test_field_schema($field) { - if ($field['type'] == 'test_field') { + if ($field->getFieldType() == 'test_field') { return array( 'columns' => array( 'value' => array( @@ -34,13 +34,14 @@ function field_test_field_schema($field) { else { $foreign_keys = array(); // The 'foreign keys' key is not always used in tests. - if (!empty($field['settings']['foreign_key_name'])) { + $foreign_key_name = $field->getFieldSetting('foreign_key_name'); + if (!empty($foreign_key_name)) { $foreign_keys['foreign keys'] = array( // This is a dummy foreign key definition, references a table that // doesn't exist, but that's not a problem. - $field['settings']['foreign_key_name'] => array( - 'table' => $field['settings']['foreign_key_name'], - 'columns' => array($field['settings']['foreign_key_name'] => 'id'), + $foreign_key_name => array( + 'table' => $foreign_key_name, + 'columns' => array($foreign_key_name => 'id'), ), ); } 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 6547f5bc3aba8f3fa04d3c60ea74c5d14120fdf6..b89c6f2c2f42979e34721961662e6fa4c5ad29c2 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverview.php @@ -46,7 +46,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $label = array( 'label' => array( '#type' => 'select', - '#title' => $this->t('Label display for @title', array('@title' => $instance['label'])), + '#title' => $this->t('Label display for @title', array('@title' => $instance->getFieldLabel())), '#title_display' => 'invisible', '#options' => $this->getFieldLabelOptions(), '#default_value' => $display_options ? $display_options['label'] : 'above', @@ -57,7 +57,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $field_row = array_slice($field_row, 0, $label_position, TRUE) + $label + array_slice($field_row, $label_position, count($field_row) - 1, TRUE); // Update the (invisible) title of the 'plugin' column. - $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $instance['label'])); + $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $instance->getFieldLabel())); if (!empty($field_row['plugin']['settings_edit_form'])) { $plugin_type_info = $entity_display->getRenderer($field_id)->getPluginDefinition(); $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Format settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>'; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php index edd687af28d33a5f05f04c8ab2aa414d20a2a969..ede866cd03d0c72579e99a9ff4092598344ff166 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -218,8 +218,8 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, * A table row array. */ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, EntityDisplayBaseInterface $entity_display, array $form, array &$form_state) { - $field = $instance->getField(); $display_options = $entity_display->getComponent($field_id); + $label = $instance->getFieldLabel(); $field_row = array( '#attributes' => array('class' => array('draggable', 'tabledrag-leaf')), @@ -227,14 +227,14 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En '#region_callback' => array($this, 'getRowRegion'), '#js_settings' => array( 'rowHandler' => 'field', - 'defaultPlugin' => $this->getDefaultPlugin($field['type']), + 'defaultPlugin' => $this->getDefaultPlugin($instance->getFieldType()), ), 'human_name' => array( - '#markup' => check_plain($instance['label']), + '#markup' => check_plain($label), ), 'weight' => array( '#type' => 'textfield', - '#title' => $this->t('Weight for @title', array('@title' => $instance['label'])), + '#title' => $this->t('Weight for @title', array('@title' => $label)), '#title_display' => 'invisible', '#default_value' => $display_options ? $display_options['weight'] : '0', '#size' => 3, @@ -243,7 +243,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En 'parent_wrapper' => array( 'parent' => array( '#type' => 'select', - '#title' => $this->t('Label display for @title', array('@title' => $instance['label'])), + '#title' => $this->t('Label display for @title', array('@title' => $label)), '#title_display' => 'invisible', '#options' => drupal_map_assoc(array_keys($this->getRegions())), '#empty_value' => '', @@ -262,9 +262,9 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $field_row['plugin'] = array( 'type' => array( '#type' => 'select', - '#title' => $this->t('Plugin for @title', array('@title' => $instance['label'])), + '#title' => $this->t('Plugin for @title', array('@title' => $label)), '#title_display' => 'invisible', - '#options' => $this->getPluginOptions($field['type']), + '#options' => $this->getPluginOptions($instance->getFieldType()), '#default_value' => $display_options ? $display_options['type'] : 'hidden', '#parents' => array('fields', $field_id, 'type'), '#attributes' => array('class' => array('field-plugin-type')), 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 b003549f1e68d0b7c83ebaf1ac021ead4cfe13e8..13c96b5d1ce7f842aaa490daab28d226d981544e 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php @@ -125,14 +125,14 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, 'id' => drupal_html_class($name), ), 'label' => array( - '#markup' => check_plain($instance['label']), + '#markup' => check_plain($instance->getFieldLabel()), ), 'field_name' => array( - '#markup' => $instance['field_name'], + '#markup' => $instance->getFieldName(), ), 'type' => array( '#type' => 'link', - '#title' => $field_types[$field['type']]['label'], + '#title' => $field_types[$field->getFieldType()]['label'], '#href' => $admin_field_path . '/field', '#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))), ), @@ -161,7 +161,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL, '#links' => $links, ); - if (!empty($field['locked'])) { + if (!empty($field->locked)) { $table[$name]['operations'] = array('#markup' => $this->t('Locked')); $table[$name]['#attributes']['class'][] = 'menu-disabled'; } @@ -423,20 +423,21 @@ public function submitForm(array &$form, array &$form_state) { $form_state['fields_added']['_add_new_field'] = $values['field_name']; } catch (\Exception $e) { - drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $instance['label'], '!message' => $e->getMessage())), 'error'); + drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $instance->getFieldLabel(), '!message' => $e->getMessage())), 'error'); } } // Re-use existing field. if (!empty($form_values['_add_existing_field']['field_name'])) { $values = $form_values['_add_existing_field']; - $field = field_info_field($this->entity_type, $values['field_name']); - if (!empty($field['locked'])) { + $field_name = $values['field_name']; + $field = field_info_field($this->entity_type, $field_name); + if (!empty($field->locked)) { drupal_set_message($this->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_name, 'entity_type' => $this->entity_type, 'bundle' => $this->bundle, 'label' => $values['label'], @@ -450,14 +451,14 @@ public function submitForm(array &$form, array &$form_state) { // default widget and settings). It stays hidden for other form modes // until it is explicitly configured. entity_get_form_display($this->entity_type, $this->bundle, 'default') - ->setComponent($field['field_name']) + ->setComponent($field_name) ->save(); // 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_name) ->save(); $destinations[] = $this->adminPath . '/fields/' . $new_instance->id(); @@ -465,7 +466,7 @@ public function submitForm(array &$form, array &$form_state) { $form_state['fields_added']['_add_existing_field'] = $instance['field_name']; } catch (\Exception $e) { - drupal_set_message($this->t('There was a problem creating field instance %label: @message.', array('%label' => $instance['label'], '@message' => $e->getMessage())), 'error'); + drupal_set_message($this->t('There was a problem creating field instance %label: @message.', array('%label' => $instance->getFieldLabel(), '@message' => $e->getMessage())), 'error'); } } } @@ -511,16 +512,17 @@ protected function getExistingFieldOptions() { $field_types = $this->fieldTypeManager->getDefinitions(); $instances = $this->entityManager->getStorageController('field_instance')->loadMultiple($instance_ids); foreach ($instances as $instance) { - $field = $instance->getField(); // Do not show: // - locked fields, // - fields that should not be added via user interface. - if (empty($field['locked']) && empty($field_types[$field['type']]['no_ui'])) { - $options[$field->name] = array( - 'type' => $field->type, - 'type_label' => $field_types[$field->type]['label'], - 'field' => $field->name, - 'label' => $instance->label, + $field_type = $instance->getFieldType(); + $field = $instance->getField(); + if (empty($field->locked) && empty($field_types[$field_type]['no_ui'])) { + $options[$instance->getFieldName()] = array( + 'type' => $field_type, + 'type_label' => $field_types[$field_type]['label'], + 'field' => $instance->getFieldName(), + 'label' => $instance->getFieldLabel(), ); } } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php index 2924c3512767b6475db34b7dbe51701bd1871135..f59cab86d43414c93edee313a9a88c1134ecdeae 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldDeleteForm.php @@ -46,7 +46,7 @@ public static function create(ContainerInterface $container) { * {@inheritdoc} */ public function getQuestion() { - return $this->t('Are you sure you want to delete the field %field?', array('%field' => $this->entity->label())); + return $this->t('Are you sure you want to delete the field %field?', array('%field' => $this->entity->getFieldLabel())); } /** @@ -71,7 +71,7 @@ public function submit(array $form, array &$form_state) { $bundles = entity_get_bundles(); $bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label']; - if ($field && !$field['locked']) { + if ($field && !$field->locked) { $this->entity->delete(); drupal_set_message($this->t('The field %field has been deleted from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label))); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 67fa7d6625d7dedaba595552e60622174dad772f..337fdce35cda32d73957fcc7129885c972e3a09a 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -109,7 +109,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac } // Build the configurable field values. - $cardinality = $field['cardinality']; + $cardinality = $field->getFieldCardinality(); $form['field']['cardinality_container'] = array( // We can't use the container element because it doesn't support the title // or description properties. @@ -145,10 +145,10 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac ); // 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->getFieldName()); + $form['field']['type'] = array('#type' => 'value', '#value' => $field->getFieldType()); + $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 @@ -158,9 +158,9 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac ); // Create an arbitrary entity object, so that we can have an instantiated // FieldItem. - $ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL); + $ids = (object) array('entity_type' => $this->instance->entity_type, 'bundle' => $this->instance->bundle, 'entity_id' => NULL); $entity = _field_create_entity_from_ids($ids); - $form['field']['settings'] += $entity->get($field['field_name'])->offsetGet(0)->settingsForm($form, $form_state, $field->hasData()); + $form['field']['settings'] += $entity->get($field->getFieldName())->offsetGet(0)->settingsForm($form, $form_state, $field->hasData()); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save field settings')); @@ -198,7 +198,7 @@ public function submitForm(array &$form, array &$form_state) { // Merge incoming form values into the existing field. $field = $this->instance->getField(); foreach ($field_values as $key => $value) { - $field[$key] = $value; + $field->{$key} = $value; } // Update the field. diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php index b5b7e629a3adc8d7e331cf3bb193ef8bcde50338..2fbe6f7083b2cf5d50fc4c467749a08c265cb27b 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php @@ -64,25 +64,25 @@ public function getFormID() { public function buildForm(array $form, array &$form_state, FieldInstanceInterface $field_instance = NULL) { $this->instance = $form_state['instance'] = $field_instance; - $bundle = $this->instance['bundle']; - $entity_type = $this->instance['entity_type']; + $bundle = $this->instance->bundle; + $entity_type = $this->instance->entity_type; $field = $this->instance->getField(); $bundles = entity_get_bundles(); drupal_set_title($this->t('%instance settings for %bundle', array( - '%instance' => $this->instance->label(), + '%instance' => $this->instance->getFieldLabel(), '%bundle' => $bundles[$entity_type][$bundle]['label'], )), PASS_THROUGH); $form['#field'] = $field; // Create an arbitrary entity object (used by the 'default value' widget). - $ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL); + $ids = (object) array('entity_type' => $this->instance->entity_type, 'bundle' => $this->instance->bundle, 'entity_id' => NULL); $form['#entity'] = _field_create_entity_from_ids($ids); - $items = $form['#entity']->get($this->instance['field_name']); + $items = $form['#entity']->get($this->instance->getFieldName()); - if (!empty($field['locked'])) { + if (!empty($field->locked)) { $form['locked'] = array( - '#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->instance->label())), + '#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->instance->getFieldLabel())), ); return $form; } @@ -95,7 +95,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac // Build the non-configurable instance values. $form['instance']['field_name'] = array( '#type' => 'value', - '#value' => $this->instance['field_name'], + '#value' => $this->instance->getFieldName(), ); $form['instance']['entity_type'] = array( '#type' => 'value', @@ -110,7 +110,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['label'] = array( '#type' => 'textfield', '#title' => $this->t('Label'), - '#default_value' => $this->instance->label() ?: $field['field_name'], + '#default_value' => $this->instance->getFieldLabel() ?: $field->getFieldName(), '#required' => TRUE, '#weight' => -20, ); @@ -118,7 +118,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['description'] = array( '#type' => 'textarea', '#title' => $this->t('Help text'), - '#default_value' => !empty($this->instance['description']) ? $this->instance['description'] : '', + '#default_value' => $this->instance->getFieldDescription(), '#rows' => 5, '#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '<br />' . $this->t('This field supports tokens.'), '#weight' => -10, @@ -127,7 +127,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac $form['instance']['required'] = array( '#type' => 'checkbox', '#title' => $this->t('Required field'), - '#default_value' => !empty($this->instance['required']), + '#default_value' => $this->instance->isFieldRequired(), '#weight' => -5, ); @@ -163,7 +163,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac */ public function validateForm(array &$form, array &$form_state) { if (isset($form['instance']['default_value'])) { - $items = $form['#entity']->get($this->instance['field_name']); + $items = $form['#entity']->get($this->instance->getFieldName()); $items->defaultValuesFormValidate($form['instance']['default_value'], $form, $form_state); } } @@ -175,18 +175,18 @@ public function submitForm(array &$form, array &$form_state) { // Handle the default value. $default_value = array(); if (isset($form['instance']['default_value'])) { - $items = $form['#entity']->get($this->instance['field_name']); + $items = $form['#entity']->get($this->instance->getFieldName()); $default_value = $items->defaultValuesFormSubmit($form['instance']['default_value'], $form, $form_state); } - $this->instance['default_value'] = $default_value; + $this->instance->default_value = $default_value; // Merge incoming values into the instance. foreach ($form_state['values']['instance'] as $key => $value) { - $this->instance[$key] = $value; + $this->instance->$key = $value; } $this->instance->save(); - drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->instance->label()))); + drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->instance->getFieldLabel()))); $form_state['redirect'] = $this->getNextDestination(); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php index bdbea8acccd9d16b26a4377b57737a7c276a050b..a60b3290687f3ed2f6c66d2768c049f5595efc67 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/FormDisplayOverview.php @@ -42,7 +42,7 @@ protected function buildFieldRow($field_id, FieldInstanceInterface $instance, En $field_row = parent::buildFieldRow($field_id, $instance, $entity_display, $form, $form_state); // Update the (invisible) title of the 'plugin' column. - $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $instance['label'])); + $field_row['plugin']['#title'] = $this->t('Formatter for @title', array('@title' => $instance->getFieldLabel())); if (!empty($field_row['plugin']['settings_edit_form']) && ($plugin = $entity_display->getRenderer($field_id))) { $plugin_type_info = $plugin->getPluginDefinition(); $field_row['plugin']['settings_edit_form']['label']['#markup'] = $this->t('Widget settings:') . ' <span class="plugin-name">' . $plugin_type_info['label'] . '</span>'; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php index daf263ec428f53685b1bbc23b57ea0dd20f1e2d4..0cb1c932df273a534cc0cf348c5252d0776e3759 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php @@ -243,10 +243,6 @@ function testNonInitializedFields() { ); $this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $edit); - // Check that no settings have been set for the 'teaser' mode. - $instance = field_info_instance('node', 'field_test', $this->type); - $this->assertFalse(isset($instance['display']['teaser'])); - // Check that the field appears as 'hidden' on the 'Manage display' page // for the 'teaser' mode. $this->drupalGet('admin/structure/types/manage/' . $this->type . '/display/teaser'); 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 79b1fbe86c4c6b886ebba37b00b973ba459fac6e..1a8f65e5e4edac9a2395c6d65b3e2caaa846de59 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 @@ -225,11 +225,11 @@ function assertFieldSettings($bundle, $field_name, $string = 'dummy test string' field_info_cache_clear(); // Assert field settings. $field = field_info_field($entity_type, $field_name); - $this->assertTrue($field['settings']['test_field_setting'] == $string, 'Field settings were found.'); + $this->assertTrue($field->getFieldSetting('test_field_setting') == $string, 'Field settings were found.'); // Assert instance settings. $instance = field_info_instance($entity_type, $field_name, $bundle); - $this->assertTrue($instance['settings']['test_instance_setting'] == $string, 'Field instance settings were found.'); + $this->assertTrue($instance->getFieldSetting('test_instance_setting') == $string, 'Field instance settings were found.'); } /** @@ -301,7 +301,7 @@ function testDefaultValue() { $this->assertText("Saved $field_name configuration", 'The form was successfully submitted.'); field_info_cache_clear(); $instance = field_info_instance('node', $field_name, $this->type); - $this->assertEqual($instance['default_value'], array(array('value' => 1)), 'The default value was correctly saved.'); + $this->assertEqual($instance->default_value, array(array('value' => 1)), 'The default value was correctly saved.'); // Check that the default value shows up in the form $this->drupalGet($admin_path); @@ -313,10 +313,10 @@ function testDefaultValue() { $this->assertText("Saved $field_name configuration", 'The form was successfully submitted.'); field_info_cache_clear(); $instance = field_info_instance('node', $field_name, $this->type); - $this->assertEqual($instance['default_value'], NULL, 'The default value was correctly saved.'); + $this->assertEqual($instance->default_value, NULL, 'The default value was correctly saved.'); // Check that the default widget is used when the field is hidden. - entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') + entity_get_form_display($instance->entity_type, $instance->bundle, 'default') ->removeComponent($field_name)->save(); $this->drupalGet($admin_path); $this->assertFieldById($element_id, '', 'The default value widget was displayed when field is hidden.'); diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc index 430f79f2b7bc8bbd2ad1f8aeff3f4a05a74e3352..723abc6f22099eefb83bab9347a620f7a919d988 100644 --- a/core/modules/file/file.field.inc +++ b/core/modules/file/file.field.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\NestedArray; +use Drupal\field\FieldInterface; /** * Implements hook_field_info_alter(). @@ -52,16 +53,19 @@ function file_field_widget_value($element, $input = FALSE, $form_state) { */ function file_field_widget_multiple_count_validate($element, &$form_state, $form) { $parents = $element['#parents']; + $entity_type = $element['#entity_type']; + $field_name = $element['#field_name']; $values = NestedArray::getValue($form_state['values'], $parents); array_pop($parents); $current = count(element_children(NestedArray::getValue($form, $parents))) - 1; - $field = field_info_field($element['#entity_type'], $element['#field_name']); + $field = field_info_field($entity_type, $field_name); + $cardinality = $field->getFieldCardinality(); $uploaded = count($values['fids']); $count = $uploaded + $current; - if ($count > $field['cardinality']) { - $keep = $uploaded - $count + $field['cardinality']; + if ($count > $cardinality) { + $keep = $uploaded - $count + $cardinality; $removed_files = array_slice($values['fids'], $keep); $removed_names = array(); foreach ($removed_files as $fid) { @@ -72,8 +76,8 @@ function file_field_widget_multiple_count_validate($element, &$form_state, $form t( 'Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', array( - '%field' => $field['field_name'], - '@max' => $field['cardinality'], + '%field' => $field_name, + '@max' => $cardinality, '@count' => $keep, '%list' => implode(', ', $removed_names), ) @@ -485,15 +489,16 @@ function theme_file_upload_help($variables) { /** * Determine whether a field references files stored in {file_managed}. * - * @param array $field - * A field array. + * @param Drupal\field\FieldInterface $field + * A field definition. * * @return * The field column if the field references {file_managed}.fid, typically * fid, FALSE if it doesn't. */ -function file_field_find_file_reference_column($field) { - foreach ($field['foreign keys'] as $data) { +function file_field_find_file_reference_column(FieldInterface $field) { + $schema = $field->getSchema(); + foreach ($schema['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.module b/core/modules/file/file.module index 16ce43f74e266e0eaf0a65721ebd8599743d5ad9..1a8b61e30f015cd7c15693388c047954f62972bf 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1869,15 +1869,15 @@ function file_get_file_references(File $file, $field = NULL, $age = EntityStorag // This contains the possible field names. $instances = field_info_instances($entity_type, $bundle); foreach ($instances as $field_name => $instance) { - $current_field = $instance->getField(); + $field_type = $instance->getFieldType(); // 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[$field_type])) { + $field_columns[$field_type] = file_field_find_file_reference_column($instance->getField()); } // 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[$field_type]) { + $file_fields[$entity_type][$bundle][$field_name] = $field_columns[$field_type]; } } } @@ -1909,7 +1909,7 @@ function file_get_file_references(File $file, $field = NULL, $age = EntityStorag foreach ($return as $field_name => $data) { foreach (array_keys($data) as $entity_type) { $current_field = field_info_field($entity_type, $field_name); - if (($field_type && $current_field['type'] != $field_type) || ($field && $field['id'] != $current_field['id'])) { + if (($field_type && $current_field->getFieldType() != $field_type) || ($field && $field->uuid() != $current_field->uuid())) { unset($return[$field_name][$entity_type]); } } diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc index 6ae04af259e2303e850f702e5345507e122a028e..f42a7b07a2ced9fbff50ad4532ad74acba5bbb84 100644 --- a/core/modules/file/file.views.inc +++ b/core/modules/file/file.views.inc @@ -467,12 +467,12 @@ function file_field_views_data(FieldInterface $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'] . '_target_id']['relationship'] = array( + $data[$table_name][$field->getFieldName() . '_target_id']['relationship'] = array( 'id' => 'standard', 'base' => 'file_managed', 'entity type' => 'file', 'base field' => 'target_id', - 'label' => t('file from !field_name', array('!field_name' => $field['field_name'])), + 'label' => t('file from !field_name', array('!field_name' => $field->getFieldName())), ); } @@ -485,23 +485,24 @@ function file_field_views_data(FieldInterface $field) { * Views integration to provide reverse relationships on file fields. */ function file_field_views_data_views_data_alter(array &$data, FieldInterface $field) { - $entity_type = $field['entity_type']; + $entity_type = $field->entity_type; $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $field_name = $field->getFieldName(); + $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type; - list($label,) = field_views_field_label($entity_type, $field['field_name']); + list($label,) = field_views_field_label($entity_type, $field_name); $data['file_managed'][$pseudo_field_name]['relationship'] = array( 'title' => t('@entity using @field', array('@entity' => $entity_info['label'], '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the file.', array('@entity' => $entity_info['label'], '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], - 'entity_type' => $field['entity_type'], + 'field_name' => $field_name, + 'entity_type' => $entity_type, 'field table' => DatabaseStorageController::_fieldTableName($field), - 'field field' => $field['field_name'] . '_target_id', + 'field field' => $field_name . '_target_id', '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_name)), 'join_extra' => array( 0 => array( 'field' => 'deleted', diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index 09907586e9bd972fa6eb4f673c60efb78198b059..7edeec7b1530bcbdbee65eff000f96956e12d400 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -124,12 +124,11 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra */ function updateFileField($name, $type_name, $instance_settings = array(), $widget_settings = array()) { $instance = field_info_instance('node', $name, $type_name); - $instance['settings'] = array_merge($instance['settings'], $instance_settings); - + $instance->settings = array_merge($instance->settings, $instance_settings); $instance->save(); - entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') - ->setComponent($instance['field_name'], array( + entity_get_form_display('node', $type_name, 'default') + ->setComponent($name, array( 'settings' => $widget_settings, )) ->save(); @@ -162,7 +161,7 @@ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, // Attach a file to the node. $field = field_info_field('node', $field_name); $name = 'files[' . $field_name . '_0]'; - if ($field['cardinality'] != 1) { + if ($field->getFieldCardinality() != 1) { $name .= '[]'; } $edit[$name] = drupal_realpath($file->getFileUri()); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index 19a3e31e992756f53254d14544598f075aadc6e7..18bead4afcdd093ce77513b6d39f58e059e1bb14 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -7,7 +7,7 @@ namespace Drupal\file\Tests; -use Drupal\Core\Language\Language; +use Drupal\field\Field; /** * Tests various validations. @@ -31,14 +31,14 @@ function testRequired() { $type_name = 'article'; $field_name = strtolower($this->randomName()); $field = $this->createFileField($field_name, 'node', $type_name, array(), array('required' => '1')); - $instance = field_info_instance($field_name, 'node', $type_name); + $instance = Field::fieldInfo()->getInstance('node', $type_name, $field_name); $test_file = $this->getTestFile('text'); // Try to post a new node without uploading a file. $edit = array("title" => $this->randomName()); $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish')); - $this->assertRaw(t('!title field is required.', array('!title' => $instance['label'])), 'Node save failed when required file field was empty.'); + $this->assertRaw(t('!title field is required.', array('!title' => $instance->getFieldLabel())), 'Node save failed when required file field was empty.'); // Create a new node with the uploaded file. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); @@ -57,7 +57,7 @@ function testRequired() { // Try to post a new node without uploading a file in the multivalue field. $edit = array('title' => $this->randomName()); $this->drupalPostForm('node/add/' . $type_name, $edit, t('Save and publish')); - $this->assertRaw(t('!title field is required.', array('!title' => $instance['label'])), 'Node save failed when required multiple value file field was empty.'); + $this->assertRaw(t('!title field is required.', array('!title' => $instance->getFieldLabel())), 'Node save failed when required multiple value file field was empty.'); // Create a new node with the uploaded file into the multivalue field. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); diff --git a/core/modules/file/tests/file_module_test.module b/core/modules/file/tests/file_module_test.module index fc116ad7a6c17980f68698c0310581424bc2e83c..f76488ceefdc0643da9d0568296ff9df52af5560 100644 --- a/core/modules/file/tests/file_module_test.module +++ b/core/modules/file/tests/file_module_test.module @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\file\Entity\File; +use Drupal\field\FieldInterface; /** * Implements hook_menu(). @@ -87,8 +88,8 @@ 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()); +function file_module_test_file_download_access(FieldInterface $field, EntityInterface $entity, File $file) { + $instance = field_info_instance($entity->entityType(), $field->getFieldName(), $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.module b/core/modules/forum/forum.module index 05cd432707af97a40852c0164339f08f3b016e24..4593c72bfe9a5ec638a40bdb4e33a517e7b4c614 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -159,7 +159,7 @@ function forum_menu_local_tasks(&$data, $route_name) { $links = array(); // Loop through all bundles for forum taxonomy vocabulary field. $field = Field::fieldInfo()->getField('node', 'taxonomy_forums'); - foreach ($field['bundles'] as $type) { + foreach ($field->getBundles() as $type) { if (node_access('create', $type)) { $links[$type] = array( '#theme' => 'menu_local_action', diff --git a/core/modules/image/image.views.inc b/core/modules/image/image.views.inc index 3cba1213a70a3f32f8214a1e943823f070151ea6..7ab6ac65d12b17a51b42fabf81fa9b3e7f1f17fe 100644 --- a/core/modules/image/image.views.inc +++ b/core/modules/image/image.views.inc @@ -22,11 +22,11 @@ function image_field_views_data(FieldInterface $field) { $data = field_views_field_default_views_data($field); foreach ($data as $table_name => $table_data) { // Add the relationship only on the target_id field. - $data[$table_name][$field['field_name'] . '_target_id']['relationship'] = array( + $data[$table_name][$field->getFieldName() . '_target_id']['relationship'] = array( 'id' => 'standard', 'base' => 'file_managed', 'base field' => 'target_id', - 'label' => t('image from !field_name', array('!field_name' => $field['field_name'])), + 'label' => t('image from !field_name', array('!field_name' => $field->getFieldName())), ); } @@ -39,23 +39,24 @@ function image_field_views_data(FieldInterface $field) { * Views integration to provide reverse relationships on image fields. */ function image_field_views_data_views_data_alter(array &$data, FieldInterface $field) { - $entity_type = $field['entity_type']; + $entity_type = $field->entity_type; + $field_name = $field->getFieldName(); $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type; - list($label,) = field_views_field_label($entity_type, $field['field_name']); + list($label,) = field_views_field_label($entity_type, $field_name); $data['file_managed'][$pseudo_field_name]['relationship'] = array( 'title' => t('@entity using @field', array('@entity' => $entity_info['label'], '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the image.', array('@entity' => $entity_info['label'], '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], - 'entity_type' => $field['entity_type'], + 'field_name' => $field_name, + 'entity_type' => $entity_type, 'field table' => DatabaseStorageController::_fieldTableName($field), - 'field field' => $field['field_name'] . '_target_id', + 'field field' => $field_name . '_target_id', '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_name)), 'join_extra' => array( 0 => array( 'field' => 'deleted', diff --git a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php index b9f326772d29b19e2fe8a51088de76ffb72ab4aa..aabef1e28b081f904ac77d8a228628bf9a6d0629 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -145,30 +145,29 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont */ protected static function replaceImageStyle(ImageStyleInterface $style) { if ($style->id() != $style->getOriginalID()) { - $instances = field_read_instances(); // Loop through all fields searching for image fields. - foreach ($instances as $instance) { - if ($instance->getField()->type == 'image') { - $view_modes = entity_get_view_modes($instance['entity_type']); - $view_modes = array('default') + array_keys($view_modes); + foreach (field_read_instances() as $instance) { + if ($instance->getFieldType() == 'image') { + $field_name = $instance->getFieldName(); + $view_modes = array('default') + array_keys(entity_get_view_modes($instance->entity_type)); foreach ($view_modes as $view_mode) { - $display = entity_get_display($instance['entity_type'], $instance['bundle'], $view_mode); - $display_options = $display->getComponent($instance['field_name']); + $display = entity_get_display($instance->entity_type, $instance->bundle, $view_mode); + $display_options = $display->getComponent($field_name); // Check if the formatter involves an image style. if ($display_options && $display_options['type'] == 'image' && $display_options['settings']['image_style'] == $style->getOriginalID()) { // Update display information for any instance using the image // style that was just deleted. $display_options['settings']['image_style'] = $style->id(); - $display->setComponent($instance['field_name'], $display_options) + $display->setComponent($field_name, $display_options) ->save(); } } - $entity_form_display = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default'); - $widget_configuration = $entity_form_display->getComponent($instance['field_name']); + $entity_form_display = entity_get_form_display($instance->entity_type, $instance->bundle, 'default'); + $widget_configuration = $entity_form_display->getComponent($field_name); if ($widget_configuration['settings']['preview_image_style'] == $style->getOriginalID()) { $widget_options['settings']['preview_image_style'] = $style->id(); - $entity_form_display->setComponent($instance['field_name'], $widget_options) + $entity_form_display->setComponent($field_name, $widget_options) ->save(); } } diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php index 45b2eef6e99f4739fb99a2b67e2ee3a430b07786..698b34b72a08f85f1335e85b35b86aa8530d1e8d 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDefaultImagesTest.php @@ -82,7 +82,7 @@ public function testDefaultImages() { )); $instance2->save(); - $widget_settings = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($field_name); + $widget_settings = entity_get_form_display('node', $instance->bundle, 'default')->getComponent($field_name); entity_get_form_display('node', 'page', 'default') ->setComponent($field_name, $widget_settings) ->save(); @@ -157,7 +157,7 @@ public function testDefaultImages() { ); // Upload a new default for the field. - $field['settings']['default_image'] = array($default_images['field_new']->id()); + $field->settings['default_image'] = array($default_images['field_new']->id()); $field->save(); // Confirm that the new default is used on the article field settings form. @@ -192,7 +192,7 @@ public function testDefaultImages() { ); // Upload a new default for the article's field instance. - $instance['settings']['default_image'] = $default_images['instance_new']->id(); + $instance->settings['default_image'] = $default_images['instance_new']->id(); $instance->save(); // Confirm the new field instance default is used on the article field @@ -231,7 +231,7 @@ public function testDefaultImages() { ); // Remove the instance default from articles. - $instance['settings']['default_image'] = 0; + $instance->settings['default_image'] = 0; $instance->save(); // Confirm the article field instance default has been removed. diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 5c2746251ed919e722f61e21e68c96d37bc8e069..53261467572d944fb8b25df4fe4fd94eb9ac1611 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -248,7 +248,7 @@ function testImageFieldDefaultImage() { // Clear field info cache so the new default image is detected. field_info_cache_clear(); $field = field_info_field('node', $field_name); - $file = file_load($field['settings']['default_image']); + $file = file_load($field->getFieldSetting('default_image')); $this->assertTrue($file->isPermanent(), 'The default image status is permanent.'); $image = array( '#theme' => 'image', @@ -281,7 +281,7 @@ function testImageFieldDefaultImage() { // Clear field info cache so the new default image is detected. field_info_cache_clear(); $field = field_info_field('node', $field_name); - $this->assertFalse($field['settings']['default_image'], 'Default image removed from field.'); + $this->assertFalse($field->getFieldSetting('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()); @@ -295,7 +295,7 @@ function testImageFieldDefaultImage() { field_info_cache_clear(); $private_field = field_info_field('node', $private_field_name); - $file = file_load($private_field['settings']['default_image']); + $file = file_load($private_field->getFieldSetting('default_image')); $this->assertEqual('private', file_uri_scheme($file->getFileUri()), 'Default image uses private:// scheme.'); $this->assertTrue($file->isPermanent(), '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 9075b46da2b5b5ce38a7713250d46bddddb1557d..e71beac2c9ae3d5bb4e5b86e4c272172d725540c 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -460,7 +460,7 @@ function testLinkSeparateFormatter() { // Update the field formatter settings. $display_options['settings'] = array($setting => $new_value); entity_get_display('entity_test', 'entity_test', 'full') - ->setComponent($this->field['field_name'], $display_options) + ->setComponent($field_name, $display_options) ->save(); $this->renderTestEntity($id); diff --git a/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php b/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php index 8f8009682bf2e2900eaa75ff0d20ade75ea45b07..fe796ce871b7375d55ff21a1d21811cdafad11e9 100644 --- a/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php +++ b/core/modules/node/lib/Drupal/node/Plugin/views/wizard/Node.php @@ -265,12 +265,13 @@ protected function buildFilters(&$form, &$form_state) { } $tag_fields = array(); foreach ($bundles as $bundle) { - foreach (field_info_instances($this->entity_type, $bundle) as $instance) { - $widget = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($instance['field_name']); + $display = entity_get_form_display($this->entity_type, $bundle, 'default'); + foreach (field_info_instances($this->entity_type, $bundle) as $field_name => $instance) { + $widget = $display->getComponent($field_name); // We define "tag-like" taxonomy fields as ones that use the // "Autocomplete term widget (tagging)" widget. if ($widget['type'] == 'taxonomy_autocomplete') { - $tag_fields[] = $instance['field_name']; + $tag_fields[] = $field_name; } } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index 598d5521e9cb506c0e6541f32d4b3f994774dc10..5589b1c94a4dd8a2028bb2fb837fa1e2c4d411c4 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php @@ -84,7 +84,7 @@ function testNodeTypeEditing() { $this->drupalLogin($web_user); $instance = field_info_instance('node', 'body', 'page'); - $this->assertEqual($instance['label'], 'Body', 'Body field was found.'); + $this->assertEqual($instance->getFieldLabel(), 'Body', 'Body field was found.'); // Verify that title and body fields are displayed. $this->drupalGet('node/add/page'); diff --git a/core/modules/node/node.tokens.inc b/core/modules/node/node.tokens.inc index 161df68f283f042bd478f9ed477d274b81f068bd..2f5d821be29302efbbe32619b1a39f77373d1ab8 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -156,7 +156,7 @@ function node_tokens($type, $tokens, array $data = array(), array $options = arr $length = $settings['trim_length']; } - $output = text_summary($output, $instance['settings']['text_processing'] ? $item->format : NULL, $length); + $output = text_summary($output, $instance->getFieldSetting('text_processing') ? $item->format : NULL, $length); } } $replacements[$original] = $output; diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index 1a1e2b405764bcc4a7ddea4d553b6436fe6c835a..8a1d9b2f061139d1c104a3feed63279d97dade66 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -62,23 +62,23 @@ function setUp() { */ function testNumberDecimalField() { // Create a field with settings to validate. - $this->field = entity_create('field_entity', array( - 'name' => drupal_strtolower($this->randomName()), + $field_name = drupal_strtolower($this->randomName()); + entity_create('field_entity', array( + 'name' => $field_name, 'entity_type' => 'entity_test', 'type' => 'number_decimal', 'settings' => array( 'precision' => 8, 'scale' => 4, 'decimal_separator' => '.', ) - )); - $this->field->save(); + ))->save(); entity_create('field_instance', array( - 'field_name' => $this->field->name, + 'field_name' => $field_name, 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->name, array( + ->setComponent($field_name, array( 'type' => 'number', 'settings' => array( 'placeholder' => '0.00' @@ -86,14 +86,14 @@ function testNumberDecimalField() { )) ->save(); entity_get_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->name, array( + ->setComponent($field_name, array( 'type' => 'number_decimal', )) ->save(); // Display creation form. $this->drupalGet('entity_test/add'); - $this->assertFieldByName("{$this->field['field_name']}[0][value]", '', 'Widget is displayed'); + $this->assertFieldByName("{$field_name}[0][value]", '', 'Widget is displayed'); $this->assertRaw('placeholder="0.00"'); // Submit a signed decimal value within the allowed precision and scale. @@ -101,7 +101,7 @@ function testNumberDecimalField() { $edit = array( 'user_id' => 1, 'name' => $this->randomName(), - "{$this->field['field_name']}[0][value]" => $value, + "{$field_name}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)|', $this->url, $match); @@ -121,10 +121,10 @@ function testNumberDecimalField() { foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); $edit = array( - "{$this->field['field_name']}[0][value]" => $wrong_entry, + "{$field_name}[0][value]" => $wrong_entry, ); $this->drupalPostForm(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' => $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. @@ -139,10 +139,10 @@ function testNumberDecimalField() { foreach ($wrong_entries as $wrong_entry) { $this->drupalGet('entity_test/add'); $edit = array( - "{$this->field['field_name']}[0][value]" => $wrong_entry, + "{$field_name}[0][value]" => $wrong_entry, ); $this->drupalPostForm(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' => $field_name)), 'Correctly failed to save decimal value with minus sign in the wrong position.'); } } diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php index fa542388a207bd56a2a916e55eb91a57921b0e54..7f18ec2e382ab6cff5f4dd27d9ea94471bab0fce 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldUITest.php @@ -232,9 +232,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('node', $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->getFieldSetting('allowed_values'), $allowed_values, 'The allowed value is correct'); + $this->assertNull($field->getFieldSetting('on'), 'The on value is not saved into settings'); + $this->assertNull($field->getFieldSetting('off'), 'The off value is not saved into settings'); } /** @@ -282,7 +282,7 @@ protected function createOptionsField($type) { * element. * @param $result * Either an expected resulting array in - * $field['settings']['allowed_values'], or an expected error message. + * $field->getFieldSetting('allowed_values'), or an expected error message. * @param $message * Message to display. */ @@ -296,7 +296,7 @@ function assertAllowedValuesInput($input_string, $result, $message) { else { field_info_cache_clear(); $field = field_info_field('node', $this->field_name); - $this->assertIdentical($field['settings']['allowed_values'], $result, $message); + $this->assertIdentical($field->getFieldSetting('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 206b8c82015c131f73897ddab2c9c23b4add344a..877148c11bb79756901abd472cdf346be8dc7d0e 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -110,13 +110,13 @@ function setUp() { function testRadioButtons() { // Create an instance of the 'single value' field. $instance = entity_create('field_instance', array( - 'field_name' => $this->card_1->name, + 'field_name' => $this->card_1->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_1->name, array( + ->setComponent($this->card_1->getFieldName(), array( 'type' => 'options_buttons', )) ->save(); @@ -167,13 +167,13 @@ function testRadioButtons() { function testCheckBoxes() { // Create an instance of the 'multiple values' field. $instance = entity_create('field_instance', array( - 'field_name' => $this->card_2->name, + 'field_name' => $this->card_2->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_2->name, array( + ->setComponent($this->card_2->getFieldName(), array( 'type' => 'options_buttons', )) ->save(); @@ -257,14 +257,14 @@ function testCheckBoxes() { function testSelectListSingle() { // Create an instance of the 'single value' field. $instance = entity_create('field_instance', array( - 'field_name' => $this->card_1->name, + 'field_name' => $this->card_1->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', 'required' => TRUE, )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_1->name, array( + ->setComponent($this->card_1->getFieldName(), array( 'type' => 'options_select', )) ->save(); @@ -292,7 +292,7 @@ function testSelectListSingle() { // Submit form: select invalid 'none' option. $edit = array('card_1' => '_none'); $this->drupalPostForm(NULL, $edit, t('Save')); - $this->assertRaw(t('!title field is required.', array('!title' => $instance['field_name'])), 'Cannot save a required field when selecting "none" from the select list.'); + $this->assertRaw(t('!title field is required.', array('!title' => $instance->getFieldName())), 'Cannot save a required field when selecting "none" from the select list.'); // Submit form: select first option. $edit = array('card_1' => 0); @@ -322,8 +322,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'; $this->card_1->save(); // Display form: with no field data, nothing is selected @@ -357,13 +357,13 @@ function testSelectListSingle() { function testSelectListMultiple() { // Create an instance of the 'multiple values' field. $instance = entity_create('field_instance', array( - 'field_name' => $this->card_2->name, + 'field_name' => $this->card_2->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', )); $instance->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->card_2->name, array( + ->setComponent($this->card_2->getFieldName(), array( 'type' => 'options_select', )) ->save(); @@ -477,12 +477,12 @@ function testSelectListMultiple() { function testOnOffCheckbox() { // Create an instance of the 'boolean' field. entity_create('field_instance', array( - 'field_name' => $this->bool->name, + 'field_name' => $this->bool->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->bool->name, array( + ->setComponent($this->bool->getFieldName(), array( 'type' => 'options_onoff', )) ->save(); @@ -531,8 +531,9 @@ function testOnOffCheckboxLabelSetting() { $this->drupalLogin($admin_user); // Create a test field instance. + $field_name = 'bool'; entity_create('field_entity', array( - 'name' => 'bool', + 'name' => $field_name, 'entity_type' => 'node', 'type' => 'list_boolean', 'cardinality' => 1, @@ -541,13 +542,13 @@ function testOnOffCheckboxLabelSetting() { ), ))->save(); entity_create('field_instance', array( - 'field_name' => 'bool', + 'field_name' => $field_name, 'entity_type' => 'node', 'bundle' => 'page', ))->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($this->bool['field_name'], array( + ->setComponent($field_name, array( 'type' => 'options_onoff', )) ->save(); @@ -557,7 +558,6 @@ function testOnOffCheckboxLabelSetting() { $fieldEditUrl = 'admin/structure/types/manage/page/form-display'; $this->drupalGet($fieldEditUrl); - $field_name = $this->bool['field_name']; // Click on the widget settings button to open the widget settings form. $this->drupalPostAjaxForm(NULL, array(), $field_name . "_settings_edit"); diff --git a/core/modules/options/options.install b/core/modules/options/options.install index 6c2c8afff714d4d2a5aefff7d7292d6bd5be906b..40f49db81b396d895d95babc433ef338c4565005 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->getFieldType()) { case 'list_text': $columns = array( 'value' => array( diff --git a/core/modules/options/options.module b/core/modules/options/options.module index 3c649c502af731620ba0fe3a53176f5b66936ec2..5ab2241549eb9c44e08ed6c32e1d8a6cb73f248e 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -68,9 +68,10 @@ function options_field_info() { * Implements hook_field_settings_form(). */ function options_field_settings_form($field, $instance) { - $settings = $field['settings']; + $settings = $field->getFieldSettings(); + $field_type = $field->getFieldType(); - switch ($field['type']) { + switch ($field_type) { case 'list_integer': case 'list_float': case 'list_text': @@ -82,12 +83,12 @@ function options_field_settings_form($field, $instance) { '#element_validate' => array('options_field_settings_form_validate_allowed_values'), '#field_has_data' => $field->hasData(), '#field' => $field, - '#field_type' => $field['type'], + '#field_type' => $field_type, '#access' => empty($settings['allowed_values_function']), ); $description = '<p>' . 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 .= '<br/>' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); $description .= '<br/>' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); $description .= '<br/>' . 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.'); @@ -142,12 +143,9 @@ function options_field_settings_form($field, $instance) { } // Alter the description for allowed values depending on the widget type. - if ($instance['widget']['type'] == 'options_onoff') { + if ($field_type == 'list_boolean') { $form['allowed_values']['#description'] .= '<p>' . t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the <strong>Allowed values</strong> section. Note that the checkbox will be labeled with the label of the 'on' value.") . '</p>'; } - elseif ($instance['widget']['type'] == 'options_buttons') { - $form['allowed_values']['#description'] .= '<p>' . t("The 'checkboxes/radio buttons' widget will display checkboxes if the <em>Number of values</em> option is greater than 1 for this field, otherwise radios will be displayed.") . '</p>'; - } $form['allowed_values']['#description'] .= '<p>' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '</p>'; $form['allowed_values_function'] = array( @@ -167,10 +165,10 @@ function options_field_settings_form($field, $instance) { 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->getFieldType(); $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.')); @@ -194,7 +192,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->getFieldSetting('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.')); } @@ -368,11 +366,13 @@ function options_allowed_values_string($values) { * Implements hook_field_update_forbid(). */ function options_field_update_forbid($field, $prior_field) { - if ($field['module'] == 'options' && $field->hasData()) { + if ($field->module == 'options' && $field->hasData()) { // 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'])); + $allowed_values = $field->getFieldSetting('allowed_values'); + $prior_allowed_values = $prior_field->getFieldSetting('allowed_values'); + $lost_keys = array_diff(array_keys($prior_allowed_values), array_keys($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->getFieldName()))); } } } @@ -380,12 +380,11 @@ function options_field_update_forbid($field, $prior_field) { /** * Checks if a list of values are being used in actual field values. */ -function _options_values_in_use($field, $values) { +function _options_values_in_use(FieldInterface $field, $values) { if ($values) { - $field = field_info_field_by_id($field['uuid']); $factory = \Drupal::service('entity.query'); $result = $factory->get($field->entity_type) - ->condition($field['field_name'] . '.value', $values) + ->condition($field->getFieldName() . '.value', $values) ->count() ->accessCheck(FALSE) ->range(0, 1) @@ -418,9 +417,9 @@ 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[$instance->getFieldName()][$langcode][$delta][] = array( 'error' => 'list_illegal_value', - 'message' => t('%name: illegal value.', array('%name' => $instance['label'])), + 'message' => t('%name: illegal value.', array('%name' => $instance->getFieldLabel())), ); } } diff --git a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php index 9c7815c17584561ab3c3c36aa8cffb6535fe7bac..3fd241fecfcc98506c02eb64fb6ef8674d131cbe 100644 --- a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php @@ -74,14 +74,16 @@ public function getRelations() { protected function writeCache() { $data = array(); - foreach (field_info_fields() as $field) { - foreach ($field['bundles'] as $bundle) { - $relation_uri = $this->getRelationUri($field->entity_type, $bundle, $field->name); - $data[$relation_uri] = array( - 'entity_type' => $field->entity_type, - 'bundle' => $bundle, - 'field_name' => $field->name, - ); + foreach (field_info_field_map() as $entity_type => $entity_type_map) { + foreach ($entity_type_map as $field_name => $field_info) { + foreach ($field_info['bundles'] as $bundle) { + $relation_uri = $this->getRelationUri($entity_type, $bundle, $field_name); + $data[$relation_uri] = array( + 'entity_type' => $entity_type, + 'bundle' => $bundle, + 'field_name' => $field_name, + ); + } } } // These URIs only change when field info changes, so cache it permanently diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index f75e199b65356f7f4deb5d8d20b00c97e6dd51fe..5b2e9d889305d05bfe0dedcfc4f5fe8aaa3e203d 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\field\Field; + /** * Test integration searching comments. */ @@ -58,8 +60,8 @@ function testSearchResultsComment() { $comment_body = 'Test comment body'; // Make preview optional. - $instance = field_info_instance('node', 'comment', 'article'); - $instance['settings']['preview'] = DRUPAL_OPTIONAL; + $instance = Field::fieldInfo()->getInstance('node', 'article', 'comment'); + $instance->settings['preview'] = DRUPAL_OPTIONAL; $instance->save(); // Enable check_plain() for 'Basic HTML' text format. $basic_html_format_id = 'basic_html'; @@ -135,8 +137,8 @@ function testSearchResultsCommentAccess() { // Create a node. // Make preview optional. - $instance = field_info_instance('node', 'comment', 'article'); - $instance['settings']['preview'] = DRUPAL_OPTIONAL; + $instance = Field::fieldInfo()->getInstance('node', 'article', 'comment'); + $instance->settings['preview'] = DRUPAL_OPTIONAL; $instance->save(); $this->node = $this->drupalCreateNode(array('type' => 'article')); 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 68f6303768cffe28737d49ccef61bf0653cdf827..78326e9af5b3b01590df376b8818bf26076e82dd 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -106,7 +106,7 @@ function testEntityFormLanguage() { $field->translatable = TRUE; $field->save(); $field = field_info_field('node', 'body'); - $this->assertTrue($field['translatable'], 'Field body is translatable.'); + $this->assertTrue($field->isFieldTranslatable(), '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/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index d6fb95694fe9ae675bd21927e8303fb4bd2395b4..5e663ca12a2310fa23f410c2a0438d0049d7df1e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -483,7 +483,7 @@ function testEntityTranslationAPI() { $entity = $this->reloadEntity($entity); $instance_id = implode('.', array($entity->entityType(), $entity->bundle(), $this->field_name)); $instance = $this->entityManager->getStorageController('field_instance')->load($instance_id); - $instance['default_value_function'] = 'entity_test_field_default_value'; + $instance->default_value_function = 'entity_test_field_default_value'; $instance->save(); $translation = $entity->addTranslation($langcode2); $field = $translation->get($this->field_name); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php index 5efa6b89928f5600e60c7cf053f45dde0276a46c..956e995bdeab5acd2c4bb3d42baac3e1609b108f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php @@ -70,11 +70,12 @@ function setUp() { $entity_type = 'entity_test_rev'; $this->field_name = strtolower($this->randomName()); + $this->field_cardinality = 4; $this->field = entity_create('field_entity', array( 'name' => $this->field_name, 'entity_type' => $entity_type, 'type' => 'test_field', - 'cardinality' => 4, + 'cardinality' => $this->field_cardinality, )); $this->field->save(); $this->instance = entity_create('field_instance', array( @@ -113,7 +114,7 @@ function testFieldLoad() { $query = db_insert($this->revision_table)->fields($columns); foreach ($revision_ids as $revision_id) { // Put one value too many. - for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { + for ($delta = 0; $delta <= $this->field_cardinality; $delta++) { $value = mt_rand(1, 127); $values[$revision_id][] = $value; $query->values(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->id, $value)); @@ -130,7 +131,7 @@ function testFieldLoad() { foreach ($revision_ids as $revision_id) { $entity = $storage_controller->loadRevision($revision_id); foreach ($values[$revision_id] as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field_cardinality) { $this->assertEqual($entity->{$this->field_name}[$delta]->value, $value); } else { @@ -142,7 +143,7 @@ function testFieldLoad() { // Load the "current revision" and check the values. $entity = $storage_controller->load($entity->id()); foreach ($values[$revision_id] as $delta => $value) { - if ($delta < $this->field['cardinality']) { + if ($delta < $this->field_cardinality) { $this->assertEqual($entity->{$this->field_name}[$delta]->value, $value); } else { @@ -171,7 +172,7 @@ function testFieldWrite() { // Check insert. Add one value too many. $values = array(); - 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} = $values; @@ -179,7 +180,7 @@ function testFieldWrite() { // Read the tables and check the correct values have been stored. $rows = db_select($this->table, 't')->fields('t')->execute()->fetchAllAssoc('delta', \PDO::FETCH_ASSOC); - $this->assertEqual(count($rows), $this->field['cardinality']); + $this->assertEqual(count($rows), $this->field_cardinality); foreach ($rows as $delta => $row) { $expected = array( 'bundle' => $bundle, @@ -196,7 +197,7 @@ function testFieldWrite() { // Test update. Add less values and check that the previous values did not // persist. $values = array(); - for ($delta = 0; $delta <= $this->field['cardinality'] - 2; $delta++) { + for ($delta = 0; $delta <= $this->field_cardinality - 2; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name} = $values; @@ -219,7 +220,7 @@ function testFieldWrite() { // Create a new revision. $revision_values[$entity->getRevisionId()] = $values; $values = array(); - 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} = $values; @@ -230,7 +231,7 @@ function testFieldWrite() { // Check that data for both revisions are in the revision table. foreach ($revision_values as $revision_id => $values) { $rows = db_select($this->revision_table, 't')->fields('t')->condition('revision_id', $revision_id)->execute()->fetchAllAssoc('delta', \PDO::FETCH_ASSOC); - $this->assertEqual(count($rows), min(count($values), $this->field['cardinality'])); + $this->assertEqual(count($rows), min(count($values), $this->field_cardinality)); foreach ($rows as $delta => $row) { $expected = array( 'bundle' => $bundle, 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 d6155126048c355ba4b19943023df59374193c02..5e9c2557143a1f639f30c009b0b279d7df486ef1 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/FieldUpgradePathTest.php @@ -67,7 +67,7 @@ public function testEntityDisplayUpgrade() { // Check that the display key in the instance data was removed. $body_instance = field_info_instance('node', 'body', 'article'); - $this->assertTrue(!isset($body_instance['display'])); + $this->assertTrue(!isset($body_instance->display)); // Check that deleted fields were not added to the display. $this->assertFalse(isset($displays['default']['content']['test_deleted_field'])); @@ -110,7 +110,7 @@ public function testEntityFormDisplayUpgrade() { // Check that the display key in the instance data was removed. $body_instance = field_info_instance('node', 'body', 'article'); - $this->assertTrue(!isset($body_instance['widget'])); + $this->assertTrue(!isset($body_instance->widget)); // Check that deleted fields were not added to the display. $this->assertFalse(isset($form_display['content']['test_deleted_field'])); 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 c8825af647a9c0eebd0465d54f406a24c188dbe8..15253ad8111f5be1d1671a36121bf4bddd0cd4dc 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php @@ -42,8 +42,10 @@ public function testUserPictureUpgrade() { // Retrieve the field instance and check for migrated settings. $instance = field_info_instance('user', 'user_picture', 'user'); - $file = entity_load('file', $instance['settings']['default_image'][0]); - $this->assertIdentical($instance['settings']['default_image'][0], $file->id(), 'Default user picture has been migrated.'); + // We explicitly avoid using the getFieldSetting() method here, since it + // merges field and instance settings. + $file = entity_load('file', $instance->settings['default_image'][0]); + $this->assertTrue($file, 'Default user picture has been migrated.'); $this->assertEqual($file->getFileUri(), 'public://user_pictures_dir/druplicon.png', 'File id matches the uri expected.'); $this->assertEqual($file->getFilename(), 'druplicon.png'); $this->assertEqual($file->langcode->value, Language::LANGCODE_NOT_SPECIFIED); @@ -53,12 +55,12 @@ public function testUserPictureUpgrade() { // Check file usage for the default image. $usage = file_usage()->listUsage($file); $field = field_info_field('user', 'user_picture'); - $this->assertTrue(isset($usage['image']['default_image'][$field['uuid']])); + $this->assertTrue(isset($usage['image']['default_image'][$field->uuid()])); - $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.'); - $this->assertEqual($instance['description'], 'These are user picture guidelines.', 'User picture guidelines are now the user picture field description.'); - $this->assertEqual($instance['settings']['file_directory'], 'user_pictures_dir', 'User picture directory path has been migrated.'); + $this->assertEqual($instance->getFieldSetting('max_resolution'), '800x800', 'User picture maximum resolution has been migrated.'); + $this->assertEqual($instance->getFieldSetting('max_filesize'), '700 KB', 'User picture maximum filesize has been migrated.'); + $this->assertEqual($instance->getFieldDescription(), 'These are user picture guidelines.', 'User picture guidelines are now the user picture field description.'); + $this->assertEqual($instance->getFieldSetting('file_directory'), 'user_pictures_dir', 'User picture directory path has been migrated.'); $display_options = entity_get_display('user', 'user', 'default')->getComponent('user_picture'); $this->assertEqual($display_options['settings']['image_style'], 'thumbnail', 'User picture image style setting has been migrated.'); diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index f490c6816785ba57134dc03fd9acf8c307f04d7c..cc8800e0cb17a83edc29ae83840ad7352dc04928 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -517,7 +517,7 @@ function entity_test_entity_test_mul_translation_delete(EntityInterface $transla * The field language code to fill-in with the default value. */ function entity_test_field_default_value(EntityInterface $entity, Field $field, FieldInstance $instance, $langcode) { - return array(array('value' => $field['field_name'] . '_' . $langcode)); + return array(array('value' => $field->getFieldName() . '_' . $langcode)); } /** diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php index 844ccb07cf2875b9b7a6a60deffa760c4b001530..616091e68d4d19d76b9f5c293f122ccea862fc08 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TermAutocompleteController.php @@ -110,7 +110,7 @@ public function autocomplete(Request $request, $entity_type, $field_name) { $tags_typed = $request->query->get('q'); // Make sure the field exists and is a taxonomy field. - if (!($field = $this->fieldInfo->getField($entity_type, $field_name)) || $field['type'] !== 'taxonomy_term_reference') { + if (!($field = $this->fieldInfo->getField($entity_type, $field_name)) || $field->getFieldType() !== 'taxonomy_term_reference') { // Error string. The JavaScript handler will realize this is not JSON and // will display it as debugging information. return new Response(t('Taxonomy field @field_name not found.', array('@field_name' => $field_name)), 403); @@ -126,7 +126,7 @@ public function autocomplete(Request $request, $entity_type, $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->getFieldSetting('allowed_values') as $tree) { $vids[] = $tree['vocabulary']; } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php index 4844f7bf3e881d6887580bc41fa1ccaf7ae8a5da..ed179dd18f9bfe0b6b7ee63a9ba10b9e3e3bd831 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Entity/Vocabulary.php @@ -114,8 +114,8 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $ $fields = field_read_fields(); foreach ($fields as $field) { $update_field = FALSE; - if ($field['type'] == 'taxonomy_term_reference') { - foreach ($field['settings']['allowed_values'] as &$value) { + if ($field->getFieldType() == 'taxonomy_term_reference') { + foreach ($field->settings['allowed_values'] as &$value) { if ($value['vocabulary'] == $this->getOriginalID()) { $value['vocabulary'] = $this->id(); $update_field = TRUE; @@ -159,14 +159,14 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont $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'])) { $taxonomy_field->delete(); } else { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index a0a8a3b593d38f3b0b52079d1fb491b54c791248..9ddb3c47dcb4f5fba1ff43c6d345563ea4eff592 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -123,8 +123,8 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->assertNoText($term2->label(), 'Term 2 name is not displayed.'); // Verify that field and instance settings are correct. - $field_info = field_info_field('entity_test', $this->field_name); - $this->assertEqual(count($field_info['settings']['allowed_values']), 1, 'Only one vocabulary is allowed for the field.'); + $field = field_info_field('entity_test', $this->field_name); + $this->assertEqual(count($field->getFieldSetting('allowed_values')), 1, 'Only one vocabulary is allowed for the field.'); // The widget should still be displayed. $this->drupalGet('entity_test/add'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index a908f552f62b68bb6f3050e88a25634326ab8d0c..d289a2c54a0bd9c5f3108a06eefeeebf0da9e4d5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -158,7 +158,7 @@ function testTaxonomyTermFieldChangeMachineName() { // Check that the field instance is still attached to the vocabulary. $field = field_info_field('entity_test', $this->field_name); - $allowed_values = $field['settings']['allowed_values']; + $allowed_values = $field->getFieldSetting('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/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index c57397b13e53556febe61ae509146f518e6dfd67..d11eefe3c9f1b1a70614411f88587068d6fdfeef 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -26,8 +26,9 @@ function setUp() { $this->drupalLogin($this->admin_user); $this->vocabulary = $this->createVocabulary(); + $field_name = 'taxonomy_' . $this->vocabulary->id(); $field = array( - 'name' => 'taxonomy_' . $this->vocabulary->id(), + 'name' => $field_name, 'entity_type' => 'node', 'type' => 'taxonomy_term_reference', 'cardinality' => FIELD_CARDINALITY_UNLIMITED, @@ -43,18 +44,18 @@ function setUp() { entity_create('field_entity', $field)->save(); $this->instance = entity_create('field_instance', array( - 'field_name' => 'taxonomy_' . $this->vocabulary->id(), + 'field_name' => $field_name, 'bundle' => 'article', 'entity_type' => 'node', )); $this->instance->save(); entity_get_form_display('node', 'article', 'default') - ->setComponent('taxonomy_' . $this->vocabulary->id(), array( + ->setComponent($field_name, array( 'type' => 'options_select', )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->instance['field_name'], array( + ->setComponent($field_name, array( 'type' => 'taxonomy_term_reference_link', )) ->save(); @@ -111,7 +112,7 @@ function testTaxonomyNode() { $edit = array(); $edit['title'] = $this->randomName(); $edit['body[0][value]'] = $this->randomName(); - $edit[$this->instance['field_name'] . '[]'] = $term1->id(); + $edit[$this->instance->getFieldName() . '[]'] = $term1->id(); $this->drupalPostForm('node/add/article', $edit, t('Save')); // Check that the term is displayed when the node is viewed. @@ -125,7 +126,7 @@ function testTaxonomyNode() { $this->assertText($term1->label(), 'Term is displayed after saving the node with no changes.'); // Edit the node with a different term. - $edit[$this->instance['field_name'] . '[]'] = $term2->id(); + $edit[$this->instance->getFieldName() . '[]'] = $term2->id(); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save')); $this->drupalGet('node/' . $node->id()); @@ -144,8 +145,8 @@ function testTaxonomyNode() { function testNodeTermCreationAndDeletion() { // Enable tags in the vocabulary. $instance = $this->instance; - entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') - ->setComponent($instance['field_name'], array( + entity_get_form_display($instance->entity_type, $instance->bundle, 'default') + ->setComponent($instance->getFieldName(), array( 'type' => 'taxonomy_autocomplete', 'settings' => array( 'placeholder' => 'Start typing here.', @@ -164,7 +165,7 @@ function testNodeTermCreationAndDeletion() { $edit['body[0][value]'] = $this->randomName(); // Insert the terms in a comma separated list. Vocabulary 1 is a // free-tagging field created by the default profile. - $edit[$instance['field_name']] = drupal_implode_tags($terms); + $edit[$instance->getFieldName()] = drupal_implode_tags($terms); // Verify the placeholder is there. $this->drupalGet('node/add/article'); @@ -508,8 +509,8 @@ function testTaxonomyGetTermByName() { function testReSavingTags() { // Enable tags in the vocabulary. $instance = $this->instance; - entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default') - ->setComponent($instance['field_name'], array( + entity_get_form_display($instance->entity_type, $instance->bundle, 'default') + ->setComponent($instance->getFieldName(), array( 'type' => 'taxonomy_autocomplete', )) ->save(); @@ -519,7 +520,7 @@ function testReSavingTags() { $edit = array(); $edit['title'] = $this->randomName(8); $edit['body[0][value]'] = $this->randomName(16); - $edit[$this->instance['field_name']] = $term->label(); + $edit[$this->instance->getFieldName()] = $term->label(); $this->drupalPostForm('node/add/article', $edit, t('Save')); // Check that the term is displayed when editing and saving the node with no diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index c687da4c2047336f4aa20543b41d7dd08a76e9f6..4a17f3dbcda7c7cdf896566c1ecdff6b47294ff3 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -8,6 +8,8 @@ use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldDefinitionInterface; +use Drupal\field\FieldInterface; +use Drupal\field\FieldInstanceInterface; use Drupal\file\FileInterface; use Drupal\node\Entity\Node; use Drupal\taxonomy\Entity\Term; @@ -931,7 +933,7 @@ function taxonomy_options_list(FieldDefinitionInterface $field_definition, Entit * Possible error codes: * - 'taxonomy_term_illegal_value': The value is not part of the list of allowed values. */ -function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instance, $langcode, $items, &$errors) { +function taxonomy_field_validate(EntityInterface $entity = NULL, FieldInterface $field, FieldInstanceInterface $instance, $langcode, $items, &$errors) { // Build an array of existing term IDs so they can be loaded with // entity_load_multiple('taxonomy_term'); foreach ($items as $delta => $item) { @@ -948,7 +950,7 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan $validate = TRUE; if (!empty($item['target_id']) && $item['target_id'] != 'autocreate') { $validate = FALSE; - foreach ($field['settings']['allowed_values'] as $settings) { + foreach ($instance->getFieldSetting('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['target_id']]->bundle()) { @@ -970,9 +972,9 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan } } if (!$validate) { - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$instance->getFieldName()][$langcode][$delta][] = array( 'error' => 'taxonomy_term_reference_illegal_value', - 'message' => t('%name: illegal value.', array('%name' => $instance['label'])), + 'message' => t('%name: illegal value.', array('%name' => $instance->getFieldLabel())), ); } } @@ -1051,7 +1053,7 @@ function taxonomy_field_settings_form($field, $instance) { '#tree' => TRUE, ); - foreach ($field['settings']['allowed_values'] as $delta => $tree) { + foreach ($field->getFieldSetting('allowed_values') as $delta => $tree) { $form['allowed_values'][$delta]['vocabulary'] = array( '#type' => 'select', '#title' => t('Vocabulary'), @@ -1135,7 +1137,7 @@ function taxonomy_build_node_index($node) { foreach (field_info_instances('node', $node->getType()) as $instance) { $field = $instance->getField(); $field_name = $field->getFieldName(); - if ($field['module'] == 'taxonomy') { + if ($field->module == 'taxonomy') { foreach ($node->getTranslationLanguages() as $language) { foreach ($node->getTranslation($language->id)->$field_name as $item) { if (!$item->isEmpty()) { diff --git a/core/modules/taxonomy/taxonomy.views.inc b/core/modules/taxonomy/taxonomy.views.inc index e7583099a6e273f65fdcf5cfd2d267b56732f13a..15a978a2af98b7a861f4e8e477261d0d108f9303 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -412,16 +412,18 @@ function taxonomy_field_views_data(FieldInterface $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']; + $allowed_values = $field->getFieldSetting('allowed_values'); + $data[$table_name][$field_name]['filter']['vocabulary'] = $allowed_values[0]['vocabulary']; } } // Add the relationship only on the tid field. - $data[$table_name][$field['field_name'] . '_target_id']['relationship'] = array( + $field_name = $field->getFieldName(); + $data[$table_name][$field_name . '_target_id']['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_name)), ); } @@ -435,23 +437,24 @@ function taxonomy_field_views_data(FieldInterface $field) { * Views integration to provide reverse relationships on term references. */ function taxonomy_field_views_data_views_data_alter(array &$data, FieldInterface $field) { - $entity_type = $field['entity_type']; + $field_name = $field->getFieldName(); + $entity_type = $field->entity_type; $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type; - list($label,) = field_views_field_label($entity_type, $field['field_name']); + list($label,) = field_views_field_label($entity_type, $field_name); $data['taxonomy_term_data'][$pseudo_field_name]['relationship'] = array( 'title' => t('@entity using @field', array('@entity' => $entity_info['label'], '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the term.', array('@entity' => $entity_info['label'], '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], - 'entity_type' => $field['entity_type'], + 'field_name' => $field_name, + 'entity_type' => $entity_type, 'field table' => DatabaseStorageController::_fieldTableName($field), - 'field field' => $field['field_name'] . '_target_id', + 'field field' => $field_name . '_target_id', '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_name)), 'join_extra' => array( 0 => array( 'field' => 'deleted', diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index aeea6b269a9f64f210cfca05c4fbf7eb51c972a4..471b0bd32419b9c9e80912ae7b5e1945ba1a8e04 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -226,8 +226,9 @@ function views_ui_taxonomy_autocomplete_validate($element, &$form_state) { // vocabulary IDs. $field = field_info_field($element['#entity_type'], $element['#field_name']); $vocabularies = array(); - if (!empty($field['settings']['allowed_values'])) { - foreach ($field['settings']['allowed_values'] as $tree) { + $allowed_values = $field->getFieldSetting('allowed_values'); + if (!empty($allowed_values)) { + foreach ($allowed_values as $tree) { if ($vocabulary = entity_load('taxonomy_vocabulary', $tree['vocabulary'])) { $vocabularies[$vocabulary->id()] = $tree['vocabulary']; }