diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php index 9d13fcd..d19f35d 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageController.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageController.php @@ -577,7 +577,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') @@ -592,11 +592,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; @@ -645,13 +645,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) { $items = $entity->getTranslation($langcode)->{$field_name}->getValue(); if (!isset($items)) { @@ -668,7 +668,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); $value = isset($item[$column]) ? $item[$column] : NULL; // Serialize the value if specified in the column schema. @@ -677,7 +677,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; } } @@ -780,7 +780,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 @@ -830,7 +830,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) @@ -839,7 +839,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); @@ -855,11 +855,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(); } @@ -945,13 +945,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->id()} ({$field->entity_type}, {$field->getFieldName()})."; + $description_revision = "Revision archive storage for deleted field {$field->id()} ({$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( @@ -1076,12 +1076,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); @@ -1105,12 +1105,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); @@ -1131,7 +1131,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/FieldableEntityStorageControllerBase.php b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php index 87b86c0..452e255 100644 --- a/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php +++ b/core/lib/Drupal/Core/Entity/FieldableEntityStorageControllerBase.php @@ -90,7 +90,7 @@ protected function loadFieldItems(array $entities, $age) { foreach ($entity->getTranslationLanguages() as $langcode => $language) { $translation = $entity->getTranslation($langcode); foreach ($instances as $instance) { - $data[$langcode][$instance['field_name']] = $translation->{$instance['field_name']}->getValue(); + $data[$langcode][$instance->getFieldName()] = $translation->{$instance->getFieldName()}->getValue(); } } $cid = "field:{$this->entityType}:$id"; diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 9607dd1..91cac04 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 092e584..c51be01 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 9ea559c..3c11987 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', '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/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index c35bc78..283f809 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -71,7 +71,7 @@ function setUp() { // Make comment body translatable. $field = field_info_field('comment', '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/CommentTranslationUITest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php index 96e2d20..d5a32bb 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTranslationUITest.php @@ -64,7 +64,7 @@ protected function getTranslatorPermissions() { function setupTestFields() { parent::setupTestFields(); $field = field_info_field('comment', '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 9904ba0..86539ab 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -24,22 +24,24 @@ function content_translation_field_sync_widget(Field $field, FieldInstance $instance) { $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 = $instance->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'), @@ -98,10 +100,10 @@ function _content_translation_form_language_content_settings_form_alter(array &$ foreach ($fields as $field_name => $instance) { $field = $instance->getField(); $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' => $field->isFieldTranslatable(), ); $column_element = content_translation_field_sync_widget($field, $instance); if ($column_element) { @@ -340,7 +342,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 +387,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 +422,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 +454,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 a6cf31c..8276023 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,7 +810,7 @@ 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['#field']->isFieldTranslatable()) { module_load_include('inc', 'content_translation', 'content_translation.admin'); $element = content_translation_field_sync_widget($form['#field'], $form['#instance']); if ($element) { @@ -992,8 +992,8 @@ function content_translation_save_settings($settings) { 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 ($field->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 be151b9..c5d2596 100644 --- a/core/modules/content_translation/content_translation.pages.inc +++ b/core/modules/content_translation/content_translation.pages.inc @@ -43,7 +43,7 @@ function content_translation_overview(EntityInterface $entity) { $translatable = FALSE; foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { $field = $instance->getField(); - if ($field['translatable']) { + if ($field->isFieldTranslatable()) { $translatable = TRUE; break; } diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php index 77ac782..b970e77 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationController.php @@ -49,9 +49,9 @@ public function removeTranslation(EntityInterface $entity, $langcode) { // @todo Handle properties. // Remove field translations. foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field_name = $instance['field_name']; + $field_name = $instance->getFieldName(); $field = $instance->getField(); - if ($field['translatable']) { + if ($field->isFieldTranslatable()) { $entity->{$field_name}[$langcode] = array(); } } 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 46a5b89..07e43d2 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(EntityInterface $entity, $sync_langcode, $orig // 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 6ab01af..2907e47 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'] ? "
" . t("All the existing translations of this field will be deleted.
This action cannot be undone.") : ''; + $description .= $this->field->isFieldTranslatable() ? "
" . t("All the existing translations of this field will be deleted.
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 ecab4c4..45a1e7d 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 @@ -90,7 +90,7 @@ function testSettingsUI() { $this->assertSettings('comment', 'comment_node_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', 'comment_node_article'); diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index 0da06cb..2458131 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -190,11 +190,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 f755730..0b4ee54 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 4fd86d9..abb1e41 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 6a75527..c767f5a 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 eabce25..4bcc8fb 100644 --- a/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php +++ b/core/modules/entity/lib/Drupal/entity/EntityDisplayBase.php @@ -224,7 +224,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($field->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 b9e7c58..3e4bd80 100644 --- a/core/modules/entity_reference/entity_reference.module +++ b/core/modules/entity_reference/entity_reference.module @@ -37,15 +37,15 @@ 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') { + $field = field_info_field($entity_type, $field_name); + if ($field->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'] = $field->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'] = $field->getFieldSetting('target_type'); } } } @@ -74,7 +74,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 492fa25..8fa080c 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 426af2c..ce0cec7 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/EntityReferenceController.php @@ -77,7 +77,7 @@ public function handleAutocomplete(Request $request, $type, $field_name, $entity throw new AccessDeniedHttpException(); } - if ($field['type'] != 'entity_reference' || !field_access('edit', $field, $entity_type)) { + if ($field->getFieldType() != 'entity_reference' || !field_access('edit', $field, $entity_type)) { throw new AccessDeniedHttpException(); } 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 74a1a8a..a66a582 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 @@ -108,8 +108,9 @@ public static function settingsForm(FieldDefinitionInterface $field_definition) 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)); + $columns = $field_info->getColumns(); + foreach ($columns as $column_name => $column_info) { + $fields[$instance_name . '.' . $column_name] = t('@label (@column)', array('@label' => $instance_info->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 ee5e79a..12d3125 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,8 +68,8 @@ 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']); + if (is_subclass_of($entity_manager->getControllerClass($field->getFieldSetting('target_type'), 'storage'), 'Drupal\Core\Entity\DatabaseStorageController')) { + $entity_info = $entity_manager->getDefinition($field->getFieldSetting('target_type')); $base_table = $entity_info['base_table']; $id_column = $entity_info['entity_keys']['id']; @@ -203,7 +203,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 6ed2ace..a93300e 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 f082960..3ed8b0d 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,8 +201,8 @@ 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_id = $instance->id(); + $field_name = $instance->getFieldName(); // Let the closure determine the target object on which the method should // be called. @@ -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()); }; } @@ -349,7 +349,7 @@ function _field_invoke_widget_target($form_display) { */ function field_attach_preprocess(EntityInterface $entity, $element, &$variables) { foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field_name = $instance['field_name']; + $field_name = $instance->getFieldName(); 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 e33b150..4764e41 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 79345a8..3578bfb 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 @@ -50,8 +51,8 @@ function field_info_cache_clear() { * @param string $op * The name of the operation. Currently supported: 'default_value', * 'multiple_values'. - * @param array $instance - * The field instance array. + * @param \Drupal\field\FieldInstanceInterface $instance + * The field instance definition. * * @return int * One of these values: @@ -59,9 +60,9 @@ function field_info_cache_clear() { * - FIELD_BEHAVIOR_CUSTOM: Use the widget's callback function. * - FIELD_BEHAVIOR_DEFAULT: Use field.module default behavior. */ -function field_behaviors_widget($op, $instance) { +function field_behaviors_widget($op, FieldInstanceInterface $instance) { $info = array(); - if ($component = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($instance['field_name'])) { + if ($component = entity_get_form_display($instance->entity_type, $instance->bundle, 'default')->getComponent($instance->getFieldName())) { $info = \Drupal::service('plugin.manager.field.widget')->getDefinition($component['type']); } return isset($info[$op]) ? $info[$op] : FIELD_BEHAVIOR_DEFAULT; diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 681fc63..988fdef 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -189,7 +189,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; } @@ -285,7 +285,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(); @@ -683,7 +683,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 17b065a..dfbb57b 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); } /** @@ -309,17 +310,17 @@ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = // 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; + if (_field_translated_value_exists($entity, $langcode, $instance->getFieldName())) { + $display_langcode[$instance->getFieldName()] = $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[$instance->getFieldName()] = 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->{$instance->getFieldName()}[$language_locked->id])) { + $display_langcode[$instance->getFieldName()] = $language_locked->id; break; } } diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index df30467..3732f15 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,13 @@ 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:' . $field->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 +132,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 +151,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 +171,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 8269575..10f6045 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,8 @@ 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_counter[$instance->getFieldLabel()] = isset($label_counter[$instance->getFieldLabel()]) ? ++$label_counter[$instance->getFieldLabel()] : 1; + $all_labels[$instance->getFieldLabel()] = TRUE; } } if (empty($label_counter)) { @@ -118,15 +118,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'])) { + $field_bundles = $field->getBundles(); + if (empty($field_bundles)) { return $data; } - $field_name = $field['field_name']; + $field_name = $field->getFieldName(); // Grab information about the entity type tables. $entity_manager = \Drupal::entityManager(); @@ -147,13 +148,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->getFieldName()}", ), ); 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->getFieldName()}", ); } @@ -183,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->getColumns()) as $column) { $add_fields[] = DatabaseStorageController::_fieldColumnName($field, $column); } // Determine the label to use for the field. We don't have a label available @@ -243,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->getColumns()); $real_field = reset($keys); $data[$table_alias][$field_alias]['field'] = array( 'table' => $table, @@ -261,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->getColumns() as $column => $attributes) { $allow_sort = TRUE; // Identify likely filters and arguments for each column based on field type. @@ -288,7 +289,7 @@ function field_views_field_default_views_data(FieldInterface $field) { break; } - if (count($field['columns']) == 1 || $column == 'value') { + if (count($field->getColumns()) == 1 || $column == 'value') { $title = t('@label (!name)', array('@label' => $label, '!name' => $field_name)); $title_short = $label; } @@ -327,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->getColumns()) == 1 || $column == 'value') { $alias_title = t('@label (!name)', array('@label' => $label_name, '!name' => $field_name)); } else { @@ -376,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)); @@ -418,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)); @@ -475,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 3421461..8414a71 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -454,7 +454,7 @@ public function delete() { /** * {@inheritdoc} */ - public function getSchema() { + public function getSchema($key = '') { if (!isset($this->schema)) { // Get the schema from the field item class. $definition = \Drupal::service('plugin.manager.entity.field.field_type')->getDefinition($this->type); @@ -475,6 +475,10 @@ public function getSchema() { $this->schema = $schema; } + if (!empty($key)) { + return $this->schema[$key]; + } + return $this->schema; } @@ -548,9 +552,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; + } } /** @@ -602,58 +609,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. * * @return array diff --git a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php index 8f391ad..18759b6 100644 --- a/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php +++ b/core/modules/field/lib/Drupal/field/Entity/FieldInstance.php @@ -608,46 +608,6 @@ public function allowBundleRename() { } /** - * {@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 8d6bc3a..114744c 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,9 @@ 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; + $field = $this->getField($instance->entity_type, $instance->getFieldName()); + $instance = $this->prepareInstance($instance, $field->getFieldType()); + $this->bundleInstances[$instance->entity_type][$instance->bundle][$instance->getFieldName()] = $instance; } // Store in persistent cache. @@ -330,8 +332,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 +371,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 +414,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,14 +461,14 @@ 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. @@ -474,8 +476,8 @@ public function getBundleInstances($entity_type, $bundle) { foreach ($loaded_instances as $instance) { $field = $instance->getField(); - $instance = $this->prepareInstance($instance, $field['type']); - $instances[$field['field_name']] = $instance; + $instance = $this->prepareInstance($instance, $field->getFieldType()); + $instances[$field->getFieldName()] = $instance; } } } @@ -569,9 +571,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; } @@ -579,21 +581,21 @@ 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 \Drupal\field\FieldInstanceInterface $instance + * The instance definition. * @param $field_type * The field type. * * @return * The field instance array completed for the current runtime context. */ - public function prepareInstance($instance, $field_type) { + public function prepareInstance(FieldInstanceInterface $instance, $field_type) { // Make sure all expected instance settings are present. - $instance['settings'] += $this->fieldTypeManager->getDefaultInstanceSettings($field_type); + $instance->settings += $this->fieldTypeManager->getDefaultInstanceSettings($field_type); // Set a default value for the instance. - if (field_behaviors_widget('default value', $instance) == FIELD_BEHAVIOR_DEFAULT && !isset($instance['default_value'])) { - $instance['default_value'] = NULL; + if (field_behaviors_widget('default value', $instance) == FIELD_BEHAVIOR_DEFAULT && !isset($instance->default_value)) { + $instance->default_value = NULL; } return $instance; diff --git a/core/modules/field/lib/Drupal/field/FieldInstanceInterface.php b/core/modules/field/lib/Drupal/field/FieldInstanceInterface.php index 318bf4f..d9da54c 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. @@ -24,6 +24,14 @@ public function getField(); /** + * Returns the field type from the field for this instance. + * + * @return $type + * The field type. + */ + public function getFieldType(); + + /** * Allows a bundle to be renamed. * * Renaming a bundle on the instance is allowed when an entity's bundle diff --git a/core/modules/field/lib/Drupal/field/FieldInterface.php b/core/modules/field/lib/Drupal/field/FieldInterface.php index 2a03aab..7b992ba 100644 --- a/core/modules/field/lib/Drupal/field/FieldInterface.php +++ b/core/modules/field/lib/Drupal/field/FieldInterface.php @@ -13,11 +13,14 @@ /** * Provides an interface defining a field entity. */ -interface FieldInterface extends ConfigEntityInterface, FieldDefinitionInterface, \ArrayAccess { +interface FieldInterface extends ConfigEntityInterface, FieldDefinitionInterface { /** * Returns the field schema. * + * @param string $key + * (optional) A key corresponding to one of the keys in the schema array. + * * @return array * The field schema, as an array of key/value pairs in the format returned * by hook_field_schema(): @@ -31,7 +34,7 @@ * however, that depending on the storage backend specified for the field, * the field data is not necessarily stored in SQL. */ - public function getSchema(); + public function getSchema($key = ''); /** * Returns the field columns, as defined in 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 a84c94f..f5e2957 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 @@ */ 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 ea74a94..fe1b87c 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 @@ -117,7 +117,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o $this->multiple = FALSE; $this->limit_values = FALSE; - if ($field['cardinality'] > 1 || $field['cardinality'] == FIELD_CARDINALITY_UNLIMITED) { + if ($field->getFieldCardinality() > 1 || $field->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED) { $this->multiple = TRUE; // If "Display all values in the same row" is FALSE, then we always limit @@ -133,7 +133,7 @@ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$o // Otherwise, we only limit values if the user hasn't selected "all", 0, or // the value matching field cardinality. - if ((intval($this->options['delta_limit']) && ($this->options['delta_limit'] != $field['cardinality'])) || intval($this->options['delta_offset'])) { + if ((intval($this->options['delta_limit']) && ($this->options['delta_limit'] != $field->getFieldCardinality())) || intval($this->options['delta_offset'])) { $this->limit_values = TRUE; } } @@ -302,8 +302,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) { @@ -338,7 +338,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, @@ -374,8 +374,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) { @@ -383,7 +383,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] : '', @@ -473,14 +473,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( @@ -801,14 +801,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 0baa951..d015ffa 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 7578ed2..d050f59 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 c79c6d4..23e7fd1 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 2de2456..71c8f4d 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -51,7 +51,7 @@ function testFieldAttachSaveLoad() { // 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 +60,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($this->field->getFieldCardinality() + 1); $entity->{$this->field_name}->setValue($current_values); $entity->setNewRevision(); $entity->save(); @@ -74,8 +74,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}), $this->field->getFieldCardinality(), 'Current revision: expected number of values'); + for ($delta = 0; $delta < $this->field->getFieldCardinality(); $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 +86,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}), $this->field->getFieldCardinality(), format_string('Revision %revision_id: expected number of values.', array('%revision_id' => $revision_id))); + for ($delta = 0; $delta < $this->field->getFieldCardinality(); $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))); // The value added in hook_field_load() is found. @@ -126,7 +126,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], @@ -220,7 +220,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. @@ -247,11 +247,11 @@ function testFieldAttachSaveEmptyDataDefaultValue() { function testFieldAttachDelete() { $entity_type = 'entity_test_rev'; $this->createFieldWithInstance('', $entity_type); - $entity = entity_create($entity_type, array('type' => $this->instance['bundle'])); + $entity = entity_create($entity_type, array('type' => $this->instance->bundle)); $vids = array(); // Create revision 0 - $values = $this->_generateTestFieldValues($this->field['cardinality']); + $values = $this->_generateTestFieldValues($this->field->getFieldCardinality()); $entity->{$this->field_name} = $values; $entity->save(); $vids[] = $entity->getRevisionId(); @@ -271,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}), $this->field->getFieldCardinality(), "The test entity revision $vid has {$this->field->getFieldCardinality()} values."); } // Delete revision 1, confirm the other two still load. @@ -280,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}), $this->field->getFieldCardinality(), "The test entity revision $vid has {$this->field->getFieldCardinality()} 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}), $this->field->getFieldCardinality(), "The test entity current revision has {$this->field->getFieldCardinality()} values."); // Delete all field data, confirm nothing loads $entity->delete(); @@ -314,13 +314,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($this->field->getFieldCardinality()); $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}), $this->field->getFieldCardinality(), "Data is retrieved for the new bundle"); // Rename the bundle. $new_bundle = 'test_bundle_' . drupal_strtolower($this->randomName()); @@ -328,13 +328,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}), $this->field->getFieldCardinality(), "Bundle name has been updated in the field storage"); } /** @@ -364,7 +364,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), @@ -372,8 +372,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); @@ -383,7 +383,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()); @@ -394,7 +394,7 @@ 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', $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"); } diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldImportChangeTest.php index 6e4b8b8..ca941e9 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 fe97da2..637aacf 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 8c4afcc..ace8393 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->getField()->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 cd809a6..097d015 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 3dd2e32..5a740d1 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 4919115..2936d8b 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -591,8 +591,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(); @@ -612,10 +612,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($this->instance->entity_type, $this->instance->bundle, 'default') + ->setComponent($this->instance->getFieldName(), array( 'type' => 'test_field_widget', )) ->save(); @@ -634,8 +634,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($this->instance->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 0edb901..8125a1e 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; @@ -253,9 +254,9 @@ function testFieldDisplayLanguage() { 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, $this->instance->bundle); $langcodes = array(); // This array is used to store, for each field name, which one of the locked @@ -265,7 +266,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 +275,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 +293,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 +302,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 6250a95..7f0eb0b 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 2f8e5a6..90e3934 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 985dc7f..457643d 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,9 @@ protected function setUp() { protected function prepareView(ViewExecutable $view) { $view->initDisplay(); foreach ($this->fields as $key => $field) { - $view->display_handler->options['fields'][$field['field_name']]['id'] = $field['field_name']; - $view->display_handler->options['fields'][$field['field_name']]['table'] = 'node__' . $field['field_name']; - $view->display_handler->options['fields'][$field['field_name']]['field'] = $field['field_name']; + $view->display_handler->options['fields'][$field->getFieldName()]['id'] = $field->getFieldName(); + $view->display_handler->options['fields'][$field->getFieldName()]['table'] = 'node__' . $field->getFieldName(); + $view->display_handler->options['fields'][$field->getFieldName()]['field'] = $field->getFieldName(); } } @@ -116,8 +116,8 @@ public function _testSimpleFieldRender() { for ($i = 0; $i < 3; $i++) { for ($key = 0; $key < 2; $key++) { $field = $this->fields[$key]; - $rendered_field = $view->style_plugin->getField($i, $field['field_name']); - $expected_field = $this->nodes[$i]->{$field['field_name']}->value; + $rendered_field = $view->style_plugin->getField($i, $field->getFieldName()); + $expected_field = $this->nodes[$i]->{$field->getFieldName()}->value; $this->assertEqual($rendered_field, $expected_field); } } @@ -129,8 +129,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 +138,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 +165,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 3ac75fa..ab23d03 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 @@ -65,7 +65,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'"); } } @@ -80,7 +80,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) { @@ -127,9 +128,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())), ); } } @@ -149,7 +150,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', @@ -166,7 +167,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', @@ -202,13 +203,13 @@ function field_test_default_value(EntityInterface $entity, $field, $instance) { * Implements hook_field_access(). */ function field_test_field_access($op, FieldInterface $field, $entity_type, $entity, $account) { - if ($field['field_name'] == "field_no_{$op}_access") { + if ($field->getFieldName() == "field_no_{$op}_access") { return FALSE; } // Only grant view access to test_view_field fields when the user has // 'view test_view_field content' permission. - if ($field['field_name'] == 'test_view_field' && $op == 'view' && !$account->hasPermission('view test_view_field content')) { + if ($field->getFieldName() == 'test_view_field' && $op == 'view' && !$account->hasPermission('view test_view_field content')) { return FALSE; } diff --git a/core/modules/field/tests/modules/field_test/field_test.install b/core/modules/field/tests/modules/field_test/field_test.install index a079829..ee2e28d 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 dfc6a13..e9cb4b0 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:') . ' ' . $plugin_type_info['label'] . ''; 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 3f9adea..ca5d3dd 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/DisplayOverviewBase.php @@ -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($field->getFieldType()), ), 'human_name' => array( - '#markup' => check_plain($instance['label']), + '#markup' => check_plain($instance->getFieldLabel()), ), 'weight' => array( '#type' => 'textfield', - '#title' => $this->t('Weight for @title', array('@title' => $instance['label'])), + '#title' => $this->t('Weight for @title', array('@title' => $instance->getFieldLabel())), '#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' => $instance->getFieldLabel())), '#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' => $instance->getFieldLabel())), '#title_display' => 'invisible', - '#options' => $this->getPluginOptions($field['type']), + '#options' => $this->getPluginOptions($field->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 a2dbb68..490a73a 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,7 +423,7 @@ 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'); } } @@ -431,12 +431,12 @@ public function submitForm(array &$form, array &$form_state) { 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'])) { + 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->getFieldName(), 'entity_type' => $this->entity_type, 'bundle' => $this->bundle, 'label' => $values['label'], @@ -450,14 +450,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->getFieldName()) ->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->getFieldName()) ->save(); $destinations[] = $this->adminPath . '/fields/' . $new_instance->id(); @@ -465,7 +465,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'); } } } @@ -515,12 +515,12 @@ protected function getExistingFieldOptions() { // 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'])) { + if (empty($field->locked) && empty($field_types[$field->getFieldType()]['no_ui'])) { $options[$field->name] = array( - 'type' => $field->type, - 'type_label' => $field_types[$field->type]['label'], - 'field' => $field->name, - 'label' => $instance->label, + 'type' => $field->getFieldType(), + 'type_label' => $field_types[$field->getFieldType()]['label'], + 'field' => $field->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 2924c35..f59cab8 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 4f0a5d9..49d1dfb 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 @@ -110,7 +110,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. @@ -146,10 +146,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 @@ -159,9 +159,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'] += $this->getFieldItem($entity, $field['field_name'])->settingsForm($form, $form_state, $field->hasData()); + $form['field']['settings'] += $this->getFieldItem($entity, $field->getFieldName())->settingsForm($form, $form_state, $field->hasData()); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save field settings')); @@ -199,7 +199,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 d358f0e..e861048 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 @@ -66,25 +66,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 = $this->getFieldItems($form['#entity'], $this->instance['field_name']); + $items = $this->getFieldItems($form['#entity'], $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; } @@ -97,7 +97,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', @@ -112,24 +112,26 @@ 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, ); + $description = $this->instance->getFieldDescription(); $form['instance']['description'] = array( '#type' => 'textarea', '#title' => $this->t('Help text'), - '#default_value' => !empty($this->instance['description']) ? $this->instance['description'] : '', + '#default_value' => !empty($description) ? $description : '', '#rows' => 5, '#description' => $this->t('Instructions to present to the user below this field on the editing form.
Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '
' . $this->t('This field supports tokens.'), '#weight' => -10, ); + $required = $this->instance->isFieldRequired(); $form['instance']['required'] = array( '#type' => 'checkbox', '#title' => $this->t('Required field'), - '#default_value' => !empty($this->instance['required']), + '#default_value' => !empty($required), '#weight' => -5, ); @@ -165,7 +167,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 = $this->getFieldItems($form['#entity'], $this->instance['field_name']); + $items = $this->getFieldItems($form['#entity'], $this->instance->getFieldName()); $items->defaultValuesFormValidate($form['instance']['default_value'], $form, $form_state); } } @@ -177,18 +179,18 @@ public function submitForm(array &$form, array &$form_state) { // Handle the default value. $default_value = array(); if (isset($form['instance']['default_value'])) { - $items = $this->getFieldItems($form['#entity'], $this->instance['field_name']); + $items = $this->getFieldItems($form['#entity'], $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 1186fc2..56f7c9c 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->label())); 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:') . ' ' . $plugin_type_info['label'] . ''; 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 daf263e..0cb1c93 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 79b1fbe..1a8f65e 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 430f79f..56628d5 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(). @@ -60,8 +61,8 @@ function file_field_widget_multiple_count_validate($element, &$form_state, $form $field = field_info_field($element['#entity_type'], $element['#field_name']); $uploaded = count($values['fids']); $count = $uploaded + $current; - if ($count > $field['cardinality']) { - $keep = $uploaded - $count + $field['cardinality']; + if ($count > $field->getFieldCardinality()) { + $keep = $uploaded - $count + $field->getFieldCardinality(); $removed_files = array_slice($values['fids'], $keep); $removed_names = array(); foreach ($removed_files as $fid) { @@ -72,8 +73,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->getFieldName(), + '@max' => $field->getFieldCardinality(), '@count' => $keep, '%list' => implode(', ', $removed_names), ) @@ -485,15 +486,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 entity. * * @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 769d480..246b33d 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -1866,12 +1866,12 @@ function file_get_file_references(File $file, $field = NULL, $age = EntityStorag $current_field = $instance->getField(); // If this is the first time this field type is seen, check // whether it references files. - if (!isset($field_columns[$current_field['type']])) { - $field_columns[$current_field['type']] = file_field_find_file_reference_column($current_field); + if (!isset($field_columns[$current_field->getFieldType()])) { + $field_columns[$current_field->getFieldType()] = file_field_find_file_reference_column($current_field); } // If the field type does reference files then record it. - if ($field_columns[$current_field['type']]) { - $file_fields[$entity_type][$bundle][$field_name] = $field_columns[$current_field['type']]; + if ($field_columns[$current_field->getFieldType()]) { + $file_fields[$entity_type][$bundle][$field_name] = $field_columns[$current_field->getFieldType()]; } } } @@ -1903,7 +1903,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->getFieldName() != $current_field->getFieldName())) { unset($return[$field_name][$entity_type]); } } diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc index 501ce7c..70cb0ea 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,24 +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; + $pseudo_field_name = 'reverse_' . $field->getFieldName() . '_' . $entity_type; - list($label,) = field_views_field_label($entity_type, $field['field_name']); + list($label,) = field_views_field_label($entity_type, $field->getFieldName()); $entity_label = ($entity_info['label'] == t('Node')) ? t('Content') : $entity_info['label']; $data['file_managed'][$pseudo_field_name]['relationship'] = array( 'title' => t('@entity using @field', array('@entity' => $entity_label, '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the file.', array('@entity' => $entity_label, '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], - 'entity_type' => $field['entity_type'], + 'field_name' => $field->getFieldName(), + 'entity_type' => $field->entity_type, 'field table' => DatabaseStorageController::_fieldTableName($field), - 'field field' => $field['field_name'] . '_target_id', + 'field field' => $field->getFieldName() . '_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->getFieldName())), '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 0990758..8ca51df 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -124,12 +124,12 @@ 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($instance->entity_type, $instance->bundle, 'default') + ->setComponent($instance->getFieldName(), array( 'settings' => $widget_settings, )) ->save(); @@ -162,7 +162,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 19a3e31..f83b992 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -31,14 +31,13 @@ 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); $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' => $field_name)), '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 +56,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' => $field_name)), '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 fc116ad..f76488c 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 6c43b69..9138e52 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -157,7 +157,7 @@ function forum_menu_local_tasks(&$data, $router_item, $root_path) { $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 356f140..915ddfa 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,24 +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; $entity_info = entity_get_info($entity_type); - $pseudo_field_name = 'reverse_' . $field['field_name'] . '_' . $entity_type; + $pseudo_field_name = 'reverse_' . $field->getFieldName() . '_' . $entity_type; - list($label,) = field_views_field_label($entity_type, $field['field_name']); + list($label,) = field_views_field_label($entity_type, $field->getFieldName()); $entity_label = ($entity_info['label'] == t('Node')) ? t('Content') : $entity_info['label']; $data['file_managed'][$pseudo_field_name]['relationship'] = array( 'title' => t('@entity using @field', array('@entity' => $entity_label, '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the image.', array('@entity' => $entity_label, '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], - 'entity_type' => $field['entity_type'], + 'field_name' => $field->getFieldName(), + 'entity_type' => $field->entity_type, 'field table' => DatabaseStorageController::_fieldTableName($field), - 'field field' => $field['field_name'] . '_target_id', + 'field field' => $field->getFieldName() . '_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->getFieldName())), '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 83aea6f..559e672 100644 --- a/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php +++ b/core/modules/image/lib/Drupal/image/Entity/ImageStyle.php @@ -148,27 +148,27 @@ protected static function replaceImageStyle(ImageStyleInterface $style) { $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']); + if ($instance->getFieldType() == 'image') { + $view_modes = entity_get_view_modes($instance->entity_type); $view_modes = array('default') + array_keys($view_modes); 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($instance->getFieldName()); // 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($instance->getFieldName(), $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($instance->getFieldName()); 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($instance->getFieldName(), $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 45b2eef..3bfdfa4 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($instance->entity_type, $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 5c27462..5326146 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 37de2be..7d28265 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($this->field->getFieldName(), $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 9d79e70..aab8697 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 @@ -278,11 +278,11 @@ 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']); + $widget = entity_get_form_display($instance->entity_type, $instance->bundle, 'default')->getComponent($instance->getFieldName()); // 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[] = $instance->getFieldName(); } } } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeTest.php index 598d552..5589b1c 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 298d44e..1275759 100644 --- a/core/modules/node/node.tokens.inc +++ b/core/modules/node/node.tokens.inc @@ -164,7 +164,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 c5ff8f4..1194c98 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -72,13 +72,13 @@ function testNumberDecimalField() { )); $this->field->save(); entity_create('field_instance', array( - 'field_name' => $this->field->name, + 'field_name' => $this->field->getFieldName(), 'entity_type' => 'entity_test', 'bundle' => 'entity_test', ))->save(); entity_get_form_display('entity_test', 'entity_test', 'default') - ->setComponent($this->field->name, array( + ->setComponent($this->field->getFieldName(), 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($this->field->getFieldName(), 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("{$this->field->getFieldName()}[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, + "{$this->field->getFieldName()}[0][value]" => $value, ); $this->drupalPostForm(NULL, $edit, t('Save')); preg_match('|entity_test/manage/(\d+)/edit|', $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, + "{$this->field->getFieldName()}[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' => $this->field->getFieldName())), '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, + "{$this->field->getFieldName()}[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' => $this->field->getFieldName())), '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 fa54238..7f18ec2 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 e2a004d..4f1f8dc 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(); @@ -290,9 +290,9 @@ function testSelectListSingle() { $this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.'); // Submit form: select invalid 'none' option. - $edit = array('card_1' => '_none'); + $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(); @@ -547,7 +547,7 @@ function testOnOffCheckboxLabelSetting() { ))->save(); entity_get_form_display('node', 'page', 'default') - ->setComponent($this->bool['field_name'], array( + ->setComponent($this->bool->getFieldName(), array( 'type' => 'options_onoff', )) ->save(); @@ -557,7 +557,7 @@ function testOnOffCheckboxLabelSetting() { $fieldEditUrl = 'admin/structure/types/manage/page/form-display'; $this->drupalGet($fieldEditUrl); - $field_name = $this->bool['field_name']; + $field_name = $this->bool->getFieldName(); // 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 6c2c8af..40f49db 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 3c649c5..15ef7a8 100644 --- a/core/modules/options/options.module +++ b/core/modules/options/options.module @@ -68,9 +68,9 @@ function options_field_info() { * Implements hook_field_settings_form(). */ function options_field_settings_form($field, $instance) { - $settings = $field['settings']; + $settings = $field->getFieldSettings(); - switch ($field['type']) { + switch ($field->getFieldType()) { case 'list_integer': case 'list_float': case 'list_text': @@ -82,12 +82,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->getFieldType(), '#access' => empty($settings['allowed_values_function']), ); $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - if ($field['type'] == 'list_integer' || $field['type'] == 'list_float') { + if ($field->getFieldType() == 'list_integer' || $field->getFieldType() == 'list_float') { $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); @@ -142,12 +142,12 @@ 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 ($instance->widget['type'] == 'options_onoff') { $form['allowed_values']['#description'] .= '

' . t("For a 'single on/off checkbox' widget, define the 'off' value first, then the 'on' value in the Allowed values section. Note that the checkbox will be labeled with the label of the 'on' value.") . '

'; } - elseif ($instance['widget']['type'] == 'options_buttons') { + elseif ($instance->widget['type'] == 'options_buttons') { $form['allowed_values']['#description'] .= '

' . t("The 'checkboxes/radio buttons' widget will display checkboxes if the Number of values option is greater than 1 for this field, otherwise radios will be displayed.") . '

'; - } + }*/ $form['allowed_values']['#description'] .= '

' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '

'; $form['allowed_values_function'] = array( @@ -167,10 +167,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->getFieldType(), $generate_keys); if (!is_array($values)) { form_error($element, t('Allowed values list: invalid input.')); @@ -194,7 +194,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 +368,11 @@ 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'])); + $lost_keys = array_diff(array_keys($prior_field->getFieldSetting('allowed_values')), array_keys($field->getFieldSetting('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,12 @@ 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']); + $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 +418,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[$field->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 9c7815c..a6c26cd 100644 --- a/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php +++ b/core/modules/rest/lib/Drupal/rest/LinkManager/RelationLinkManager.php @@ -75,12 +75,12 @@ 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); + foreach ($field->getBundles() as $bundle) { + $relation_uri = $this->getRelationUri($field->entity_type, $bundle, $field->getFieldName()); $data[$relation_uri] = array( 'entity_type' => $field->entity_type, 'bundle' => $bundle, - 'field_name' => $field->name, + 'field_name' => $field->getFieldName(), ); } } 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 68f6303..78326e9 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 d6fb956..5e663ca 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 34818e0..0300118 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/FieldSqlStorageTest.php @@ -114,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->getFieldCardinality(); $delta++) { $value = mt_rand(1, 127); $values[$revision_id][] = $value; $query->values(array($bundle, 0, $entity->id(), $revision_id, $delta, $entity->language()->id, $value)); @@ -131,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->getFieldCardinality()) { $this->assertEqual($entity->{$this->field_name}[$delta]->value, $value); } else { @@ -143,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->getFieldCardinality()) { $this->assertEqual($entity->{$this->field_name}[$delta]->value, $value); } else { @@ -172,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->getFieldCardinality(); $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name} = $values; @@ -180,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->getFieldCardinality()); foreach ($rows as $delta => $row) { $expected = array( 'bundle' => $bundle, @@ -197,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->getFieldCardinality() - 2; $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name} = $values; @@ -220,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->getFieldCardinality(); $delta++) { $values[$delta]['value'] = mt_rand(1, 127); } $entity->{$this->field_name} = $values; @@ -231,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->getFieldCardinality())); 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 d615512..5e9c255 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 c8825af..d1185d2 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,9 @@ 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.'); + $default_image = $instance->getFieldSetting('default_image'); + $file = entity_load('file', $default_image[0]); + $this->assertIdentical($default_image[0], $file->id(), '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 +54,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 9ca18e7..af28f0c 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -496,7 +496,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 844ccb0..616091e 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 df4018a..2e7fca3 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_name => $field) { $update_field = FALSE; - if ($field['type'] == 'taxonomy_term_reference') { - foreach ($field['settings']['allowed_values'] as $key => &$value) { + if ($field->getFieldType() == 'taxonomy_term_reference') { + foreach ($field->settings['allowed_values'] as $key => &$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 5726333..9ad0b6b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -124,7 +124,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { // 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.'); + $this->assertEqual(count($field_info->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 b480f0b..929627c 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 c57397b..ffc8c54 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -54,7 +54,7 @@ function setUp() { )) ->save(); entity_get_display('node', 'article', 'default') - ->setComponent($this->instance['field_name'], array( + ->setComponent($this->instance->getFieldName(), array( 'type' => 'taxonomy_term_reference_link', )) ->save(); @@ -111,7 +111,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 +125,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 +144,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 +164,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 +508,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 +519,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 81537b6..2c23cb5 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\node\Entity\Node; use Drupal\taxonomy\Entity\Term; use Drupal\taxonomy\Entity\Vocabulary; @@ -908,7 +910,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) { @@ -925,7 +927,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 ($field->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()) { @@ -947,9 +949,9 @@ function taxonomy_field_validate(EntityInterface $entity = NULL, $field, $instan } } if (!$validate) { - $errors[$field['field_name']][$langcode][$delta][] = array( + $errors[$field->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())), ); } } @@ -1028,7 +1030,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'), @@ -1112,7 +1114,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 4e9f27c..ffe0b10 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -412,16 +412,16 @@ 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']; + $data[$table_name][$field_name]['filter']['vocabulary'] = $field->settings['allowed_values'][0]['vocabulary']; } } // Add the relationship only on the tid field. - $data[$table_name][$field['field_name'] . '_target_id']['relationship'] = array( + $data[$table_name][$field->getFieldName() . '_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->getFieldName())), ); } @@ -435,24 +435,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']; + $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->getFieldName() . '_' . $entity_type; - list($label,) = field_views_field_label($entity_type, $field['field_name']); + list($label,) = field_views_field_label($entity_type, $field->getFieldName()); $entity_label = ($entity_info['label'] == t('Node')) ? t('Content') : $entity_info['label']; $data['taxonomy_term_data'][$pseudo_field_name]['relationship'] = array( 'title' => t('@entity using @field', array('@entity' => $entity_label, '@field' => $label)), 'help' => t('Relate each @entity with a @field set to the term.', array('@entity' => $entity_label, '@field' => $label)), 'id' => 'entity_reverse', - 'field_name' => $field['field_name'], - 'entity_type' => $field['entity_type'], + 'field_name' => $field->getFieldName(), + 'entity_type' => $field->entity_type, 'field table' => DatabaseStorageController::_fieldTableName($field), - 'field field' => $field['field_name'] . '_target_id', + 'field field' => $field->getFieldName() . '_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->getFieldName())), 'join_extra' => array( 0 => array( 'field' => 'deleted', diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index aeea6b2..471b0bd 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']; }