Commit bcc57632 authored by alexpott's avatar alexpott

Issue #1953408 by swentel, aspilicious, andypost, yched: Remove ArrayAccess BC...

Issue #1953408 by swentel, aspilicious, andypost, yched: Remove ArrayAccess BC layer from field config entities.
parent cd74c624
......@@ -53,7 +53,6 @@ public function validate(array $form, array &$form_state) {
// Map errors back to form elements.
if ($violations) {
foreach ($violations as $field_name => $field_violations) {
$langcode = field_is_translatable($entity_type, field_info_field($entity_type, $field_name)) ? $entity_langcode : Language::LANGCODE_NOT_SPECIFIED;
$field_state = field_form_get_state($form['#parents'], $field_name, $form_state);
$field_state['constraint_violations'] = $field_violations;
field_form_set_state($form['#parents'], $field_name, $form_state, $field_state);
......
......@@ -588,7 +588,7 @@ protected function doLoadFieldItems($entities, $age) {
// If the field is translatable ensure that only values having valid
// languages are retrieved. Since we are loading values for multiple
// entities, we cannot limit the query to the available translations.
$langcodes = $field['translatable'] ? $all_langcodes : array(Language::LANGCODE_NOT_SPECIFIED);
$langcodes = $field->isFieldTranslatable() ? $all_langcodes : array(Language::LANGCODE_NOT_SPECIFIED);
$results = $this->database->select($table, 't')
->fields('t')
->condition($load_current ? 'entity_id' : 'revision_id', $ids, 'IN')
......@@ -603,11 +603,11 @@ protected function doLoadFieldItems($entities, $age) {
$delta_count[$row->entity_id][$row->langcode] = 0;
}
if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field['cardinality']) {
if ($field->getFieldCardinality() == FIELD_CARDINALITY_UNLIMITED || $delta_count[$row->entity_id][$row->langcode] < $field->getFieldCardinality()) {
$item = array();
// For each column declared by the field, populate the item from the
// prefixed database column.
foreach ($field['columns'] as $column => $attributes) {
foreach ($field->getColumns() as $column => $attributes) {
$column_name = static::_fieldColumnName($field, $column);
// Unserialize the value if specified in the column schema.
$item[$column] = (!empty($attributes['serialize'])) ? unserialize($row->$column_name) : $row->$column_name;
......@@ -656,13 +656,13 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) {
// Prepare the multi-insert query.
$do_insert = FALSE;
$columns = array('entity_id', 'revision_id', 'bundle', 'delta', 'langcode');
foreach ($field['columns'] as $column => $attributes) {
foreach ($field->getColumns() as $column => $attributes) {
$columns[] = static::_fieldColumnName($field, $column);
}
$query = $this->database->insert($table_name)->fields($columns);
$revision_query = $this->database->insert($revision_name)->fields($columns);
$langcodes = $field['translatable'] ? array_keys($entity->getTranslationLanguages()) : array(Language::LANGCODE_NOT_SPECIFIED);
$langcodes = $field->isFieldTranslatable() ? array_keys($entity->getTranslationLanguages()) : array(Language::LANGCODE_NOT_SPECIFIED);
foreach ($langcodes as $langcode) {
$delta_count = 0;
$items = $entity->getTranslation($langcode)->get($field_name);
......@@ -677,7 +677,7 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) {
'delta' => $delta,
'langcode' => $langcode,
);
foreach ($field['columns'] as $column => $attributes) {
foreach ($field->getColumns() as $column => $attributes) {
$column_name = static::_fieldColumnName($field, $column);
// Serialize the value if specified in the column schema.
$record[$column_name] = !empty($attributes['serialize']) ? serialize($item->$column) : $item->$column;
......@@ -685,7 +685,7 @@ protected function doSaveFieldItems(EntityInterface $entity, $update) {
$query->values($record);
$revision_query->values($record);
if ($field['cardinality'] != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field['cardinality']) {
if ($field->getFieldCardinality() != FIELD_CARDINALITY_UNLIMITED && ++$delta_count == $field->getFieldCardinality()) {
break;
}
}
......@@ -788,7 +788,7 @@ public function onFieldUpdate(FieldInterface $field) {
}
}
else {
if ($field['columns'] != $original['columns']) {
if ($field->getColumns() != $original->getColumns()) {
throw new FieldUpdateForbiddenException("The SQL storage cannot change the schema for an existing field with data.");
}
// There is data, so there are no column changes. Drop all the prior
......@@ -838,7 +838,7 @@ public function onFieldUpdate(FieldInterface $field) {
*/
public function onFieldDelete(FieldInterface $field) {
// Mark all data associated with the field for deletion.
$field['deleted'] = FALSE;
$field->deleted = FALSE;
$table = static::_fieldTableName($field);
$revision_table = static::_fieldRevisionTableName($field);
$this->database->update($table)
......@@ -847,7 +847,7 @@ public function onFieldDelete(FieldInterface $field) {
// Move the table to a unique name while the table contents are being
// deleted.
$field['deleted'] = TRUE;
$field->deleted = TRUE;
$new_table = static::_fieldTableName($field);
$revision_new_table = static::_fieldRevisionTableName($field);
$this->database->schema()->renameTable($table, $new_table);
......@@ -863,11 +863,11 @@ public function onInstanceDelete(FieldInstanceInterface $instance) {
$revision_name = static::_fieldRevisionTableName($field);
$this->database->update($table_name)
->fields(array('deleted' => 1))
->condition('bundle', $instance['bundle'])
->condition('bundle', $instance->bundle)
->execute();
$this->database->update($revision_name)
->fields(array('deleted' => 1))
->condition('bundle', $instance['bundle'])
->condition('bundle', $instance->bundle)
->execute();
}
......@@ -953,13 +953,13 @@ public function onFieldPurge(FieldInterface $field) {
* @see hook_schema()
*/
public static function _fieldSqlSchema(FieldInterface $field, array $schema = NULL) {
if ($field['deleted']) {
$description_current = "Data storage for deleted field {$field['id']} ({$field['entity_type']}, {$field['field_name']}).";
$description_revision = "Revision archive storage for deleted field {$field['id']} ({$field['entity_type']}, {$field['field_name']}).";
if ($field->deleted) {
$description_current = "Data storage for deleted field {$field->uuid()} ({$field->entity_type}, {$field->getFieldName()}).";
$description_revision = "Revision archive storage for deleted field {$field->uuid()} ({$field->entity_type}, {$field->getFieldName()}).";
}
else {
$description_current = "Data storage for {$field['entity_type']} field {$field['field_name']}.";
$description_revision = "Revision archive storage for {$field['entity_type']} field {$field['field_name']}.";
$description_current = "Data storage for {$field->entity_type} field {$field->getFieldName()}.";
$description_revision = "Revision archive storage for {$field->entity_type} field {$field->getFieldName()}.";
}
$current = array(
......@@ -1084,12 +1084,12 @@ public static function _fieldSqlSchema(FieldInterface $field, array $schema = NU
*
*/
static public function _fieldTableName(FieldInterface $field) {
if ($field['deleted']) {
if ($field->deleted) {
// When a field is a deleted, the table is renamed to
// {field_deleted_data_FIELD_UUID}. To make sure we don't end up with
// table names longer than 64 characters, we hash the uuid and return the
// first 10 characters so we end up with a short unique ID.
return "field_deleted_data_" . substr(hash('sha256', $field['uuid']), 0, 10);
return "field_deleted_data_" . substr(hash('sha256', $field->uuid()), 0, 10);
}
else {
return static::_generateFieldTableName($field, FALSE);
......@@ -1113,12 +1113,12 @@ static public function _fieldTableName(FieldInterface $field) {
* A string containing the generated name for the database table.
*/
static public function _fieldRevisionTableName(FieldInterface $field) {
if ($field['deleted']) {
if ($field->deleted) {
// When a field is a deleted, the table is renamed to
// {field_deleted_revision_FIELD_UUID}. To make sure we don't end up with
// table names longer than 64 characters, we hash the uuid and return the
// first 10 characters so we end up with a short unique ID.
return "field_deleted_revision_" . substr(hash('sha256', $field['uuid']), 0, 10);
return "field_deleted_revision_" . substr(hash('sha256', $field->uuid()), 0, 10);
}
else {
return static::_generateFieldTableName($field, TRUE);
......@@ -1139,7 +1139,7 @@ static public function _fieldRevisionTableName(FieldInterface $field) {
* @return string
* The final table name.
*/
static protected function _generateFieldTableName($field, $revision) {
static protected function _generateFieldTableName(FieldInterface $field, $revision) {
$separator = $revision ? '_revision__' : '__';
$table_name = $field->entity_type . $separator . $field->name;
// Limit the string to 48 characters, keeping a 16 characters margin for db
......
......@@ -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');
......
......@@ -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);
......
......@@ -79,7 +79,7 @@ public function testCustomBlockTypeEditing() {
$this->createCustomBlockType('other');
$instance = field_info_instance('custom_block', 'body', 'basic');
$this->assertEqual($instance['label'], 'Block body', 'Body field was found.');
$this->assertEqual($instance->getFieldLabel(), 'Block body', 'Body field was found.');
// Verify that title and body fields are displayed.
$this->drupalGet('block/add/basic');
......
......@@ -923,7 +923,7 @@ function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL)
* Implements hook_form_FORM_ID_alter().
*/
function comment_form_field_ui_field_instance_edit_form_alter(&$form, $form_state) {
if ($form['#field']['type'] == 'comment') {
if ($form['#field']->getFieldType() == 'comment') {
// Collect translation settings.
if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
array_unshift($form['#submit'], 'comment_translation_configuration_element_submit');
......@@ -965,7 +965,7 @@ function comment_form_field_ui_display_overview_form_alter(&$form, $form_state)
* Implements hook_form_FORM_ID_alter().
*/
function comment_form_field_ui_field_edit_form_alter(&$form, $form_state) {
if ($form['#field']['type'] == 'comment') {
if ($form['#field']->getFieldType() == 'comment') {
// We only support posting one comment at the time so it doesn't make sense
// to let the site builder choose anything else.
$form['field']['cardinality_container']['cardinality']['#options'] = drupal_map_assoc(array(1));
......
......@@ -74,7 +74,7 @@ function setUp() {
// Make comment body translatable.
$field = field_info_field('comment', 'comment_body');
$field['translatable'] = TRUE;
$field->translatable = TRUE;
$field->save();
$this->assertTrue(field_is_translatable('comment', $field), 'Comment body is translatable.');
}
......
......@@ -88,8 +88,8 @@ function postComment(EntityInterface $entity, $comment, $subject = '', $contact
$edit['comment_body[0][value]'] = $comment;
$instance = $this->container->get('field.info')->getInstance('entity_test_render', 'entity_test_render', 'comment');
$preview_mode = $instance['settings']['preview'];
$subject_mode = $instance['settings']['subject'];
$preview_mode = $instance->getFieldSetting('preview');
$subject_mode = $instance->getFieldSetting('subject');
// Must get the page before we test for fields.
if ($entity !== NULL) {
......
......@@ -77,7 +77,7 @@ protected function getTranslatorPermissions() {
function setupTestFields() {
parent::setupTestFields();
$field = field_info_field('comment', 'comment_body');
$field['translatable'] = TRUE;
$field->translatable = TRUE;
$field->save();
}
......
......@@ -6,40 +6,39 @@
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Field\FieldDefinitionInterface;
use Drupal\Core\Language\Language;
use Drupal\field\Entity\Field;
use Drupal\field\Entity\FieldInstance;
/**
* Returns a form element to configure field synchronization.
*
* @param \Drupal\field\Entity\Field $field
* A field definition array.
* @param \Drupal\field\Entity\FieldInstance $instance
* A field instance definition object.
* @param \Drupal\Core\Entity\Field\FieldDefinitionInterface $field
* A field definition object.
*
* @return array
* A form element to configure field synchronization.
*/
function content_translation_field_sync_widget(Field $field, FieldInstance $instance) {
function content_translation_field_sync_widget(FieldDefinitionInterface $field) {
$element = array();
if (!empty($field['settings']['column_groups']) && count($field['settings']['column_groups']) > 1) {
$column_groups = $field->getFieldSetting('column_groups');
if (!empty($column_groups) && count($column_groups) > 1) {
$options = array();
$default = array();
foreach ($field['settings']['column_groups'] as $group => $info) {
foreach ($column_groups as $group => $info) {
$options[$group] = $info['label'];
$default[$group] = !empty($info['translatable']) ? $group : FALSE;
}
$settings = array('dependent_selectors' => array('instance[settings][translation_sync]' => array('file')));
$translation_sync = $field->getFieldSetting('translation_sync');
$element = array(
'#type' => 'checkboxes',
'#title' => t('Translatable elements'),
'#options' => $options,
'#default_value' => !empty($instance['settings']['translation_sync']) ? $instance['settings']['translation_sync'] : $default,
'#default_value' => !empty($translation_sync) ? $translation_sync : $default,
'#attached' => array(
'library' => array(
array('content_translation', 'drupal.content_translation.admin'),
......@@ -85,8 +84,8 @@ function _content_translation_form_language_content_settings_form_alter(array &$
// Only show the checkbox to enable translation if the bundles in the
// entity might have fields and if there are fields to translate.
if (!empty($entity_info['fieldable'])) {
$fields = field_info_instances($entity_type, $bundle);
if ($fields) {
$instances = field_info_instances($entity_type, $bundle);
if ($instances) {
$form['settings'][$entity_type][$bundle]['translatable'] = array(
'#type' => 'checkbox',
'#title' => $bundle,
......@@ -95,15 +94,14 @@ function _content_translation_form_language_content_settings_form_alter(array &$
// @todo Exploit field definitions once all core entities and field
// types are migrated to the Entity Field API.
foreach ($fields as $field_name => $instance) {
$field = $instance->getField();
foreach ($instances as $field_name => $instance) {
$form['settings'][$entity_type][$bundle]['fields'][$field_name] = array(
'#label' => $instance['label'],
'#label' => $instance->getFieldLabel(),
'#type' => 'checkbox',
'#title' => $instance['label'],
'#default_value' => $field['translatable'],
'#title' => $instance->getFieldLabel(),
'#default_value' => $instance->isFieldTranslatable(),
);
$column_element = content_translation_field_sync_widget($field, $instance);
$column_element = content_translation_field_sync_widget($instance);
if ($column_element) {
$form['settings'][$entity_type][$bundle]['columns'][$field_name] = $column_element;
......@@ -340,7 +338,7 @@ function _content_translation_update_field_translatability($settings) {
foreach ($fields as $entity_type => $entity_type_fields) {
foreach ($entity_type_fields as $field_name => $translatable) {
$field = field_info_field($entity_type, $field_name);
if ($field['translatable'] != $translatable) {
if ($field->isFieldTranslatable() != $translatable) {
// If a field is untranslatable, it can have no data except under
// Language::LANGCODE_NOT_SPECIFIED. Thus we need a field to be translatable before
// we convert data to the entity language. Conversely we need to switch
......@@ -385,8 +383,8 @@ function _content_translation_update_field_translatability($settings) {
*/
function content_translation_translatable_switch($translatable, $entity_type, $field_name) {
$field = field_info_field($entity_type, $field_name);
if ($field['translatable'] !== $translatable) {
$field['translatable'] = $translatable;
if ($field->isFieldTranslatable() !== $translatable) {
$field->translatable = $translatable;
$field->save();
}
}
......@@ -420,7 +418,8 @@ function content_translation_translatable_batch($translatable, $field_name, &$co
foreach ($entity_types as $entity_type) {
$field = field_info_field($entity_type, $field_name);
$column = isset($field['columns']['value']) ? 'value' : key($field['columns']);
$columns = $field->getColumns();
$column = isset($columns['value']) ? 'value' : key($columns);
$query_field = "$field_name.$column";
// How many entities will need processing?
......@@ -451,7 +450,8 @@ function content_translation_translatable_batch($translatable, $field_name, &$co
$offset = $context['sandbox']['progress_entity_type'][$entity_type];
$query = \Drupal::entityQuery($entity_type);
$field = field_info_field($entity_type, $field_name);
$column = isset($field['columns']['value']) ? 'value' : key($field['columns']);
$columns = $field->getColumns();
$column = isset($columns['value']) ? 'value' : key($columns);
$query_field = "$field_name.$column";
$result = $query
->exists($query_field)
......
......@@ -775,9 +775,9 @@ function content_translation_field_extra_fields() {
*/
function content_translation_form_field_ui_field_edit_form_alter(array &$form, array &$form_state, $form_id) {
$field = $form['#field'];
$entity_type = $field['entity_type'];
$field_name = $field['field_name'];
$translatable = $field['translatable'];
$field_name = $field->getFieldName();
$translatable = $field->isFieldTranslatable();
$entity_type = $field->entity_type;
$label = t('Field translation');
if ($field->hasData()) {
......@@ -810,9 +810,9 @@ function content_translation_form_field_ui_field_edit_form_alter(array &$form, a
* Implements hook_form_FORM_ID_alter() for 'field_ui_field_instance_edit_form'.
*/
function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, array &$form_state, $form_id) {
if ($form['#field']['translatable']) {
if ($form['#instance']->isFieldTranslatable()) {
module_load_include('inc', 'content_translation', 'content_translation.admin');
$element = content_translation_field_sync_widget($form['#field'], $form['#instance']);
$element = content_translation_field_sync_widget($form['#instance']);
if ($element) {
$form['instance']['settings']['translation_sync'] = $element;
}
......@@ -990,10 +990,9 @@ function content_translation_save_settings($settings) {
// Store whether fields have translation enabled or not.
if (!empty($bundle_settings['columns'])) {
foreach ($bundle_settings['columns'] as $field_name => $column_settings) {
$field = field_info_field($entity_type, $field_name);
$instance = field_info_instance($entity_type, $field_name, $bundle);
if ($field['translatable']) {
$instance['settings']['translation_sync'] = $column_settings;
if ($instance->isFieldTranslatable()) {
$instance->settings['translation_sync'] = $column_settings;
}
// If the field does not have translatable enabled we need to reset
// the sync settings to their defaults.
......
......@@ -42,8 +42,7 @@ function content_translation_overview(EntityInterface $entity) {
// Determine whether the current entity is translatable.
$translatable = FALSE;
foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) {
$field = $instance->getField();
if ($field['translatable']) {
if ($instance->isFieldTranslatable()) {
$translatable = TRUE;
break;
}
......
......@@ -60,14 +60,16 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode
// Sync when the field is not empty, when the synchronization translations
// setting is set, and the field is translatable.
if (!$entity->get($field_name)->isEmpty() && !empty($instance['settings']['translation_sync']) && field_is_translatable($entity_type, $field)) {
$translation_sync = $instance->getFieldSetting('translation_sync');
if (!$entity->get($field_name)->isEmpty() && !empty($translation_sync) && field_is_translatable($entity_type, $field)) {
// Retrieve all the untranslatable column groups and merge them into
// single list.
$groups = array_keys(array_diff($instance['settings']['translation_sync'], array_filter($instance['settings']['translation_sync'])));
$groups = array_keys(array_diff($translation_sync, array_filter($translation_sync)));
if (!empty($groups)) {
$columns = array();
foreach ($groups as $group) {
$info = $field['settings']['column_groups'][$group];
$column_groups = $field->getFieldSetting('column_groups');
$info = $column_groups[$group];
// A missing 'columns' key indicates we have a single-column group.
$columns = array_merge($columns, isset($info['columns']) ? $info['columns'] : array($group));
}
......
......@@ -43,7 +43,7 @@ public function getFormID() {
* {@inheritdoc}
*/
public function getQuestion() {
if ($this->field['translatable']) {
if ($this->field->isFieldTranslatable()) {
$question = t('Are you sure you want to disable translation for the %name field?', array('%name' => $this->fieldName));
}
else {
......@@ -59,7 +59,7 @@ public function getDescription() {
$description = t('By submitting this form these changes will apply to the %name field everywhere it is used.',
array('%name' => $this->fieldName)
);
$description .= $this->field['translatable'] ? "<br>" . t("<strong>All the existing translations of this field will be deleted.</strong><br>This action cannot be undone.") : '';
$description .= $this->field->isFieldTranslatable() ? "<br>" . t("<strong>All the existing translations of this field will be deleted.</strong><br>This action cannot be undone.") : '';
return $description;
}
......@@ -107,7 +107,7 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
public function submitForm(array &$form, array &$form_state) {
// This is the current state that we want to reverse.
$translatable = $form_state['values']['translatable'];
if ($this->field['translatable'] !== $translatable) {
if ($this->field->translatable !== $translatable) {
// Field translatability has changed since form creation, abort.
$t_args = array('%field_name');
$msg = $translatable ?
......
......@@ -91,7 +91,7 @@ function testSettingsUI() {
$this->assertSettings('comment', 'node__comment_article', TRUE, $edit);
field_info_cache_clear();
$field = field_info_field('comment', 'comment_body');
$this->assertTrue($field['translatable'], 'Comment body is translatable.');
$this->assertTrue($field->isFieldTranslatable(), 'Comment body is translatable.');
// Test that language settings are correctly stored.
$language_configuration = language_get_default_configuration('comment', 'node__comment_article');
......
......@@ -191,11 +191,11 @@ function datetime_default_value($entity, $field, $instance, $langcode) {
$value = '';
$date = '';
if ($instance['settings']['default_value'] == 'now') {
if ($instance->getFieldSetting('default_value') == 'now') {
// A default value should be in the format and timezone used for date
// storage.
$date = new DrupalDateTime('now', DATETIME_STORAGE_TIMEZONE);
$storage_format = $field['settings']['datetime_type'] == 'date' ? DATETIME_DATE_STORAGE_FORMAT: DATETIME_DATETIME_STORAGE_FORMAT;
$storage_format = $field->getFieldSetting('datetime_type') == 'date' ? DATETIME_DATE_STORAGE_FORMAT: DATETIME_DATETIME_STORAGE_FORMAT;
$value = $date->format($storage_format);
}
......
......@@ -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(
......
......@@ -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.
......
......@@ -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;
......
......@@ -232,8 +232,7 @@ public function setComponent($name, array $options = array()) {
}
if ($instance = field_info_instance($this->targetEntityType, $name, $this->bundle)) {
$field = $instance->getField();
$options = $this->pluginManager->prepareConfiguration($field['type'], $options);
$options = $this->pluginManager->prepareConfiguration($instance->getFieldType(), $options);
// Clear the persisted plugin, if any.
unset($this->plugins[$name]);
......
......@@ -37,15 +37,14 @@ function entity_reference_field_info_alter(&$info) {
function entity_reference_entity_field_info_alter(&$info, $entity_type) {
foreach (field_info_instances($entity_type) as $bundle_name => $instances) {
foreach ($instances as $field_name => $instance) {
$field = $instance->getField();
if ($field['type'] != 'entity_reference') {
if ($instance->getFieldType() != 'entity_reference') {
continue;
}
if (isset($info['definitions'][$field_name])) {
$info['definitions'][$field_name]['settings']['target_type'] = $field['settings']['target_type'];
$info['definitions'][$field_name]['settings']['target_type'] = $instance->getFieldSetting('target_type');
}
elseif (isset($info['optional'][$field_name])) {