diff -u b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php --- b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -960,7 +960,7 @@ $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(); } } } @@ -1030,7 +1030,7 @@ if (!($instance instanceof FieldInstanceConfigInterface)) { continue; } - $field = $instance->getField(); + $field = $instance->getFieldStorageDefinition(); $table_name = static::_fieldTableName($field); $revision_name = static::_fieldRevisionTableName($field); @@ -1107,7 +1107,7 @@ 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) @@ -1129,7 +1129,7 @@ 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) @@ -1260,7 +1260,7 @@ * {@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) @@ -1282,7 +1282,7 @@ // 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) @@ -1300,7 +1300,7 @@ * {@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()) @@ -1315,7 +1315,7 @@ * {@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) diff -u b/core/lib/Drupal/Core/Field/FieldDefinition.php b/core/lib/Drupal/Core/Field/FieldDefinition.php --- b/core/lib/Drupal/Core/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Field/FieldDefinition.php @@ -594,2 +594,9 @@ + /** + * {@inheritdoc} + */ + public function getFieldStorageDefinition() { + return $this; + } + } diff -u b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php --- b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php +++ b/core/lib/Drupal/Core/Field/FieldDefinitionInterface.php @@ -57,2 +57,23 @@ /** + * 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. @@ -149,2 +170,9 @@ + /** + * Returns the field storage definition. + * + * @return \Drupal\Core\Field\FieldStorageDefinitionInterface + * The field storage definition. + */ + public function getFieldStorageDefinition(); } diff -u b/core/lib/Drupal/Core/Field/FieldItemList.php b/core/lib/Drupal/Core/Field/FieldItemList.php --- b/core/lib/Drupal/Core/Field/FieldItemList.php +++ b/core/lib/Drupal/Core/Field/FieldItemList.php @@ -285,7 +285,7 @@ // 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(); + $cardinality = $this->getFieldDefinition()->getFieldStorageDefinition()->getCardinality(); if ($cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) { $constraints[] = \Drupal::typedDataManager() ->getValidationConstraintManager() diff -u b/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php --- b/core/lib/Drupal/Core/Field/WidgetBase.php +++ b/core/lib/Drupal/Core/Field/WidgetBase.php @@ -137,7 +137,7 @@ */ 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. @@ -193,7 +193,7 @@ '#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, diff -u b/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module --- b/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -642,7 +642,7 @@ '#default_value' => $instance->isTranslatable(), '#weight' => -1, '#disabled' => !$bundle_is_translatable, - '#access' => $instance->getField()->isTranslatable(), + '#access' => $instance->getFieldStorageDefinition()->isTranslatable(), ); // Provide helpful pointers for administrators. diff -u b/core/modules/field/src/Entity/FieldInstanceConfig.php b/core/modules/field/src/Entity/FieldInstanceConfig.php --- b/core/modules/field/src/Entity/FieldInstanceConfig.php +++ b/core/modules/field/src/Entity/FieldInstanceConfig.php @@ -276,6 +276,21 @@ /** * {@inheritdoc} */ + public function getName() { + return $this->field_name; + } + + /** + * {@inheritdoc} + */ + public function getType() { + return $this->getFieldStorageDefinition()->getType(); + } + + + /** + * {@inheritdoc} + */ public function toArray() { $properties = parent::toArray(); // Additionally, include the field type, that is needed to be able to @@ -291,7 +306,7 @@ 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(); @@ -299,7 +314,7 @@ // '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(); } } @@ -315,7 +330,7 @@ $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. @@ -351,7 +366,7 @@ 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 @@ -371,7 +386,7 @@ // 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(); } @@ -422,7 +437,7 @@ // 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; @@ -459,7 +474,7 @@ /** * {@inheritdoc} */ - public function getField() { + public function getFieldStorageDefinition() { if (!$this->field) { $fields = \Drupal::entityManager()->getFieldStorageDefinitions($this->entity_type); if (!isset($fields[$this->field_name])) { @@ -477,22 +492,8 @@ /** * {@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(); } /** @@ -503,23 +504,16 @@ 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() { // A field can be enabled for translation only if translation is supported. - return $this->translatable && $this->getField()->isTranslatable(); + return $this->translatable && $this->getFieldStorageDefinition()->isTranslatable(); } /** @@ -534,7 +527,0 @@ - * {@inheritdoc} - */ - public function isRevisionable() { - return $this->getField()->isRevisionable(); - } - - /** @@ -581,13 +568,6 @@ /** * {@inheritdoc} */ - public function getCardinality() { - return $this->getField()->cardinality; - } - - /** - * {@inheritdoc} - */ public function isRequired() { return $this->required; } @@ -595,13 +575,6 @@ /** * {@inheritdoc} */ - public function isMultiple() { - return $this->getField()->isMultiple(); - } - - /** - * {@inheritdoc} - */ public function getDefaultValue(ContentEntityInterface $entity) { // Allow custom default values function. if ($function = $this->default_value_function) { @@ -633,20 +606,6 @@ /** * {@inheritdoc} */ - public function getTargetEntityTypeId() { - return $this->entity_type; - } - - /** - * {@inheritdoc} - */ - public function isQueryable() { - return TRUE; - } - - /** - * {@inheritdoc} - */ public function allowBundleRename() { $this->bundle_rename_allowed = TRUE; } @@ -764,55 +723,6 @@ /** * {@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} - */ public function isDeleted() { return $this->deleted; } diff -u b/core/modules/field_ui/src/FieldOverview.php b/core/modules/field_ui/src/FieldOverview.php --- b/core/modules/field_ui/src/FieldOverview.php +++ b/core/modules/field_ui/src/FieldOverview.php @@ -116,7 +116,7 @@ // Fields. foreach ($instances as $name => $instance) { - $field = $instance->getField(); + $field = $instance->getFieldStorageDefinition(); $route_parameters = array( $this->bundleEntityType => $this->bundle, 'field_instance_config' => $instance->id(), @@ -515,7 +515,7 @@ // - 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, diff -u b/core/modules/field_ui/src/Form/FieldEditForm.php b/core/modules/field_ui/src/Form/FieldEditForm.php --- b/core/modules/field_ui/src/Form/FieldEditForm.php +++ b/core/modules/field_ui/src/Form/FieldEditForm.php @@ -78,7 +78,7 @@ $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; @@ -187,7 +187,7 @@ 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; } diff -u b/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php --- b/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -236,7 +236,7 @@ $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, only in patch2: unchanged: --- a/core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php +++ b/core/lib/Drupal/Core/Field/TypedData/FieldItemDataDefinition.php @@ -61,21 +61,21 @@ public static function create($field_definition) { * {@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(); } } only in patch2: unchanged: --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -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')) { only in patch2: unchanged: --- a/core/modules/field/src/FieldInstanceConfigInterface.php +++ b/core/modules/field/src/FieldInstanceConfigInterface.php @@ -21,7 +21,7 @@ * @return \Drupal\field\FieldConfigInterface * The field entity for this instance. */ - public function getField(); + public function getFieldStorageDefinition(); /** * Allows a bundle to be renamed. only in patch2: unchanged: --- a/core/modules/field/src/FieldInstanceConfigStorage.php +++ b/core/modules/field/src/FieldInstanceConfigStorage.php @@ -132,7 +132,7 @@ public function loadByProperties(array $conditions = array()) { $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) { only in patch2: unchanged: --- a/core/modules/field_ui/src/Form/FieldInstanceEditForm.php +++ b/core/modules/field_ui/src/Form/FieldInstanceEditForm.php @@ -67,7 +67,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceConfigIn $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( only in patch2: unchanged: --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -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; only in patch2: unchanged: --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -77,7 +77,7 @@ public function testDefaultImages() { $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'); only in patch2: unchanged: --- a/core/modules/options/src/Plugin/Field/FieldWidget/OptionsWidgetBase.php +++ b/core/modules/options/src/Plugin/Field/FieldWidget/OptionsWidgetBase.php @@ -47,7 +47,7 @@ */ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings); - $property_names = $this->fieldDefinition->getPropertyNames(); + $property_names = $this->fieldDefinition->getFieldStorageDefinition()->getPropertyNames(); $this->column = $property_names[0]; } @@ -58,7 +58,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // 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. only in patch2: unchanged: --- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php @@ -399,7 +399,7 @@ protected function checkIntrospection($entity_type) { $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.');