Issue #2143291 by plach, alexpott, xjm, effulgentsia, pwolanin, swentel | yched: Clarify handling of field translatability.

8.0.x
Nathaniel Catchpole 2014-06-20 18:40:27 +01:00
parent 0f752ca609
commit 86e432e05e
78 changed files with 423 additions and 459 deletions

View File

@ -14,13 +14,12 @@ use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Entity\Schema\ContentEntitySchemaHandler;
use Drupal\Core\Entity\Sql\DefaultTableMapping;
use Drupal\Core\Entity\Sql\SqlEntityStorageInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\FieldConfigUpdateForbiddenException;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldConfigUpdateForbiddenException;
use Drupal\field\FieldInstanceConfigInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -239,11 +238,11 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
public function getTableMapping() {
if (!isset($this->tableMapping)) {
$definitions = array_filter($this->getFieldStorageDefinitions(), function (FieldDefinitionInterface $definition) {
$definitions = array_filter($this->getFieldStorageDefinitions(), function (FieldStorageDefinitionInterface $definition) {
// @todo Remove the check for FieldDefinitionInterface::isMultiple() when
// multiple-value base fields are supported in
// https://drupal.org/node/2248977.
return !$definition->isComputed() && !$definition->hasCustomStorage() && !$definition->isMultiple();
return !$definition->hasCustomStorage() && !$definition->isMultiple();
});
$this->tableMapping = new DefaultTableMapping($definitions);
@ -956,10 +955,12 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
// Collect impacted fields.
$fields = array();
$definitions = array();
foreach ($bundles as $bundle => $v) {
foreach ($this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle) as $field_name => $instance) {
$definitions[$bundle] = $this->entityManager->getFieldDefinitions($this->entityTypeId, $bundle);
foreach ($definitions[$bundle] as $field_name => $instance) {
if ($instance instanceof FieldInstanceConfigInterface) {
$fields[$field_name] = $instance->getField();
$fields[$field_name] = $instance->getFieldStorageDefinition();
}
}
}
@ -982,10 +983,11 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
$delta_count = array();
foreach ($results as $row) {
$bundle = $entities[$row->entity_id]->bundle();
// Ensure that records for non-translatable fields having invalid
// languages are skipped.
if ($row->langcode == $default_langcodes[$row->entity_id] || $field->isTranslatable()) {
if ($row->langcode == $default_langcodes[$row->entity_id] || $definitions[$bundle][$field_name]->isTranslatable()) {
if (!isset($delta_count[$row->entity_id][$row->langcode])) {
$delta_count[$row->entity_id][$row->langcode] = 0;
}
@ -1028,7 +1030,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
if (!($instance instanceof FieldInstanceConfigInterface)) {
continue;
}
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$table_name = static::_fieldTableName($field);
$revision_name = static::_fieldRevisionTableName($field);
@ -1105,7 +1107,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
if (!($instance instanceof FieldInstanceConfigInterface)) {
continue;
}
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$table_name = static::_fieldTableName($field);
$revision_name = static::_fieldRevisionTableName($field);
$this->database->delete($table_name)
@ -1127,7 +1129,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
if (!($instance instanceof FieldInstanceConfigInterface)) {
continue;
}
$revision_name = static::_fieldRevisionTableName($instance->getField());
$revision_name = static::_fieldRevisionTableName($instance->getFieldStorageDefinition());
$this->database->delete($revision_name)
->condition('entity_id', $entity->id())
->condition('revision_id', $vid)
@ -1258,7 +1260,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
* {@inheritdoc}
*/
public function onInstanceDelete(FieldInstanceConfigInterface $instance) {
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$table_name = static::_fieldTableName($field);
$revision_name = static::_fieldRevisionTableName($field);
$this->database->update($table_name)
@ -1280,7 +1282,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
// using the old bundle name.
$instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $this->entityTypeId, 'bundle' => $bundle, 'include_deleted' => TRUE));
foreach ($instances as $instance) {
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$table_name = static::_fieldTableName($field);
$revision_name = static::_fieldRevisionTableName($field);
$this->database->update($table_name)
@ -1298,7 +1300,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
* {@inheritdoc}
*/
protected function readFieldItemsToPurge(EntityInterface $entity, FieldInstanceConfigInterface $instance) {
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$table_name = static::_fieldTableName($field);
$query = $this->database->select($table_name, 't', array('fetch' => \PDO::FETCH_ASSOC))
->condition('entity_id', $entity->id())
@ -1313,7 +1315,7 @@ class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements S
* {@inheritdoc}
*/
public function purgeFieldItems(EntityInterface $entity, FieldInstanceConfigInterface $instance) {
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$table_name = static::_fieldTableName($field);
$revision_name = static::_fieldRevisionTableName($field);
$this->database->delete($table_name)

View File

@ -15,7 +15,7 @@ use Drupal\field\FieldException;
/**
* A class for defining entity fields.
*/
class FieldDefinition extends ListDataDefinition implements FieldDefinitionInterface {
class FieldDefinition extends ListDataDefinition implements FieldDefinitionInterface, FieldStorageDefinitionInterface {
/**
* The field type.
@ -253,7 +253,7 @@ class FieldDefinition extends ListDataDefinition implements FieldDefinitionInter
* Sets the maximum number of items allowed for the field.
*
* Possible values are positive integers or
* FieldDefinitionInterface::CARDINALITY_UNLIMITED.
* FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
*
* @param int $cardinality
* The field cardinality.
@ -592,4 +592,11 @@ class FieldDefinition extends ListDataDefinition implements FieldDefinitionInter
return $this;
}
/**
* {@inheritdoc}
*/
public function getFieldStorageDefinition() {
return $this;
}
}

View File

@ -52,7 +52,28 @@ use Drupal\Core\TypedData\ListDataDefinitionInterface;
* based on that abstract definition, even though that abstract definition can
* differ from the concrete definition of any particular node's body field.
*/
interface FieldDefinitionInterface extends FieldStorageDefinitionInterface, ListDataDefinitionInterface {
interface FieldDefinitionInterface extends ListDataDefinitionInterface {
/**
* Returns the machine name of the field.
*
* This defines how the field data is accessed from the entity. For example,
* if the field name is "foo", then $entity->foo returns its data.
*
* @return string
* The field name.
*/
public function getName();
/**
* Returns the field type.
*
* @return string
* The field type, i.e. the id of a field type plugin. For example 'text'.
*
* @see \Drupal\Core\Field\FieldTypePluginManagerInterface
*/
public function getType();
/**
* Returns whether the display for the field can be configured.
@ -131,4 +152,29 @@ interface FieldDefinitionInterface extends FieldStorageDefinitionInterface, List
*/
public function getDefaultValue(ContentEntityInterface $entity);
/**
* Returns whether the field is translatable.
*
* @return bool
* TRUE if the field is translatable.
*/
public function isTranslatable();
/**
* Sets whether the field is translatable.
*
* @param bool $translatable
* Whether the field is translatable.
*
* @return $this
*/
public function setTranslatable($translatable);
/**
* Returns the field storage definition.
*
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface
* The field storage definition.
*/
public function getFieldStorageDefinition();
}

View File

@ -7,12 +7,12 @@
namespace Drupal\Core\Field;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\DataDefinitionInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\TypedData\TypedDataInterface;
/**
* Represents an entity field; that is, a list of field item objects.
@ -285,8 +285,8 @@ class FieldItemList extends ItemList implements FieldItemListInterface {
// Check that the number of values doesn't exceed the field cardinality. For
// form submitted values, this can only happen with 'multiple value'
// widgets.
$cardinality = $this->getFieldDefinition()->getCardinality();
if ($cardinality != FieldDefinitionInterface::CARDINALITY_UNLIMITED) {
$cardinality = $this->getFieldDefinition()->getFieldStorageDefinition()->getCardinality();
if ($cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$constraints[] = \Drupal::typedDataManager()
->getValidationConstraintManager()
->create('Count', array(

View File

@ -77,13 +77,23 @@ interface FieldStorageDefinitionInterface {
public function getSetting($setting_name);
/**
* Returns whether the field is translatable.
* Returns whether the field supports translation.
*
* @return bool
* TRUE if the field is translatable.
* TRUE if the field supports translation.
*/
public function isTranslatable();
/**
* Sets whether the field supports translation.
*
* @param bool $translatable
* Whether the field supports translation.
*
* @return $this
*/
public function setTranslatable($translatable);
/**
* Returns whether the field is revisionable.
*
@ -193,8 +203,8 @@ interface FieldStorageDefinitionInterface {
* This method should not be confused with EntityInterface::entityType()
* (configurable fields are config entities, and thus implement both
* interfaces):
* - FieldDefinitionInterface::getTargetEntityTypeId() answers "as a field,
* which entity type are you attached to?".
* - FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a
* field, which entity type are you attached to?".
* - EntityInterface::getEntityTypeId() answers "as a (config) entity, what
* is your own entity type".
*
@ -231,7 +241,7 @@ interface FieldStorageDefinitionInterface {
* The array of field columns, keyed by column name, in the same format
* returned by getSchema().
*
* @see \Drupal\Core\Field\FieldDefinitionInterface::getSchema()
* @see \Drupal\Core\Field\FieldStorageDefinitionInterface::getSchema()
*/
public function getColumns();

View File

@ -61,21 +61,21 @@ class FieldItemDataDefinition extends DataDefinition implements ComplexDataDefin
* {@inheritdoc}
*/
public function getPropertyDefinition($name) {
return $this->fieldDefinition->getPropertyDefinition($name);
return $this->fieldDefinition->getFieldStorageDefinition()->getPropertyDefinition($name);
}
/**
* {@inheritdoc}
*/
public function getPropertyDefinitions() {
return $this->fieldDefinition->getPropertyDefinitions();
return $this->fieldDefinition->getFieldStorageDefinition()->getPropertyDefinitions();
}
/**
* {@inheritdoc}
*/
public function getMainPropertyName() {
return $this->fieldDefinition->getMainPropertyName();
return $this->fieldDefinition->getFieldStorageDefinition()->getMainPropertyName();
}
}

View File

@ -142,12 +142,12 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
*/
protected function formMultipleElements(FieldItemListInterface $items, array &$form, array &$form_state) {
$field_name = $this->fieldDefinition->getName();
$cardinality = $this->fieldDefinition->getCardinality();
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
$parents = $form['#parents'];
// Determine the number of widgets to display.
switch ($cardinality) {
case FieldDefinitionInterface::CARDINALITY_UNLIMITED:
case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
$field_state = field_form_get_state($parents, $field_name, $form_state);
$max = $field_state['items_count'];
$is_multiple = TRUE;
@ -198,7 +198,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
'#theme' => 'field_multiple_value_form',
'#field_name' => $field_name,
'#cardinality' => $cardinality,
'#cardinality_multiple' => $this->fieldDefinition->isMultiple(),
'#cardinality_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(),
'#required' => $this->fieldDefinition->isRequired(),
'#title' => $title,
'#description' => $description,
@ -206,7 +206,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
);
// Add 'add more' button, if not working with a programmed form.
if ($cardinality == FieldDefinitionInterface::CARDINALITY_UNLIMITED && empty($form_state['programmed'])) {
if ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED && empty($form_state['programmed'])) {
$id_prefix = implode('-', array_merge($parents, array($field_name)));
$wrapper_id = drupal_html_id($id_prefix . '-add-more-wrapper');
@ -264,7 +264,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
$element = NestedArray::getValue($form, array_slice($button['#array_parents'], 0, -1));
// Ensure the widget allows adding additional items.
if ($element['#cardinality'] != FieldDefinitionInterface::CARDINALITY_UNLIMITED) {
if ($element['#cardinality'] != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
return;
}

View File

@ -6,10 +6,10 @@
*/
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\Element;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldInstanceConfigInterface;
/**
@ -79,7 +79,9 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$dependent_options_settings = array();
$entity_manager = Drupal::entityManager();
foreach ($form['#labels'] as $entity_type_id => $label) {
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
$entity_type = $entity_manager->getDefinition($entity_type_id);
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array();
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
// Here we do not want the widget to be altered and hold also the "Enable
// translation" checkbox, which would be redundant. Hence we add this key
@ -98,44 +100,33 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$field_settings = content_translation_get_config($entity_type_id, $bundle, 'fields');
foreach ($fields as $field_name => $definition) {
$translatable = !empty($field_settings[$field_name]);
// We special case Field API fields as they always natively support
// translation.
// @todo Remove this special casing as soon as configurable and
// base field definitions are "unified".
if ($definition instanceof FieldInstanceConfigInterface) {
// Allow to configure only fields supporting multilingual storage.
if (!empty($storage_definitions[$field_name]) && $storage_definitions[$field_name]->isTranslatable()) {
$form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
'#label' => $definition->getLabel(),
'#type' => 'checkbox',
'#default_value' => $translatable,
'#default_value' => $definition->isTranslatable(),
);
$column_element = content_translation_field_sync_widget($definition);
if ($column_element) {
$form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element;
// @todo This should not concern only files.
if (isset($column_element['#options']['file'])) {
$dependent_options_settings["settings[{$entity_type_id}][{$bundle}][columns][{$field_name}]"] = array('file');
// Display the column translatability configuration widget.
// @todo Remove this special casing when arbitrary settings can be
// stored for any field. See https://drupal.org/node/2224761.
if ($definition instanceof FieldInstanceConfigInterface) {
$column_element = content_translation_field_sync_widget($definition);
if ($column_element) {
$form['settings'][$entity_type_id][$bundle]['columns'][$field_name] = $column_element;
// @todo This should not concern only files.
if (isset($column_element['#options']['file'])) {
$dependent_options_settings["settings[{$entity_type_id}][{$bundle}][columns][{$field_name}]"] = array('file');
}
}
}
}
// Instead we need to rely on field definitions to determine whether
// fields support translation. Whether they are actually enabled is
// determined through our settings. As a consequence only fields
// that support translation can be enabled or disabled.
elseif (isset($field_settings[$field_name]) || $definition->isTranslatable()) {
$form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
'#label' => $definition->getLabel(),
'#type' => 'checkbox',
'#default_value' => $translatable,
);
}
}
}
}
}
}
$settings = array('dependent_selectors' => $dependent_options_settings);
$form['#attached']['js'][] = array('data' => array('contentTranslationDependentOptions' => $settings), 'type' => 'setting');
$form['#validate'][] = 'content_translation_form_language_content_settings_validate';
@ -300,68 +291,40 @@ function content_translation_form_language_content_settings_submit(array $form,
// If an entity type is not translatable all its bundles and fields must be
// marked as non-translatable. Similarly, if a bundle is made non-translatable
// all of its fields will be not translatable.
foreach ($settings as $entity_type => &$entity_settings) {
foreach ($entity_settings as &$bundle_settings) {
foreach ($settings as $entity_type_id => &$entity_settings) {
foreach ($entity_settings as $bundle => &$bundle_settings) {
if (!empty($bundle_settings['translatable'])) {
$bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type];
$bundle_settings['translatable'] = $bundle_settings['translatable'] && $entity_types[$entity_type_id];
}
if (!empty($bundle_settings['fields'])) {
$definitions = \Drupal::entityManager()->getFieldDefinitions($entity_type_id, $bundle);
foreach ($bundle_settings['fields'] as $field_name => $translatable) {
$bundle_settings['fields'][$field_name] = $translatable && $bundle_settings['translatable'];
$translatable = $translatable && $bundle_settings['translatable'];
// If we have column settings and no column is translatable, no point
// in making the field translatable.
if (isset($bundle_settings['columns'][$field_name]) && !array_filter($bundle_settings['columns'][$field_name])) {
$bundle_settings['fields'][$field_name] = FALSE;
$translatable = FALSE;
}
// If we have a storable field definition we directly persist any
// change to translatability, otherwise we store changes in our config
// so we can properly alter field definitions later.
// @todo Remove this special casing when any field definition can have
// a configurable bundle override. See
// https://drupal.org/node/2224761.
$definition = $definitions[$field_name];
if ($definition instanceof FieldInstanceConfigInterface) {
if ($definition->isTranslatable() != $translatable) {
$definition->setTranslatable($translatable);
$definition->save();
}
// Do not save configurable fields unnecessarily.
unset($bundle_settings['fields'][$field_name]);
}
}
}
}
}
_content_translation_update_field_translatability($settings);
drupal_set_message(t('Settings successfully updated.'));
}
/**
* Stores content translation settings.
*
* @param array $settings
* An associative array of settings keyed by entity type and bundle. At bundle
* level the following keys are available:
* - translatable: The bundle translatability status, which is a bool.
* - settings: An array of language configuration settings as defined by
* language_save_default_configuration().
* - fields: An associative array with field names as keys and a boolean as
* value, indicating field translatability.
*/
function _content_translation_update_field_translatability($settings) {
// Update translatability for configurable fields.
// @todo Remove this once configurable fields rely on entity field info to
// track translatability. See https://drupal.org/node/2018685.
foreach ($settings as $entity_type => $entity_settings) {
$fields = array();
foreach ($entity_settings as $bundle_settings) {
// Collapse field settings since here we have per instance settings, but
// translatability has per-field scope. We assume that all the field
// instances have the same value.
if (!empty($bundle_settings['fields'])) {
foreach ($bundle_settings['fields'] as $field_name => $translatable) {
// If translatability changes for at least one field instance we need
// to switch field translatability.
$field = FieldConfig::loadByName($entity_type, $field_name);
if ($field && $field->isTranslatable() !== $translatable) {
$fields[$field_name] = $translatable;
}
}
}
}
// Store updated fields.
foreach ($fields as $field_name => $translatable) {
$field = FieldConfig::loadByName($entity_type, $field_name);
$field->translatable = $translatable;
$field->save();
}
}
content_translation_save_settings($settings);
drupal_set_message(t('Settings successfully updated.'));
}

View File

@ -5,16 +5,13 @@
* Allows entities to be translated into different languages.
*/
use Drupal\content_translation\Plugin\Derivative\ContentTranslationLocalTasks;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityFormInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\TranslatableInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\HttpFoundation\Request;
@ -145,23 +142,28 @@ function content_translation_entity_bundle_info_alter(&$bundles) {
}
/**
* Implements hook_entity_base_field_info_alter().
* Implements hook_entity_bundle_field_info_alter().
*
* @todo Remove this when any field supports per-bundle configurable overrides.
* See https://drupal.org/node/2224761.
*/
function content_translation_entity_base_field_info_alter(&$fields, EntityTypeInterface $entity_type) {
$translation_settings = \Drupal::config('content_translation.settings')->get($entity_type->id());
if ($translation_settings) {
// Currently field translatability is defined per-field but we may want to
// make it per-instance instead. In that case, we will need to implement
// hook_bundle_field_info_alter() instead.
$field_settings = array();
foreach ($translation_settings as $settings) {
$field_settings += !empty($settings['content_translation']['fields']) ? $settings['content_translation']['fields'] : array();
}
foreach ($field_settings as $name => $translatable) {
if (isset($fields[$name]) && $fields[$name] instanceof FieldDefinition) {
$fields[$name]->setTranslatable((bool) $translatable);
function content_translation_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
$settings = content_translation_get_config($entity_type->id(), $bundle, 'fields');
if (!empty($settings)) {
$base_field_definitions = \Drupal::entityManager()->getBaseFieldDefinitions($entity_type->id());
foreach ($settings as $name => $translatable) {
// Skip storable field definitions as those are supposed to have already
// been changed.
if (!isset($fields[$name]) || !$fields[$name] instanceof FieldInstanceConfigInterface) {
// If we do not have a bundle definition for the current field and we
// have to override its translatability, we need to instantiate a new
// bundle field definition from the base one.
if (!isset($fields[$name]) && isset($base_field_definitions[$name]) && $base_field_definitions[$name]->isTranslatable() != $translatable) {
$fields[$name] = clone $base_field_definitions[$name];
}
if (isset($fields[$name])) {
$fields[$name]->setTranslatable((bool) $translatable);
}
}
}
}
@ -636,58 +638,37 @@ function content_translation_entity_extra_field_info() {
}
/**
* Implements hook_form_FORM_ID_alter() for 'field_ui_field_edit_form'.
* Implements hook_form_FORM_ID_alter() for 'field_ui_instance_edit_form'.
*/
function content_translation_form_field_ui_field_edit_form_alter(array &$form, array &$form_state, $form_id) {
$field = $form['#field'];
$bundle = $form['#bundle'];
$bundle_is_translatable = content_translation_enabled($field->entity_type, $bundle);
$form['field']['translatable'] = array(
function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, array &$form_state) {
$instance = $form_state['instance'];
$bundle_is_translatable = content_translation_enabled($instance->entity_type, $instance->bundle);
$form['instance']['translatable'] = array(
'#type' => 'checkbox',
'#title' => t('Users may translate this field.'),
'#default_value' => $field->isTranslatable(),
'#weight' => 20,
'#default_value' => $instance->isTranslatable(),
'#weight' => -1,
'#disabled' => !$bundle_is_translatable,
'#access' => $instance->getFieldStorageDefinition()->isTranslatable(),
);
$form['#submit'][] = 'content_translation_form_field_ui_field_edit_form_submit';
// Provide helpful pointers for administrators.
if (\Drupal::currentUser()->hasPermission('administer content translation') && !$bundle_is_translatable) {
$toggle_url = url('admin/config/regional/content-language', array(
'query' => drupal_get_destination(),
));
$form['field']['translatable']['#description'] = t('To enable translation of this field, <a href="@language-settings-url">enable language support</a> for this type.', array(
$form['instance']['translatable']['#description'] = t('To configure translation for this field, <a href="@language-settings-url">enable language support</a> for this type.', array(
'@language-settings-url' => $toggle_url,
));
}
}
/**
* Form submission handler for 'field_ui_field_edit_form'.
*/
function content_translation_form_field_ui_field_edit_form_submit($form, array &$form_state) {
$instance = $form_state['instance'];
$value = content_translation_get_config($instance->entity_type, $instance->bundle, 'fields');
if (!isset($value)) {
$value = array();
}
$value[$instance->getField()->getName()] = $form_state['values']['field']['translatable'];
// Store the same value for all bundles as translatability is tracked per
// field.
foreach (entity_get_bundles($instance->entity_type) as $bundle => $info) {
content_translation_set_config($instance->entity_type, $bundle, 'fields', $value);
}
}
/**
* 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_state['instance']->isTranslatable()) {
if ($instance->isTranslatable()) {
module_load_include('inc', 'content_translation', 'content_translation.admin');
$element = content_translation_field_sync_widget($form_state['instance']);
$element = content_translation_field_sync_widget($instance);
if ($element) {
$form['instance']['settings']['translation_sync'] = $element;
$form['instance']['settings']['translation_sync']['#weight'] = -10;
}
}
}

View File

@ -9,7 +9,7 @@ namespace Drupal\content_translation\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Language\Language;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\simpletest\WebTestBase;
/**
@ -22,7 +22,7 @@ class ContentTranslationSettingsTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('language', 'content_translation', 'node', 'comment', 'field_ui');
public static $modules = array('language', 'content_translation', 'node', 'comment', 'field_ui', 'entity_test');
public static function getInfo() {
return array(
@ -40,6 +40,7 @@ class ContentTranslationSettingsTest extends WebTestBase {
$this->drupalCreateContentType(array('type' => 'article'));
$this->drupalCreateContentType(array('type' => 'page'));
$this->container->get('comment.manager')->addDefaultField('node', 'article', 'comment_article', CommentItemInterface::OPEN, 'comment_article');
$this->container->get('comment.manager')->addDefaultField('node', 'page', 'comment_page');
$admin_user = $this->drupalCreateUser(array('access administration pages', 'administer languages', 'administer content translation', 'administer content types', 'administer node fields', 'administer comment fields', 'administer comments', 'administer comment types'));
$this->drupalLogin($admin_user);
@ -95,8 +96,24 @@ class ContentTranslationSettingsTest extends WebTestBase {
'settings[comment][comment_article][fields][comment_body]' => TRUE,
);
$this->assertSettings('comment', 'comment_article', TRUE, $edit);
$field = FieldConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field->isTranslatable(), 'Comment body is translatable.');
$definition = $this->entityManager()->getFieldDefinitions('comment', 'comment_article')['comment_body'];
$this->assertTrue($definition->isTranslatable(), 'Article comment body is translatable.');
$definition = $this->entityManager()->getFieldDefinitions('comment', 'comment')['comment_body'];
$this->assertFalse($definition->isTranslatable(), 'Page comment body is not translatable.');
$this->assertNull(content_translation_get_config('comment', 'comment_article', 'fields'), 'Configurable fields are not saved to content_translation.settings.');
// Test that translation can be enabled for base fields.
$edit = array(
'entity_types[entity_test_mul]' => TRUE,
'settings[entity_test_mul][entity_test_mul][translatable]' => TRUE,
'settings[entity_test_mul][entity_test_mul][fields][name]' => TRUE,
'settings[entity_test_mul][entity_test_mul][fields][user_id]' => FALSE,
);
$this->assertSettings('entity_test_mul', 'entity_test_mul', TRUE, $edit);
$settings = content_translation_get_config('entity_test_mul', 'entity_test_mul', 'fields');
$this->assertTrue($settings['name'] && !$settings['user_id'], 'Base fields are saved to content_translation.settings.');
$definitions = $this->entityManager()->getFieldDefinitions('entity_test_mul', 'entity_test_mul');
$this->assertTrue($definitions['name']->isTranslatable() && !$definitions['user_id']->isTranslatable(), 'Bundle field definitions were correctly altered.');
// Test that language settings are correctly stored.
$language_configuration = language_get_default_configuration('comment', 'comment_article');
@ -134,20 +151,20 @@ class ContentTranslationSettingsTest extends WebTestBase {
// Test that configurable field translatability is correctly switched.
$edit = array('settings[node][article][fields][body]' => $translatable);
$this->assertSettings('node', 'article', TRUE, $edit);
$field = FieldConfig::loadByName('node', 'body');
$instance = FieldInstanceConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
$this->assertEqual($field->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
$this->assertEqual($instance->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
// Test that also the Field UI form behaves correctly.
$translatable = !$translatable;
$edit = array('field[translatable]' => $translatable);
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body/field', $edit, t('Save field settings'));
$edit = array('instance[translatable]' => $translatable);
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body', $edit, t('Save settings'));
\Drupal::entityManager()->clearCachedFieldDefinitions();
$field = FieldConfig::loadByName('node', 'body');
$instance = FieldInstanceConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
$this->assertEqual($field->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
$this->assertEqual($instance->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
}
}
@ -196,9 +213,9 @@ class ContentTranslationSettingsTest extends WebTestBase {
// Tests that field instance doesn't have translatable setting if bundle
// is not translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.body/field';
$path = 'admin/structure/types/manage/article/fields/node.article.body';
$this->drupalGet($path);
$this->assertText('To enable translation of this field, enable language support for this type.', 'No translatable setting for field.');
$this->assertText('To configure translation for this field, enable language support for this type.', 'No translatable setting for field.');
// Tests that field instance has translatable setting if bundle is
// translatable. Note: this field instance is not translatable when
@ -214,4 +231,14 @@ class ContentTranslationSettingsTest extends WebTestBase {
$this->assertNoText('To enable translation of this field, enable language support for this type.', 'No translatable setting for field.');
}
/**
* Returns the entity manager.
*
* @return \Drupal\Core\Entity\EntityManagerInterface
* The entity manager;
*/
protected function entityManager() {
return $this->container->get('entity.manager');
}
}

View File

@ -29,7 +29,7 @@ class Editor extends PluginBase implements InPlaceEditorInterface {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getCardinality() != 1) {
if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
return FALSE;
}
// This editor is compatible with processed ("rich") text fields; but only

View File

@ -109,12 +109,12 @@ class SelectionBase implements SelectionInterface {
});
foreach ($bundle_fields as $instance_name => $field_definition) {
/* @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
$columns = $field_definition->getColumns();
$columns = $field_definition->getFieldStorageDefinition()->getColumns();
// If there is more than one column, display them all, otherwise just
// display the field label.
// @todo: Use property labels instead of the column name.
if (count($columns) > 1) {
foreach ($field_definition->getColumns() as $column_name => $column_info) {
foreach ($columns as $column_name => $column_info) {
$fields[$instance_name . '.' . $column_name] = t('@label (@column)', array('@label' => $field_definition->getLabel(), '@column' => $column_name));
}
}

View File

@ -7,7 +7,7 @@
namespace Drupal\entity_reference\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
/**
@ -44,7 +44,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
'target_type' => 'node',
),
'type' => 'entity_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_instance_config', array(

View File

@ -7,10 +7,10 @@
namespace Drupal\entity_reference\Tests;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Tests for the entity reference field.
@ -88,7 +88,7 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
$this->referencedEntityType,
'default',
array('target_bundles' => array($this->bundle)),
FieldDefinitionInterface::CARDINALITY_UNLIMITED
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
);
$this->field = FieldConfig::loadByName($this->entityType, $this->fieldName);

View File

@ -76,6 +76,9 @@ field.instance.*.*.*:
required:
type: boolean
label: 'Required field'
translatable:
type: boolean
label: 'Translatable'
default_value:
type: field.[%parent.field_type].value
default_value_function:

View File

@ -98,7 +98,7 @@ function field_purge_batch($batch_size, $field_uuid = NULL) {
);
// Retrieve some entities.
$query = $factory->get($entity_type)
->condition('id:' . $instance->getField()->uuid() . '.deleted', 1)
->condition('id:' . $instance->getFieldStorageDefinition()->uuid() . '.deleted', 1)
->range(0, $batch_size);
// If there's no bundle key, all results will have the same bundle.
if ($bundle_key = $info[$entity_type]->getKey('bundle')) {

View File

@ -111,11 +111,11 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
/**
* Flag indicating whether the field is translatable.
*
* Defaults to FALSE.
* Defaults to TRUE.
*
* @var bool
*/
public $translatable = FALSE;
public $translatable = TRUE;
/**
* Flag indicating whether the field is available for editing.
@ -544,12 +544,7 @@ class FieldConfig extends ConfigEntityBase implements FieldConfigInterface {
}
/**
* Sets whether the field is translatable.
*
* @param bool $translatable
* Whether the field is translatable.
*
* @return $this
* {@inheritdoc}
*/
public function setTranslatable($translatable) {
$this->translatable = $translatable;

View File

@ -120,6 +120,15 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
*/
public $required = FALSE;
/**
* Flag indicating whether the field is translatable.
*
* Defaults to TRUE.
*
* @var bool
*/
public $translatable = TRUE;
/**
* Default field value.
*
@ -264,6 +273,21 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return $this->entity_type . '.' . $this->bundle . '.' . $this->field_name;
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->field_name;
}
/**
* {@inheritdoc}
*/
public function getType() {
return $this->getFieldStorageDefinition()->getType();
}
/**
* {@inheritdoc}
*/
@ -282,7 +306,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
public function postCreate(EntityStorageInterface $storage) {
// Validate that we have a valid field for this instance. This throws an
// exception if the field is invalid.
$field = $this->getField();
$field = $this->getFieldStorageDefinition();
// Make sure the field_uuid is populated.
$this->field_uuid = $field->uuid();
@ -290,7 +314,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
// 'Label' defaults to the field name (mostly useful for field instances
// created in tests).
if (empty($this->label)) {
$this->label = $this->field->name;
$this->label = $this->getName();
}
}
@ -306,7 +330,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
$entity_manager = \Drupal::entityManager();
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$field = $this->getField();
$field = $this->getFieldStorageDefinition();
if ($this->isNew()) {
// Set the default instance settings.
@ -342,7 +366,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
public function calculateDependencies() {
parent::calculateDependencies();
// Manage dependencies.
$this->addDependency('entity', $this->getField()->getConfigDependencyName());
$this->addDependency('entity', $this->getFieldStorageDefinition()->getConfigDependencyName());
$bundle_entity_type_id = \Drupal::entityManager()->getDefinition($this->entity_type)->getBundleEntityType();
if ($bundle_entity_type_id != 'bundle') {
// If the target entity type uses entities to manage its bundles then
@ -362,7 +386,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
// Invalidate the render cache for all affected entities.
$entity_manager = \Drupal::entityManager();
$entity_type = $this->getTargetEntityTypeId();
$entity_type = $this->getFieldStorageDefinition()->getTargetEntityTypeId();
if ($entity_manager->hasController($entity_type, 'view_builder')) {
$entity_manager->getViewBuilder($entity_type)->resetCache();
}
@ -413,7 +437,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
// Delete fields that have no more instances.
$fields_to_delete = array();
foreach ($instances as $instance) {
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
if (!$instance->deleted && empty($instance->noFieldDelete) && !$instance->isUninstalling() && count($field->getBundles()) == 0) {
// Key by field UUID to avoid deleting the same field twice.
$fields_to_delete[$instance->field_uuid] = $field;
@ -450,7 +474,7 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
/**
* {@inheritdoc}
*/
public function getField() {
public function getFieldStorageDefinition() {
if (!$this->field) {
$fields = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type);
if (!isset($fields[$this->field_name])) {
@ -465,25 +489,11 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return $this->field;
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->field_name;
}
/**
* {@inheritdoc}
*/
public function getType() {
return $this->getField()->getType();
}
/**
* {@inheritdoc}
*/
public function getSettings() {
return $this->settings + $this->getField()->getSettings();
return $this->settings + $this->getFieldStorageDefinition()->getSettings();
}
/**
@ -494,29 +504,24 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return $this->settings[$setting_name];
}
else {
return $this->getField()->getSetting($setting_name);
return $this->getFieldStorageDefinition()->getSetting($setting_name);
}
}
/**
* {@inheritdoc}
*/
public function getProvider() {
return $this->getField()->getProvider();
}
/**
* {@inheritdoc}
*/
public function isTranslatable() {
return $this->getField()->translatable;
// A field can be enabled for translation only if translation is supported.
return $this->translatable && $this->getFieldStorageDefinition()->isTranslatable();
}
/**
* {@inheritdoc}
*/
public function isRevisionable() {
return $this->getField()->isRevisionable();
public function setTranslatable($translatable) {
$this->translatable = $translatable;
return $this;
}
/**
@ -560,13 +565,6 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return $this->description;
}
/**
* {@inheritdoc}
*/
public function getCardinality() {
return $this->getField()->cardinality;
}
/**
* {@inheritdoc}
*/
@ -574,13 +572,6 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return $this->required;
}
/**
* {@inheritdoc}
*/
public function isMultiple() {
return $this->getField()->isMultiple();
}
/**
* {@inheritdoc}
*/
@ -612,20 +603,6 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return array('type' => 'hidden');
}
/**
* {@inheritdoc}
*/
public function getTargetEntityTypeId() {
return $this->entity_type;
}
/**
* {@inheritdoc}
*/
public function isQueryable() {
return TRUE;
}
/**
* {@inheritdoc}
*/
@ -743,55 +720,6 @@ class FieldInstanceConfig extends ConfigEntityBase implements FieldInstanceConfi
return $this->itemDefinition;
}
/**
* {@inheritdoc}
*/
public function getPropertyDefinition($name) {
return $this->getField()->getPropertyDefinition($name);
}
/**
* {@inheritdoc}
*/
public function getPropertyDefinitions() {
return $this->getField()->getPropertyDefinitions();
}
/**
* {@inheritdoc}
*/
public function getPropertyNames() {
return $this->getField()->getPropertyNames();
}
/**
* {@inheritdoc}
*/
public function getMainPropertyName() {
return $this->getField()->getMainPropertyName();
}
/**
* {@inheritdoc}
*/
public function getSchema() {
return $this->getField()->getSchema();
}
/**
* {@inheritdoc}
*/
public function getColumns() {
return $this->getField()->getColumns();
}
/**
* {@inheritdoc}
*/
public function hasCustomStorage() {
return $this->getField()->hasCustomStorage();
}
/**
* {@inheritdoc}
*/

View File

@ -20,7 +20,7 @@ class FieldInstanceConfigAccessController extends EntityAccessController {
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
if ($operation == 'delete' && $entity->getField()->isLocked()) {
if ($operation == 'delete' && $entity->getFieldStorageDefinition()->isLocked()) {
return FALSE;
}
return $account->hasPermission('administer ' . $entity->entity_type . ' fields');

View File

@ -21,7 +21,7 @@ interface FieldInstanceConfigInterface extends ConfigEntityInterface, FieldDefin
* @return \Drupal\field\FieldConfigInterface
* The field entity for this instance.
*/
public function getField();
public function getFieldStorageDefinition();
/**
* Allows a bundle to be renamed.

View File

@ -132,7 +132,7 @@ class FieldInstanceConfigStorage extends ConfigEntityStorage {
$matching_instances = array();
foreach ($instances as $instance) {
// Some conditions are checked against the field.
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
// Only keep the instance if it matches all conditions.
foreach ($conditions as $key => $value) {

View File

@ -8,21 +8,21 @@
namespace Drupal\field\Plugin\views\field;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FormatterPluginManager;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManager;
use Drupal\Core\Render\Element;
use Drupal\Core\Session\AccountInterface;
use Drupal\views\Views;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@ -181,8 +181,8 @@ class Field extends FieldPluginBase {
$this->limit_values = FALSE;
$field_definition = $this->getFieldDefinition();
$cardinality = $field_definition->getCardinality();
if ($field_definition->isMultiple()) {
$cardinality = $field_definition->getFieldStorageDefinition()->getCardinality();
if ($field_definition->getFieldStorageDefinition()->isMultiple()) {
$this->multiple = TRUE;
// If "Display all values in the same row" is FALSE, then we always limit
@ -534,7 +534,7 @@ class Field extends FieldPluginBase {
// translating prefix and suffix separately.
list($prefix, $suffix) = explode('@count', t('Display @count value(s)'));
if ($field->getCardinality() == FieldDefinitionInterface::CARDINALITY_UNLIMITED) {
if ($field->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) {
$type = 'textfield';
$options = NULL;
$size = 5;
@ -904,8 +904,8 @@ class Field extends FieldPluginBase {
$default_langcode = language_default()->id;
$langcode = str_replace(
array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
array($this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT), $default_langcode),
$this->view->display_handler->options['field_language']
array($this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id, $default_langcode),
$this->view->display_handler->options['field_langcode']
);
// Give the Entity Field API a chance to fallback to a different language

View File

@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
@ -55,7 +56,7 @@ class ConfigFieldDefinitionTest extends FieldUnitTestBase {
public function testBundleFieldDefinition() {
$definitions = $this->entityManager->getFieldDefinitions($this->entityType, $this->bundle);
$this->assertTrue(isset($definitions[$this->instance->getName()]));
$this->assertTrue($definitions[$this->instance->getName()] instanceof FieldStorageDefinitionInterface);
$this->assertTrue($definitions[$this->instance->getName()] instanceof FieldDefinitionInterface);
// Make sure no field for the instance on another entity type is exposed.
$this->assertFalse(isset($definitions[$this->instance_rev->getName()]));
}

View File

@ -8,7 +8,7 @@
namespace Drupal\field\Tests;
use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests field form handling.
@ -79,7 +79,7 @@ class FormTest extends FieldTestBase {
'name' => 'field_unlimited',
'entity_type' => 'entity_test',
'type' => 'test_field',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
);
$this->instance = array(

View File

@ -6,8 +6,7 @@
*/
namespace Drupal\field\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests field elements in nested forms.
@ -44,7 +43,7 @@ class NestedFormTest extends FieldTestBase {
'name' => 'field_unlimited',
'entity_type' => 'entity_test',
'type' => 'test_field',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
);
$this->instance = array(

View File

@ -7,7 +7,7 @@
namespace Drupal\field\Tests\Views;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
@ -52,7 +52,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
'name' => 'field_name_3',
'entity_type' => 'node',
'type' => 'text',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
));
$field->save();
// Setup a field that will have no value.
@ -60,7 +60,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
'name' => 'field_name_4',
'entity_type' => 'node',
'type' => 'text',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
));
$field->save();

View File

@ -116,7 +116,7 @@ class FieldOverview extends OverviewBase {
// Fields.
foreach ($instances as $name => $instance) {
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
$route_parameters = array(
$this->bundleEntityType => $this->bundle,
'field_instance_config' => $instance->id(),
@ -211,7 +211,7 @@ class FieldOverview extends OverviewBase {
// contrib modules can form_alter() the value for newly created fields.
'translatable' => array(
'#type' => 'value',
'#value' => FALSE,
'#value' => TRUE,
),
);
}
@ -381,6 +381,8 @@ class FieldOverview extends OverviewBase {
'entity_type' => $this->entity_type,
'bundle' => $this->bundle,
'label' => $values['label'],
// Field translatability should be explicitly enabled by the users.
'translatable' => FALSE,
);
// Create the field and instance.
@ -513,7 +515,7 @@ class FieldOverview extends OverviewBase {
// - locked fields,
// - fields that should not be added via user interface.
$field_type = $instance->getType();
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
if (empty($field->locked) && empty($field_types[$field_type]['no_ui'])) {
$options[$instance->getName()] = array(
'type' => $field_type,

View File

@ -8,6 +8,7 @@
namespace Drupal\field_ui\Form;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Form\FormBase;
use Drupal\Core\TypedData\TypedDataManager;
use Drupal\field\FieldInstanceConfigInterface;
@ -77,7 +78,7 @@ class FieldEditForm extends FormBase {
$this->instance = $form_state['instance'] = $field_instance_config;
$form['#title'] = $this->instance->label();
$field = $this->instance->getField();
$field = $this->instance->getFieldStorageDefinition();
$form['#field'] = $field;
$form['#bundle'] = $this->instance->bundle;
@ -114,13 +115,13 @@ class FieldEditForm extends FormBase {
'#title_display' => 'invisible',
'#options' => array(
'number' => $this->t('Limited'),
FieldInstanceConfigInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited'),
FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited'),
),
'#default_value' => ($cardinality == FieldInstanceConfigInterface::CARDINALITY_UNLIMITED) ? FieldInstanceConfigInterface::CARDINALITY_UNLIMITED : 'number',
'#default_value' => ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 'number',
);
$form['field']['cardinality_container']['cardinality_number'] = array(
'#type' => 'number',
'#default_value' => $cardinality != FieldInstanceConfigInterface::CARDINALITY_UNLIMITED ? $cardinality : 1,
'#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : 1,
'#min' => 1,
'#title' => $this->t('Limit'),
'#title_display' => 'invisible',
@ -136,6 +137,7 @@ class FieldEditForm extends FormBase {
$form['field']['field_name'] = array('#type' => 'value', '#value' => $field->getName());
$form['field']['type'] = array('#type' => 'value', '#value' => $field->getType());
$form['field']['module'] = array('#type' => 'value', '#value' => $field->module);
$form['field']['translatable'] = array('#type' => 'value', '#value' => $field->isTranslatable());
// Add settings provided by the field module. The field module is
// responsible for not returning settings that cannot be changed if
@ -185,7 +187,7 @@ class FieldEditForm extends FormBase {
unset($field_values['container']);
// Merge incoming form values into the existing field.
$field = $this->instance->getField();
$field = $this->instance->getFieldStorageDefinition();
foreach ($field_values as $key => $value) {
$field->{$key} = $value;
}

View File

@ -68,7 +68,7 @@ class FieldInstanceConfigDeleteForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function submit(array $form, array &$form_state) {
$field = $this->entity->getField();
$field = $this->entity->getFieldStorageDefinition();
$bundles = entity_get_bundles();
$bundle_label = $bundles[$this->entity->entity_type][$this->entity->bundle]['label'];

View File

@ -67,7 +67,7 @@ class FieldInstanceEditForm extends FormBase {
$bundle = $this->instance->bundle;
$entity_type = $this->instance->entity_type;
$field = $this->instance->getField();
$field = $this->instance->getFieldStorageDefinition();
$bundles = entity_get_bundles();
$form_title = $this->t('%instance settings for %bundle', array(

View File

@ -7,9 +7,9 @@
namespace Drupal\field_ui\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldInstanceConfig;
@ -212,12 +212,12 @@ class ManageFieldsTest extends FieldUiTestBase {
// Set to unlimited.
$edit = array(
'field[cardinality]' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'field[cardinality]' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
);
$this->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
$this->assertText('Updated field Body field settings.');
$this->drupalGet($field_edit_path);
$this->assertFieldByXPath("//select[@name='field[cardinality]']", FieldDefinitionInterface::CARDINALITY_UNLIMITED);
$this->assertFieldByXPath("//select[@name='field[cardinality]']", FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->assertFieldByXPath("//input[@name='field[cardinality_number]']", 1);
}

View File

@ -215,7 +215,7 @@ function template_preprocess_file_upload_help(&$variables) {
* fid, FALSE if it does not.
*/
function file_field_find_file_reference_column(FieldDefinitionInterface $field) {
$schema = $field->getSchema();
$schema = $field->getFieldStorageDefinition()->getSchema();
foreach ($schema['foreign keys'] as $data) {
if ($data['table'] == 'file_managed') {
foreach ($data['columns'] as $field_column => $column) {

View File

@ -8,10 +8,10 @@
namespace Drupal\file\Plugin\Field\FieldWidget;
use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Render\Element;
/**
@ -82,9 +82,9 @@ class FileWidget extends WidgetBase {
}
// Determine the number of widgets to display.
$cardinality = $this->fieldDefinition->getCardinality();
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
switch ($cardinality) {
case FieldDefinitionInterface::CARDINALITY_UNLIMITED:
case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
$max = count($items);
$is_multiple = TRUE;
break;
@ -131,7 +131,7 @@ class FileWidget extends WidgetBase {
}
$empty_single_allowed = ($cardinality == 1 && $delta == 0);
$empty_multiple_allowed = ($cardinality == FieldDefinitionInterface::CARDINALITY_UNLIMITED || $delta < $cardinality) && empty($form_state['programmed']);
$empty_multiple_allowed = ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || $delta < $cardinality) && empty($form_state['programmed']);
// Add one more empty row for new uploads except when this is a programmed
// multiple form as it is not necessary.
@ -198,7 +198,7 @@ class FileWidget extends WidgetBase {
'description_field' => NULL,
);
$cardinality = $this->fieldDefinition->getCardinality();
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
$defaults = array(
'fids' => array(),
'display' => (bool) $field_settings['display_default'],

View File

@ -7,7 +7,7 @@
namespace Drupal\file\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests that formatters are working properly.
@ -31,7 +31,7 @@ class FileFieldDisplayTest extends FileFieldTestBase {
$field_settings = array(
'display_field' => '1',
'display_default' => '1',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
);
$instance_settings = array(
'description_field' => '1',

View File

@ -7,7 +7,7 @@
namespace Drupal\file\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldInstanceConfig;
/**
@ -54,7 +54,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// Try again with a multiple value field.
$field->delete();
$this->createFileField($field_name, 'node', $type_name, array('cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED), array('required' => '1'));
$this->createFileField($field_name, 'node', $type_name, array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), array('required' => '1'));
// Try to post a new node without uploading a file in the multivalue field.
$edit = array();

View File

@ -7,9 +7,9 @@
namespace Drupal\file\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\FieldUnitTestBase;
/**
@ -49,7 +49,7 @@ class FileItemTest extends FieldUnitTestBase {
'name' => 'file_test',
'entity_type' => 'entity_test',
'type' => 'file',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'entity_test',

View File

@ -85,12 +85,12 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
'name' => 'field_test_text',
'entity_type' => 'entity_test',
'type' => 'text',
'translatable' => FALSE,
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_text',
'bundle' => 'entity_test',
'translatable' => FALSE,
))->save();
// Create the test translatable field.
@ -98,12 +98,12 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
'name' => 'field_test_translatable_text',
'entity_type' => 'entity_test',
'type' => 'text',
'translatable' => TRUE,
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_translatable_text',
'bundle' => 'entity_test',
'translatable' => TRUE,
))->save();
// Create the test entity reference field.
@ -111,7 +111,6 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
'name' => 'field_test_entity_reference',
'entity_type' => 'entity_test',
'type' => 'entity_reference',
'translatable' => TRUE,
'settings' => array(
'target_type' => 'entity_test',
),
@ -120,6 +119,7 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
'entity_type' => 'entity_test',
'field_name' => 'field_test_entity_reference',
'bundle' => 'entity_test',
'translatable' => TRUE,
))->save();
$entity_manager = \Drupal::entityManager();

View File

@ -361,7 +361,7 @@ function image_entity_presave(EntityInterface $entity) {
$field = FALSE;
$entity_type_id = $entity->getEntityTypeId();
if ($entity_type_id == 'field_instance_config') {
$field = $entity->getField();
$field = $entity->getFieldStorageDefinition();
$default_settings = \Drupal::service('plugin.manager.field.field_type')->getDefaultInstanceSettings('image');
}
elseif ($entity_type_id == 'field_config') {
@ -440,7 +440,7 @@ function image_field_config_update(FieldConfigInterface $field) {
* Implements hook_ENTITY_TYPE_update() for 'field_instance_config'.
*/
function image_field_instance_config_update(FieldInstanceConfigInterface $field_instance) {
$field = $field_instance->getField();
$field = $field_instance->getFieldStorageDefinition();
if ($field->type != 'image') {
// Only act on image fields.
return;
@ -494,7 +494,7 @@ function image_field_config_delete(FieldConfigInterface $field) {
* Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'.
*/
function image_field_instance_config_delete(FieldInstanceConfigInterface $field_instance) {
$field = $field_instance->getField();
$field = $field_instance->getFieldStorageDefinition();
if ($field->type != 'image') {
// Only act on image fields.
return;

View File

@ -29,7 +29,7 @@ abstract class ImageFormatterBase extends FileFormatterBase {
// If we are dealing with a configurable field, look in both
// instance-level and field-level settings.
if (empty($default_image['fid']) && $this->fieldDefinition instanceof FieldInstanceConfigInterface) {
$default_image = $this->fieldDefinition->getField()->getSetting('default_image');
$default_image = $this->fieldDefinition->getFieldStorageDefinition()->getSetting('default_image');
}
if (!empty($default_image['fid']) && ($file = file_load($default_image['fid']))) {

View File

@ -158,7 +158,7 @@ class ImageItem extends FileItem {
// We need the field-level 'default_image' setting, and $this->getSettings()
// will only provide the instance-level one, so we need to explicitly fetch
// the field.
$settings = $this->getFieldDefinition()->getField()->getSettings();
$settings = $this->getFieldDefinition()->getFieldStorageDefinition()->getSettings();
$scheme_options = array();
foreach (file_get_stream_wrappers(STREAM_WRAPPERS_WRITE_VISIBLE) as $scheme => $stream_wrapper) {

View File

@ -85,7 +85,7 @@ class ImageWidget extends FileWidget {
protected function formMultipleElements(FieldItemListInterface $items, array &$form, array &$form_state) {
$elements = parent::formMultipleElements($items, $form, $form_state);
$cardinality = $this->fieldDefinition->getCardinality();
$cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
$file_upload_help = array(
'#theme' => 'file_upload_help',
'#description' => '',

View File

@ -77,7 +77,7 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
$instance_field_settings = $instance->getSettings();
$this->assertEqual($instance_field_settings['default_image']['fid'], $default_images['instance']->id());
$field = $instance->getField();
$field = $instance->getFieldStorageDefinition();
// The field default image id should be 1.
$default_image = $field->getSetting('default_image');

View File

@ -7,7 +7,7 @@
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
/**
@ -236,7 +236,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
$field_name . '[0][title]' => $this->randomName($test_size),
);
$this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
$schema = $instance->getField()->getSchema();
$schema = $instance->getFieldStorageDefinition()->getSchema();
$this->assertRaw(t('Alternate text cannot be longer than %max characters but is currently %length characters long.', array(
'%max' => $schema['columns']['alt']['length'],
'%length' => $test_size,
@ -253,7 +253,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
// 1, so we need to make sure the file widget prevents these notices by
// providing all settings, even if they are not used.
// @see FileWidget::formMultipleElements().
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/field', array('field[cardinality]' => FieldDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/field', array('field[cardinality]' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
$edit = array();
$edit['files[' . $field_name . '_1][]'] = drupal_realpath($test_image->uri);
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));

View File

@ -7,9 +7,9 @@
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\FieldUnitTestBase;
/**
@ -54,7 +54,7 @@ class ImageItemTest extends FieldUnitTestBase {
'name' => 'image_test',
'entity_type' => 'entity_test',
'type' => 'image',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'entity_test',

View File

@ -7,7 +7,7 @@
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
/**
@ -49,7 +49,7 @@ class ImageThemeFunctionTest extends WebTestBase {
'name' => 'image_test',
'entity_type' => 'entity_test',
'type' => 'image',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_instance_config', array(
'entity_type' => 'entity_test',

View File

@ -103,7 +103,7 @@ class LinkWidget extends WidgetBase {
// If cardinality is 1, ensure a label is output for the field by wrapping it
// in a details element.
if ($this->fieldDefinition->getCardinality() == 1) {
if ($this->fieldDefinition->getFieldStorageDefinition()->getCardinality() == 1) {
$element += array(
'#type' => 'fieldset',
);

View File

@ -133,7 +133,8 @@ function node_access_test_entity_base_field_info(EntityTypeInterface $entity_typ
if ($entity_type->id() === 'node') {
$fields['private'] = FieldDefinition::create('boolean')
->setLabel(t('Private'))
->setComputed(TRUE);
->setComputed(TRUE)
->setCustomStorage(TRUE);
return $fields;
}

View File

@ -47,7 +47,7 @@ abstract class OptionsWidgetBase extends WidgetBase {
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings);
$property_names = $this->fieldDefinition->getPropertyNames();
$property_names = $this->fieldDefinition->getFieldStorageDefinition()->getPropertyNames();
$this->column = $property_names[0];
}
@ -58,7 +58,7 @@ abstract class OptionsWidgetBase extends WidgetBase {
// Prepare some properties for the child methods to build the actual form
// element.
$this->required = $element['#required'];
$this->multiple = $this->fieldDefinition->isMultiple();
$this->multiple = $this->fieldDefinition->getFieldStorageDefinition()->isMultiple();
$this->has_value = isset($items[0]->{$this->column});
// Add our custom validator.

View File

@ -61,9 +61,6 @@ class PathLanguageTest extends PathTestBase {
// Enable translation for page node.
$edit = array(
'entity_types[node]' => 1,
'settings[node][article][translatable]' => 1,
'settings[node][article][fields][path]' => 1,
'settings[node][article][fields][body]' => 1,
'settings[node][page][translatable]' => 1,
'settings[node][page][fields][path]' => 1,
'settings[node][page][fields][body]' => 1,
@ -71,8 +68,9 @@ class PathLanguageTest extends PathTestBase {
);
$this->drupalPostForm('admin/config/regional/content-language', $edit, t('Save'));
$field = FieldConfig::loadByName('node', 'body');
$this->assertTrue($field->isTranslatable(), 'Node body is translatable.');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'page');
$this->assertTrue($definitions['path']->isTranslatable(), 'Node path is translatable.');
$this->assertTrue($definitions['body']->isTranslatable(), 'Node body is translatable.');
}
/**
@ -81,7 +79,6 @@ class PathLanguageTest extends PathTestBase {
function testAliasTranslation() {
$english_node = $this->drupalCreateNode(array('type' => 'page', 'langcode' => 'en'));
$english_alias = $this->randomName();
$translatable = !$english_node->isNew() && $english_node->isTranslatable() && count($english_node->getTranslationLanguages()) > 1 && ($field = $english_node->getFieldDefinition('status')) && $field->isTranslatable();
// Edit the node to set language and path.
$edit = array();
@ -101,7 +98,7 @@ class PathLanguageTest extends PathTestBase {
$edit['body[0][value]'] = $this->randomName();
$french_alias = $this->randomName();
$edit['path[0][alias]'] = $french_alias;
$this->drupalPostForm(NULL, $edit, t('Save') . ' ' . ($translatable ? t('(this translation)') : t('(all translations)')));
$this->drupalPostForm(NULL, $edit, t('Save (this translation)'));
// Clear the path lookup cache.
$this->container->get('path.alias_manager')->cacheClear();

View File

@ -29,7 +29,7 @@ class PlainTextEditor extends InPlaceEditorBase {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getCardinality() != 1) {
if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
return FALSE;
}
// This editor is incompatible with processed ("rich") text fields.

View File

@ -8,7 +8,7 @@
namespace Drupal\quickedit\Tests;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\simpletest\WebTestBase;
@ -85,7 +85,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
// Set cardinality to unlimited for tagging.
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -27,7 +27,7 @@ class WysiwygEditor extends InPlaceEditorBase {
$field_definition = $items->getFieldDefinition();
// This editor is incompatible with multivalued fields.
if ($field_definition->getCardinality() != 1) {
if ($field_definition->getFieldStorageDefinition()->getCardinality() != 1) {
return FALSE;
}
// This editor is compatible with processed ("rich") text fields; but only

View File

@ -6,6 +6,7 @@
namespace Drupal\rdf\Tests\Field;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\rdf\Tests\Field\FieldRdfaTestBase;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
@ -63,7 +64,7 @@ class TaxonomyTermReferenceRdfaTest extends FieldRdfaTestBase {
'name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -7,7 +7,7 @@
namespace Drupal\rdf\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
/**
@ -159,7 +159,7 @@ class TaxonomyTermFieldAttributesTest extends TaxonomyTestBase {
'name' => $field_name,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -203,7 +203,8 @@ class Shortcut extends ContentEntityBase implements ShortcutInterface {
$fields['path'] = FieldDefinition::create('string')
->setLabel(t('Path'))
->setDescription(t('The computed shortcut path.'))
->setComputed(TRUE);
->setComputed(TRUE)
->setCustomStorage(TRUE);
$item_definition = $fields['path']->getItemDefinition();
$item_definition->setClass('\Drupal\shortcut\ShortcutPathItem');

View File

@ -7,7 +7,7 @@
namespace Drupal\system\Tests\Ajax;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests Ajax-enabled forms functionality with multiple instances of the form.
@ -40,7 +40,7 @@ class MultiFormTest extends AjaxTestBase {
'name' => $field_name,
'entity_type' => 'node',
'type' => 'text',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save();
entity_create('field_instance_config', array(
'field_name' => $field_name,

View File

@ -11,7 +11,7 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\EventSubscriber\HtmlViewSubscriber;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\system\Tests\Cache\PageCacheTagsTestBase;
/**
@ -162,7 +162,7 @@ abstract class EntityCacheTagsTestBase extends PageCacheTagsTestBase {
'name' => $field_name,
'entity_type' => $entity_type,
'type' => 'entity_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'target_type' => $referenced_entity->getEntityTypeId(),
),

View File

@ -399,7 +399,7 @@ class EntityFieldTest extends EntityUnitTestBase {
$this->assertEqual($userref_properties['target_id']->getDataType(), 'integer', $entity_type .': Entity id property of the user found.');
$this->assertEqual($userref_properties['entity']->getDataType(), 'entity_reference', $entity_type .': Entity reference property of the user found.');
$textfield_properties = $entity->field_test_text->getFieldDefinition()->getPropertyDefinitions();
$textfield_properties = $entity->field_test_text->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinitions();
$this->assertEqual($textfield_properties['value']->getDataType(), 'string', $entity_type .': String value property of the test-text field found.');
$this->assertEqual($textfield_properties['format']->getDataType(), 'filter_format', $entity_type .': String format field of the test-text field found.');
$this->assertEqual($textfield_properties['processed']->getDataType(), 'string', $entity_type .': String processed property of the test-text field found.');

View File

@ -8,7 +8,7 @@
namespace Drupal\system\Tests\Entity;
use Drupal\Core\Language\Language;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldInstanceConfig;
/**
* Base class for language-aware entity tests.
@ -75,12 +75,12 @@ abstract class EntityLanguageTestBase extends EntityUnitTestBase {
'entity_type' => $entity_type,
'type' => 'text',
'cardinality' => 4,
'translatable' => TRUE,
))->save();
entity_create('field_instance_config', array(
'field_name' => $this->field_name,
'entity_type' => $entity_type,
'bundle' => $entity_type,
'translatable' => TRUE,
))->save();
$this->instance[$entity_type] = entity_load('field_instance_config', $entity_type . '.' . $entity_type . '.' . $this->field_name);
@ -89,12 +89,12 @@ abstract class EntityLanguageTestBase extends EntityUnitTestBase {
'entity_type' => $entity_type,
'type' => 'text',
'cardinality' => 4,
'translatable' => FALSE,
))->save();
entity_create('field_instance_config', array(
'field_name' => $this->untranslatable_field_name,
'entity_type' => $entity_type,
'bundle' => $entity_type,
'translatable' => FALSE,
))->save();
}
@ -124,15 +124,15 @@ abstract class EntityLanguageTestBase extends EntityUnitTestBase {
* @param string $entity_type
* The type of the entity fields are attached to.
*/
protected function toggleFieldTranslatability($entity_type) {
protected function toggleFieldTranslatability($entity_type, $bundle) {
$fields = array($this->field_name, $this->untranslatable_field_name);
foreach ($fields as $field_name) {
$field = FieldConfig::loadByName($entity_type, $field_name);
$translatable = !$field->isTranslatable();
$field->set('translatable', $translatable);
$field->save();
$field = FieldConfig::loadByName($entity_type, $field_name);
$this->assertEqual($field->isTranslatable(), $translatable, 'Field translatability changed.');
$instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name);
$translatable = !$instance->isTranslatable();
$instance->set('translatable', $translatable);
$instance->save();
$instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name);
$this->assertEqual($instance->isTranslatable(), $translatable, 'Field translatability changed.');
}
\Drupal::cache('entity')->deleteAll();
}

View File

@ -55,7 +55,7 @@ class FieldTranslationSqlStorageTest extends EntityLanguageTestBase {
// Test that after switching field translatability things keep working as
// before.
$this->toggleFieldTranslatability($entity_type);
$this->toggleFieldTranslatability($entity_type, $entity_type);
$entity = $this->reloadEntity($entity);
foreach (array($this->field_name, $this->untranslatable_field_name) as $field_name) {
$this->assertEqual($entity->get($field_name)->value, $values[$field_name], 'Field language works as expected after switching translatability.');
@ -63,14 +63,14 @@ class FieldTranslationSqlStorageTest extends EntityLanguageTestBase {
// Test that after disabling field translatability translated values are not
// loaded.
$this->toggleFieldTranslatability($entity_type);
$this->toggleFieldTranslatability($entity_type, $entity_type);
$entity = $this->reloadEntity($entity);
$entity->langcode->value = $this->langcodes[0];
$translation = $entity->addTranslation($this->langcodes[1]);
$translated_value = $this->randomName();
$translation->get($this->field_name)->value = $translated_value;
$translation->save();
$this->toggleFieldTranslatability($entity_type);
$this->toggleFieldTranslatability($entity_type, $entity_type);
$entity = $this->reloadEntity($entity);
$this->assertEqual($entity->getTranslation($this->langcodes[1])->get($this->field_name)->value, $values[$this->field_name], 'Existing field translations are not loaded for untranslatable fields.');
}

View File

@ -7,7 +7,7 @@
namespace Drupal\system\Tests\Form;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
/**
@ -76,7 +76,7 @@ class RebuildTest extends WebTestBase {
'name' => $field_name,
'entity_type' => 'node',
'type' => 'text',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
);
entity_create('field_config', $field)->save();
$instance = array(

View File

@ -22,13 +22,13 @@ function entity_test_install() {
'entity_type' => $entity_type,
'type' => 'text',
'cardinality' => 1,
'translatable' => FALSE,
))->save();
entity_create('field_instance_config', array(
'entity_type' => $entity_type,
'field_name' => 'field_test_text',
'bundle' => $entity_type,
'label' => 'Test text-field',
'translatable' => FALSE,
))->save();
entity_get_form_display($entity_type, $entity_type, 'default')

View File

@ -11,8 +11,6 @@ use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\taxonomy\TermInterface;
/**
@ -163,7 +161,7 @@ class Term extends ContentEntityBase implements TermInterface {
$fields['parent'] = FieldDefinition::create('integer')
->setLabel(t('Term Parents'))
->setDescription(t('The parents of this term.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setCardinality(FieldDefinition::CARDINALITY_UNLIMITED)
// Save new terms with no parents by default.
->setDefaultValue(0)
->setSetting('unsigned', TRUE)

View File

@ -8,7 +8,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Test for legacy node bug.
@ -45,7 +45,7 @@ class LegacyTest extends TaxonomyTestBase {
'name' => $field_name,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -7,7 +7,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests the rendering of term reference fields in RSS feeds.
@ -41,7 +41,7 @@ class RssTest extends TaxonomyTestBase {
'name' => $this->field_name,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -7,9 +7,9 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\FieldUnitTestBase;
@ -55,7 +55,7 @@ class TaxonomyTermReferenceItemTest extends FieldUnitTestBase {
'name' => 'field_test_taxonomy',
'entity_type' => 'entity_test',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -7,7 +7,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
/**
@ -47,7 +47,7 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase {
'name' => $this->field_name,
'entity_type' => 'entity_test',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests the hook implementations that maintain the taxonomy index.
@ -37,7 +38,7 @@ class TermIndexTest extends TaxonomyTestBase {
'name' => $this->field_name_1,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(
@ -68,7 +69,7 @@ class TermIndexTest extends TaxonomyTestBase {
'name' => $this->field_name_2,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -8,9 +8,9 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Tags;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
/**
@ -37,7 +37,7 @@ class TermTest extends TaxonomyTestBase {
'name' => $field_name,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -7,9 +7,9 @@
namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Test taxonomy token replacement in strings.
@ -34,7 +34,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
'name' => $this->field_name,
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -7,7 +7,7 @@
namespace Drupal\taxonomy\Tests\Views;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
@ -83,7 +83,7 @@ abstract class TaxonomyTestBase extends ViewTestBase {
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
// Set cardinality to unlimited for tagging.
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -8,11 +8,10 @@
namespace Drupal\user\Entity;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\user\UserInterface;
/**
@ -530,7 +529,7 @@ class User extends ContentEntityBase implements UserInterface {
$fields['roles'] = FieldDefinition::create('string')
->setCustomStorage(TRUE)
->setLabel(t('Roles'))
->setCardinality(FieldDefinitionInterface::CARDINALITY_UNLIMITED)
->setCardinality(FieldDefinition::CARDINALITY_UNLIMITED)
->setDescription(t('The roles the user has.'));
return $fields;

View File

@ -7,7 +7,7 @@
namespace Drupal\user\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\simpletest\WebTestBase;
/**
@ -253,7 +253,7 @@ class UserRegistrationTest extends WebTestBase {
$this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correclty saved.');
// Check that the 'add more' button works.
$field->cardinality = FieldDefinitionInterface::CARDINALITY_UNLIMITED;
$field->cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
$field->save();
foreach (array('js', 'nojs') as $js) {
$this->drupalGet('user/register');

View File

@ -180,11 +180,11 @@ abstract class DisplayPluginBase extends PluginBase {
$this->unpackOptions($this->options, $options);
}
// Convert the field_language and field_language_add_to_query settings.
$field_language = $this->getOption('field_language');
// Convert the field_langcode and field_language_add_to_query settings.
$field_langcode = $this->getOption('field_langcode');
$field_language_add_to_query = $this->getOption('field_language_add_to_query');
if (isset($field_langcode)) {
$this->setOption('field_langcode', $field_language);
$this->setOption('field_langcode', $field_langcode);
$this->setOption('field_langcode_add_to_query', $field_language_add_to_query);
$changed = TRUE;
}
@ -1950,7 +1950,7 @@ abstract class DisplayPluginBase extends PluginBase {
case 'group_by':
$this->setOption($section, $form_state['values'][$section]);
break;
case 'field_language':
case 'field_langcode':
$this->setOption('field_langcode', $form_state['values']['field_langcode']);
$this->setOption('field_langcode_add_to_query', $form_state['values']['field_langcode_add_to_query']);
break;

View File

@ -7,7 +7,7 @@
namespace Drupal\views\Tests\Wizard;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
/**
* Tests the ability of the views wizard to create views filtered by taxonomy.
@ -59,7 +59,7 @@ class TaggedWithTest extends WizardTestBase {
'name' => 'field_views_testing_tags',
'entity_type' => 'node',
'type' => 'taxonomy_term_reference',
'cardinality' => FieldDefinitionInterface::CARDINALITY_UNLIMITED,
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'allowed_values' => array(
array(

View File

@ -248,7 +248,7 @@ class ContentEntityDatabaseStorageTest extends UnitTestCase {
),
);
$this->fieldDefinitions['id'] = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$this->fieldDefinitions['id'] = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
$this->fieldDefinitions['id']->expects($this->once())
->method('getColumns')
->will($this->returnValue($columns));
@ -366,7 +366,7 @@ class ContentEntityDatabaseStorageTest extends UnitTestCase {
$base_field_names = array('title', 'description', 'owner');
$field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names);
$definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
$this->fieldDefinitions = array_fill_keys($field_names, $definition);
$this->entityType->expects($this->any())
@ -502,11 +502,11 @@ class ContentEntityDatabaseStorageTest extends UnitTestCase {
$base_field_names = array('title');
$field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names);
$definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
$this->fieldDefinitions = array_fill_keys($field_names, $definition);
$revisionable_field_names = array('description', 'owner');
$definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
// isRevisionable() is only called once, but we re-use the same definition
// for all revisionable fields.
$definition->expects($this->any())
@ -627,7 +627,7 @@ class ContentEntityDatabaseStorageTest extends UnitTestCase {
$base_field_names = array('title', 'description', 'owner');
$field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names);
$definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
$this->fieldDefinitions = array_fill_keys($field_names, $definition);
$this->entityType->expects($this->exactly(2))
@ -809,11 +809,11 @@ class ContentEntityDatabaseStorageTest extends UnitTestCase {
$base_field_names = array('title');
$field_names = array_merge(array_values(array_filter($entity_keys)), $base_field_names);
$definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
$this->fieldDefinitions = array_fill_keys($field_names, $definition);
$revisionable_field_names = array('description', 'owner');
$definition = $this->getMock('Drupal\Core\Field\FieldDefinitionInterface');
$definition = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');
// isRevisionable() is only called once, but we re-use the same definition
// for all revisionable fields.
$definition->expects($this->any())

View File

@ -9,7 +9,7 @@ namespace Drupal\Tests\Core\Entity;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\UnitTestCase;
/**
@ -192,8 +192,8 @@ class FieldDefinitionTest extends UnitTestCase {
$this->assertEquals(1, $definition->getCardinality());
$definition->setCardinality(2);
$this->assertEquals(2, $definition->getCardinality());
$definition->setCardinality(FieldDefinitionInterface::CARDINALITY_UNLIMITED);
$this->assertEquals(FieldDefinitionInterface::CARDINALITY_UNLIMITED, $definition->getCardinality());
$definition->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->assertEquals(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, $definition->getCardinality());
}
/**

View File

@ -788,7 +788,7 @@ class ContentEntitySchemaHandlerTest extends UnitTestCase {
* The field name.
* @param array $schema
* The schema array of the field definition, as returned from
* FieldDefinitionInterface::schema().
* FieldStorageDefinitionInterface::getSchema().
*/
public function setUpStorageDefinition($field_name, array $schema) {
$this->storageDefinitions[$field_name] = $this->getMock('Drupal\Core\Field\FieldStorageDefinitionInterface');