Issue #2312093 by alexpott, yched, andypost, swentel | xjm: Rename FieldInstanceConfig to FieldConfig.

8.0.x
webchick 2014-09-19 19:45:52 -07:00
parent 7fa6684f7f
commit 1476c56c62
306 changed files with 2270 additions and 2329 deletions

View File

@ -374,7 +374,7 @@ field_config_base:
type: string type: string
label: 'Default value function' label: 'Default value function'
settings: settings:
type: field.[%parent.field_type].instance_settings type: field.[%parent.field_type].field_settings
third_party_settings: third_party_settings:
type: sequence type: sequence
label: 'Third party settings' label: 'Third party settings'
@ -410,7 +410,7 @@ core.date_format.*:
# Schema for the String field type. # Schema for the String field type.
field.string.instance_settings: field.string.field_settings:
type: sequence type: sequence
label: 'String settings' label: 'String settings'
sequence: sequence:
@ -430,7 +430,7 @@ field.string.value:
# Schema for the configuration files of the Boolean field type. # Schema for the configuration files of the Boolean field type.
field.boolean.settings: field.boolean.storage_settings:
type: mapping type: mapping
label: 'Boolean settings' label: 'Boolean settings'
mapping: mapping:
@ -441,7 +441,7 @@ field.boolean.settings:
type: string type: string
label: 'Off label' label: 'Off label'
field.boolean.instance_settings: field.boolean.field_settings:
label: 'Boolean settings' label: 'Boolean settings'
type: mapping type: mapping
mapping: { } mapping: { }
@ -459,13 +459,13 @@ field.boolean.value:
# Schema for the configuration files of the Email field type. # Schema for the configuration files of the Email field type.
field.email.settings: field.email.storage_settings:
type: sequence type: sequence
label: 'Email settings' label: 'Email settings'
sequence: sequence:
- type: string - type: string
field.email.instance_settings: field.email.field_settings:
type: sequence type: sequence
label: 'Email settings' label: 'Email settings'
sequence: sequence:
@ -485,14 +485,14 @@ field.email.value:
# Schema for configuration files of a numeric field types. # Schema for configuration files of a numeric field types.
field.integer.settings: field.integer.storage_settings:
type: sequence type: sequence
label: 'Integer settings' label: 'Integer settings'
sequence: sequence:
- type: string - type: string
label: 'setting' label: 'setting'
field.integer.instance_settings: field.integer.field_settings:
type: mapping type: mapping
label: 'Integer' label: 'Integer'
mapping: mapping:
@ -520,7 +520,7 @@ field.integer.value:
type: integer type: integer
label: 'Value' label: 'Value'
field.decimal.settings: field.decimal.storage_settings:
type: mapping type: mapping
label: 'Decimal settings' label: 'Decimal settings'
mapping: mapping:
@ -531,7 +531,7 @@ field.decimal.settings:
type: integer type: integer
label: 'Scale' label: 'Scale'
field.decimal.instance_settings: field.decimal.field_settings:
type: mapping type: mapping
label: 'Decimal' label: 'Decimal'
mapping: mapping:
@ -559,14 +559,14 @@ field.decimal.value:
type: float type: float
label: 'Value' label: 'Value'
field.float.settings: field.float.storage_settings:
type: sequence type: sequence
label: 'Float settings' label: 'Float settings'
sequence: sequence:
- type: string - type: string
label: 'setting' label: 'setting'
field.float.instance_settings: field.float.field_settings:
type: mapping type: mapping
label: 'Float' label: 'Float'
mapping: mapping:

View File

@ -822,7 +822,7 @@ class ConfigImporter {
// result of a secondary configuration write. Change the operation // result of a secondary configuration write. Change the operation
// into an update. This is the desired behavior since renames often // into an update. This is the desired behavior since renames often
// have to occur together. For example, renaming a node type must // have to occur together. For example, renaming a node type must
// also result in renaming its field instances and entity displays. // also result in renaming its fields and entity displays.
$this->storageComparer->moveRenameToUpdate($name); $this->storageComparer->moveRenameToUpdate($name);
return FALSE; return FALSE;
} }

View File

@ -215,8 +215,8 @@ class ConfigManager implements ConfigManagerInterface {
// dependencies on the to-be-removed entities. // dependencies on the to-be-removed entities.
$extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name)); $extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
// Reverse the array to that entities are removed in the correct order of // Reverse the array to that entities are removed in the correct order of
// dependence. For example, this ensures that field instances are removed // dependence. For example, this ensures that fields are removed before
// before fields. // field storages.
foreach (array_reverse($extension_dependent_entities) as $extension_dependent_entity) { foreach (array_reverse($extension_dependent_entities) as $extension_dependent_entity) {
$extension_dependent_entity->setUninstalling(TRUE); $extension_dependent_entity->setUninstalling(TRUE);
$extension_dependent_entity->delete(); $extension_dependent_entity->delete();

View File

@ -16,8 +16,8 @@ use Drupal\Component\Utility\SortArray;
* Configuration entities can depend on modules, themes and other configuration * Configuration entities can depend on modules, themes and other configuration
* entities. The dependency system is used during configuration installation to * entities. The dependency system is used during configuration installation to
* ensure that configuration entities are imported in the correct order. For * ensure that configuration entities are imported in the correct order. For
* example, node types are created before their fields and the fields are * example, node types are created before their field storages and the field
* created before their field instances. * storages are created before their fields.
* *
* Dependencies are stored to the configuration entity's configuration object so * Dependencies are stored to the configuration entity's configuration object so
* that they can be checked without the module that provides the configuration * that they can be checked without the module that provides the configuration

View File

@ -219,8 +219,8 @@ class StorageComparer implements StorageComparerInterface {
* Creates the delete changelist. * Creates the delete changelist.
* *
* The list of deletes is sorted so that dependencies are deleted after * The list of deletes is sorted so that dependencies are deleted after
* configuration entities that depend on them. For example, field instances * configuration entities that depend on them. For example, fields should be
* should be deleted after fields. * deleted after field storages.
* *
* @param string $collection * @param string $collection
* The storage collection to operate on. * The storage collection to operate on.
@ -234,8 +234,8 @@ class StorageComparer implements StorageComparerInterface {
* Creates the create changelist. * Creates the create changelist.
* *
* The list of creates is sorted so that dependencies are created before * The list of creates is sorted so that dependencies are created before
* configuration entities that depend on them. For example, fields * configuration entities that depend on them. For example, field storages
* should be created before field instances. * should be created before fields.
* *
* @param string $collection * @param string $collection
* The storage collection to operate on. * The storage collection to operate on.
@ -249,8 +249,8 @@ class StorageComparer implements StorageComparerInterface {
* Creates the update changelist. * Creates the update changelist.
* *
* The list of updates is sorted so that dependencies are created before * The list of updates is sorted so that dependencies are created before
* configuration entities that depend on them. For example, fields * configuration entities that depend on them. For example, field storages
* should be updated before field instances. * should be updated before fields.
* *
* @param string $collection * @param string $collection
* The storage collection to operate on. * The storage collection to operate on.

View File

@ -10,8 +10,6 @@ namespace Drupal\Core\Entity;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Cache\Cache;
use Drupal\field\FieldInstanceConfigInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class ContentEntityStorageBase extends EntityStorageBase implements FieldableEntityStorageInterface { abstract class ContentEntityStorageBase extends EntityStorageBase implements FieldableEntityStorageInterface {
@ -137,7 +135,7 @@ abstract class ContentEntityStorageBase extends EntityStorageBase implements Fie
* Reads values to be purged for a single field. * Reads values to be purged for a single field.
* *
* This method is called during field data purge, on fields for which * This method is called during field data purge, on fields for which
* onFieldDelete() or onFieldInstanceDelete() has previously run. * onFieldDelete() or onFieldDelete() has previously run.
* *
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The field definition. * The field definition.

View File

@ -64,7 +64,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
* // One sub-array per copy of the widget, keyed by delta. * // One sub-array per copy of the widget, keyed by delta.
* 0 => array( * 0 => array(
* '#title' => The title to be displayed by the widget, * '#title' => The title to be displayed by the widget,
* '#description' => The description text for the field instance, * '#description' => The description text for the field,
* '#required' => Whether the widget should be marked required, * '#required' => Whether the widget should be marked required,
* '#delta' => 0, * '#delta' => 0,
* '#weight' => 0, * '#weight' => 0,

View File

@ -11,8 +11,8 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ThirdPartySettingsTrait; use Drupal\Core\Config\Entity\ThirdPartySettingsTrait;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface;
/** /**
* Provides a common base class for entity view and form displays. * Provides a common base class for entity view and form displays.
@ -171,9 +171,9 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
// Create dependencies on both hidden and visible fields. // Create dependencies on both hidden and visible fields.
$fields = $this->content + $this->hidden; $fields = $this->content + $this->hidden;
foreach ($fields as $field_name => $component) { foreach ($fields as $field_name => $component) {
$field_instance = FieldInstanceConfig::loadByName($this->targetEntityType, $this->bundle, $field_name); $field = FieldConfig::loadByName($this->targetEntityType, $this->bundle, $field_name);
if ($field_instance) { if ($field) {
$this->addDependency('entity', $field_instance->getConfigDependencyName()); $this->addDependency('entity', $field->getConfigDependencyName());
} }
// Create a dependency on the module that provides the formatter or // Create a dependency on the module that provides the formatter or
// widget. // widget.
@ -373,7 +373,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
* Determines if a field has options for a given display. * Determines if a field has options for a given display.
* *
* @param FieldDefinitionInterface $definition * @param FieldDefinitionInterface $definition
* A field instance definition. * A field definition.
* @return array|null * @return array|null
*/ */
private function fieldHasDisplayOptions(FieldDefinitionInterface $definition) { private function fieldHasDisplayOptions(FieldDefinitionInterface $definition) {
@ -388,7 +388,7 @@ abstract class EntityDisplayBase extends ConfigEntityBase implements EntityDispl
public function onDependencyRemoval(array $dependencies) { public function onDependencyRemoval(array $dependencies) {
$changed = FALSE; $changed = FALSE;
foreach ($dependencies['entity'] as $entity) { foreach ($dependencies['entity'] as $entity) {
if ($entity instanceof FieldInstanceConfigInterface) { if ($entity instanceof FieldConfigInterface) {
// Remove components for fields that are being deleted. // Remove components for fields that are being deleted.
$this->removeComponent($entity->getName()); $this->removeComponent($entity->getName());
unset($this->hidden[$entity->getName()]); unset($this->hidden[$entity->getName()]);

View File

@ -109,7 +109,7 @@ interface EntityViewBuilderInterface {
* @param array $display_options * @param array $display_options
* Can be either: * Can be either:
* - The name of a view mode. The field will be displayed according to the * - The name of a view mode. The field will be displayed according to the
* display settings specified for this view mode in the $instance * display settings specified for this view mode in the $field
* definition for the field in the entity's bundle. If no display settings * definition for the field in the entity's bundle. If no display settings
* are found for the view mode, the settings for the 'default' view mode * are found for the view mode, the settings for the 'default' view mode
* will be used. * will be used.

View File

@ -1554,7 +1554,7 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
// configurable fields, so we use the specific API. // configurable fields, so we use the specific API.
// @todo Use the unified store of deleted field definitions instead in // @todo Use the unified store of deleted field definitions instead in
// https://www.drupal.org/node/2282119 // https://www.drupal.org/node/2282119
$field_definitions += entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $this->entityTypeId, 'bundle' => $bundle, 'deleted' => TRUE, 'include_deleted' => TRUE)); $field_definitions += entity_load_multiple_by_properties('field_config', array('entity_type' => $this->entityTypeId, 'bundle' => $bundle, 'deleted' => TRUE, 'include_deleted' => TRUE));
$table_mapping = $this->getTableMapping(); $table_mapping = $this->getTableMapping();
foreach ($field_definitions as $field_definition) { foreach ($field_definitions as $field_definition) {

View File

@ -939,8 +939,8 @@ class ModuleHandler implements ModuleHandlerInterface {
$entity_manager = \Drupal::entityManager(); $entity_manager = \Drupal::entityManager();
foreach ($module_list as $module) { foreach ($module_list as $module) {
// Clean up all entity bundles (including field instances) of every entity // Clean up all entity bundles (including fields) of every entity type
// type provided by the module that is being uninstalled. // provided by the module that is being uninstalled.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) { foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type->getProvider() == $module) { if ($entity_type->getProvider() == $module) {
foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) { foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) {

View File

@ -76,7 +76,7 @@ class FieldWidget extends Plugin {
/** /**
* An integer to determine the weight of this widget relative to other widgets * An integer to determine the weight of this widget relative to other widgets
* in the Field UI when selecting a widget for a given field instance. * in the Field UI when selecting a widget for a given field.
* *
* @var int optional * @var int optional
*/ */

View File

@ -62,7 +62,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
// settings for the field type. // settings for the field type.
// @todo Cleanup in https://drupal.org/node/2116341. // @todo Cleanup in https://drupal.org/node/2116341.
$field_type_manager = \Drupal::service('plugin.manager.field.field_type'); $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$default_settings = $field_type_manager->getDefaultSettings($type) + $field_type_manager->getDefaultInstanceSettings($type); $default_settings = $field_type_manager->getDefaultStorageSettings($type) + $field_type_manager->getDefaultFieldSettings($type);
$field_definition->itemDefinition->setSettings($default_settings); $field_definition->itemDefinition->setSettings($default_settings);
return $field_definition; return $field_definition;
} }

View File

@ -155,7 +155,7 @@ class BaseFieldOverride extends FieldConfigBase {
*/ */
public function preSave(EntityStorageInterface $storage) { public function preSave(EntityStorageInterface $storage) {
// Set the default instance settings. // Set the default instance settings.
$this->settings += \Drupal::service('plugin.manager.field.field_type')->getDefaultInstanceSettings($this->getType()); $this->settings += \Drupal::service('plugin.manager.field.field_type')->getDefaultFieldSettings($this->getType());
// Call the parent's presave method to perform validate and calculate // Call the parent's presave method to perform validate and calculate
// dependencies. // dependencies.

View File

@ -21,7 +21,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
use ThirdPartySettingsTrait; use ThirdPartySettingsTrait;
/** /**
* The instance ID. * The field ID.
* *
* The ID consists of 3 parts: the entity type, bundle and the field name. * The ID consists of 3 parts: the entity type, bundle and the field name.
* *
@ -32,7 +32,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
public $id; public $id;
/** /**
* The name of the field attached to the bundle by this instance. * The name of the field attached to the bundle by this field.
* *
* @var string * @var string
*/ */
@ -52,38 +52,38 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
public $field_type; public $field_type;
/** /**
* The name of the entity type the instance is attached to. * The name of the entity type the field is attached to.
* *
* @var string * @var string
*/ */
public $entity_type; public $entity_type;
/** /**
* The name of the bundle the instance is attached to. * The name of the bundle the field is attached to.
* *
* @var string * @var string
*/ */
public $bundle; public $bundle;
/** /**
* The human-readable label for the instance. * The human-readable label for the field.
* *
* This will be used as the title of Form API elements for the field in entity * This will be used as the title of Form API elements for the field in entity
* edit forms, or as the label for the field values in displayed entities. * edit forms, or as the label for the field values in displayed entities.
* *
* If not specified, this defaults to the field_name (mostly useful for field * If not specified, this defaults to the field_name (mostly useful for fields
* instances created in tests). * created in tests).
* *
* @var string * @var string
*/ */
public $label; public $label;
/** /**
* The instance description. * The field description.
* *
* A human-readable description for the field when used with this bundle. * A human-readable description for the field when used with this bundle.
* For example, the description will be the help text of Form API elements for * For example, the description will be the help text of Form API elements for
* this instance in entity edit forms. * this field in entity edit forms.
* *
* @var string * @var string
*/ */

View File

@ -18,7 +18,7 @@ use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
* to ensure that implementations have the expected save() method. * to ensure that implementations have the expected save() method.
* *
* @see \Drupal\Core\Field\Entity\BaseFieldOverride * @see \Drupal\Core\Field\Entity\BaseFieldOverride
* @see \Drupal\field\Entity\FieldInstanceConfig * @see \Drupal\field\Entity\FieldConfig
*/ */
interface FieldConfigInterface extends FieldDefinitionInterface, ConfigEntityInterface, ThirdPartySettingsInterface { interface FieldConfigInterface extends FieldDefinitionInterface, ConfigEntityInterface, ThirdPartySettingsInterface {
@ -52,10 +52,10 @@ interface FieldConfigInterface extends FieldDefinitionInterface, ConfigEntityInt
public function allowBundleRename(); public function allowBundleRename();
/** /**
* Returns the name of the bundle this field instance is attached to. * Returns the name of the bundle this field is attached to.
* *
* @return string * @return string
* The name of the bundle this field instance is attached to. * The name of the bundle this field is attached to.
*/ */
public function targetBundle(); public function targetBundle();

View File

@ -28,7 +28,7 @@ abstract class FieldConfigStorageBase extends ConfigEntityStorage {
protected function mapFromStorageRecords(array $records) { protected function mapFromStorageRecords(array $records) {
foreach ($records as &$record) { foreach ($records as &$record) {
$class = $this->fieldTypeManager->getPluginClass($record['field_type']); $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
$record['settings'] = $class::instanceSettingsFromConfigData($record['settings']); $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
} }
return parent::mapFromStorageRecords($records); return parent::mapFromStorageRecords($records);
} }
@ -39,7 +39,7 @@ abstract class FieldConfigStorageBase extends ConfigEntityStorage {
protected function mapToStorageRecord(EntityInterface $entity) { protected function mapToStorageRecord(EntityInterface $entity) {
$record = parent::mapToStorageRecord($entity); $record = parent::mapToStorageRecord($entity);
$class = $this->fieldTypeManager->getPluginClass($record['field_type']); $class = $this->fieldTypeManager->getPluginClass($record['field_type']);
$record['settings'] = $class::instanceSettingsToConfigData($record['settings']); $record['settings'] = $class::fieldSettingsFromConfigData($record['settings']);
return $record; return $record;
} }

View File

@ -28,16 +28,16 @@ use Drupal\Core\TypedData\ListDataDefinitionInterface;
* information comes from. For example, field.module provides an implementation * information comes from. For example, field.module provides an implementation
* based on two levels of configuration. It allows the site administrator to add * based on two levels of configuration. It allows the site administrator to add
* custom fields to any entity type and bundle via the "field_storage_config" * custom fields to any entity type and bundle via the "field_storage_config"
* and "field_instance_config" configuration entities. The former for storing * and "field_config" configuration entities. The former for storing
* configuration that is independent of which entity type and bundle the field * configuration that is independent of which entity type and bundle the field
* is added to, and the latter for storing configuration that is specific to the * is added to, and the latter for storing configuration that is specific to the
* entity type and bundle. The class that implements "field_instance_config" * entity type and bundle. The class that implements "field_config"
* configuration entities also implements this interface, returning information * configuration entities also implements this interface, returning information
* from either itself, or from the corresponding "field_storage_config" * from either itself, or from the corresponding "field_storage_config"
* configuration, as appropriate. * configuration, as appropriate.
* *
* However, entity base fields, such as $node->title, are not managed by * However, entity base fields, such as $node->title, are not managed by
* field.module and its "field_storage_config"/"field_instance_config" * field.module and its "field_storage_config"/"field_config"
* configuration entities. Therefore, their definitions are provided by * configuration entities. Therefore, their definitions are provided by
* different objects based on the class \Drupal\Core\Field\BaseFieldDefinition, * different objects based on the class \Drupal\Core\Field\BaseFieldDefinition,
* which implements this interface as well. * which implements this interface as well.

View File

@ -28,14 +28,14 @@ abstract class FieldItemBase extends Map implements FieldItemInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array(); return array();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultInstanceSettings() { public static function defaultFieldSettings() {
return array(); return array();
} }
@ -250,42 +250,42 @@ abstract class FieldItemBase extends Map implements FieldItemInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
return array(); return array();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function instanceSettingsForm(array $form, FormStateInterface $form_state) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
return array(); return array();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function settingsToConfigData(array $settings) { public static function storageSettingsToConfigData(array $settings) {
return $settings; return $settings;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function settingsFromConfigData(array $settings) { public static function storageSettingsFromConfigData(array $settings) {
return $settings; return $settings;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function instanceSettingsToConfigData(array $settings) { public static function fieldSettingsToConfigData(array $settings) {
return $settings; return $settings;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function instanceSettingsFromConfigData(array $settings) { public static function fieldSettingsFromConfigData(array $settings) {
return $settings; return $settings;
} }

View File

@ -55,7 +55,7 @@ interface FieldItemInterface extends ComplexDataInterface {
* *
* This method is static because the field schema information is needed on * This method is static because the field schema information is needed on
* creation of the field. FieldItemInterface objects instantiated at that * creation of the field. FieldItemInterface objects instantiated at that
* time are not reliable as field instance settings might be missing. * time are not reliable as field settings might be missing.
* *
* Computed fields having no schema should return an empty array. * Computed fields having no schema should return an empty array.
* *
@ -230,21 +230,21 @@ interface FieldItemInterface extends ComplexDataInterface {
*/ */
public static function generateSampleValue(FieldDefinitionInterface $field_definition); public static function generateSampleValue(FieldDefinitionInterface $field_definition);
/**
* Defines the storage-level settings for this plugin.
*
* @return array
* A list of default settings, keyed by the setting name.
*/
public static function defaultStorageSettings();
/** /**
* Defines the field-level settings for this plugin. * Defines the field-level settings for this plugin.
* *
* @return array * @return array
* A list of default settings, keyed by the setting name. * A list of default settings, keyed by the setting name.
*/ */
public static function defaultSettings(); public static function defaultFieldSettings();
/**
* Defines the instance-level settings for this plugin.
*
* @return array
* A list of default settings, keyed by the setting name.
*/
public static function defaultInstanceSettings();
/** /**
* Returns a settings array that can be stored as a configuration value. * Returns a settings array that can be stored as a configuration value.
@ -278,12 +278,12 @@ interface FieldItemInterface extends ComplexDataInterface {
* *
* @see \Drupal\Core\Config\Config::set() * @see \Drupal\Core\Config\Config::set()
*/ */
public static function settingsToConfigData(array $settings); public static function storageSettingsToConfigData(array $settings);
/** /**
* Returns a settings array in the field type's canonical representation. * Returns a settings array in the field type's canonical representation.
* *
* This function does the inverse of static::settingsToConfigData(). It's * This function does the inverse of static::storageSettingsToConfigData(). It's
* called when loading a field's settings from a configuration object. * called when loading a field's settings from a configuration object.
* *
* @param array $settings * @param array $settings
@ -293,58 +293,56 @@ interface FieldItemInterface extends ComplexDataInterface {
* The settings, in the representation expected by the field type and code * The settings, in the representation expected by the field type and code
* that interacts with it. * that interacts with it.
* *
* @see \Drupal\Core\Field\FieldItemInterface::settingsToConfigData() * @see \Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData()
*/ */
public static function settingsFromConfigData(array $settings); public static function storageSettingsFromConfigData(array $settings);
/** /**
* Returns a settings array that can be stored as a configuration value. * Returns a settings array that can be stored as a configuration value.
* *
* Same as static::settingsToConfigData(), but for the field's instance * Same as static::storageSettingsToConfigData(), but for the field's settings.
* settings.
* *
* @param array $settings * @param array $settings
* The field's instance settings in the field type's canonical * The field's settings in the field type's canonical representation.
* representation.
* *
* @return array * @return array
* An array (either the unmodified $settings or a modified representation) * An array (either the unmodified $settings or a modified representation)
* that is suitable for storing as a deployable configuration value. * that is suitable for storing as a deployable configuration value.
* *
* @see \Drupal\Core\Field\FieldItemInterface::settingsToConfigData() * @see \Drupal\Core\Field\FieldItemInterface::storageSettingsToConfigData()
*/ */
public static function instanceSettingsToConfigData(array $settings); public static function fieldSettingsToConfigData(array $settings);
/** /**
* Returns a settings array in the field type's canonical representation. * Returns a settings array in the field type's canonical representation.
* *
* This function does the inverse of static::instanceSettingsToConfigData(). * This function does the inverse of static::fieldSettingsToConfigData().
* It's called when loading a field's instance settings from a configuration * It's called when loading a field's settings from a configuration
* object. * object.
* *
* @param array $settings * @param array $settings
* The field's instance settings, as it is stored within a configuration * The field's settings, as it is stored within a configuration
* object. * object.
* *
* @return array * @return array
* The instance settings, in the representation expected by the field type * The field settings, in the representation expected by the field type
* and code that interacts with it. * and code that interacts with it.
* *
* @see \Drupal\Core\Field\FieldItemInterface::instanceSettingsToConfigData() * @see \Drupal\Core\Field\FieldItemInterface::fieldSettingsToConfigData()
*/ */
public static function instanceSettingsFromConfigData(array $settings); public static function fieldSettingsFromConfigData(array $settings);
/** /**
* Returns a form for the field-level settings. * Returns a form for the storage-level settings.
* *
* Invoked from \Drupal\field_ui\Form\FieldStorageEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldStorageEditForm to allow
* administrators to configure field-level settings. * administrators to configure storage-level settings.
* *
* Field storage might reject field definition changes that affect the field * Field storage might reject settings changes that affect the field
* storage schema if the field already has data. When the $has_data parameter * storage schema if the storage already has data. When the $has_data
* is TRUE, the form should not allow changing the settings that take part in * parameter is TRUE, the form should not allow changing the settings that
* the schema() method. It is recommended to set #access to FALSE on the * take part in the schema() method. It is recommended to set #access to
* corresponding elements. * FALSE on the corresponding elements.
* *
* @param array $form * @param array $form
* The form where the settings form is being included in. * The form where the settings form is being included in.
@ -356,13 +354,13 @@ interface FieldItemInterface extends ComplexDataInterface {
* @return * @return
* The form definition for the field settings. * The form definition for the field settings.
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data); public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data);
/** /**
* Returns a form for the instance-level settings. * Returns a form for the field-level settings.
* *
* Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure instance-level settings. * administrators to configure field-level settings.
* *
* @param array $form * @param array $form
* The form where the settings form is being included in. * The form where the settings form is being included in.
@ -370,8 +368,8 @@ interface FieldItemInterface extends ComplexDataInterface {
* The form state of the (entire) configuration form. * The form state of the (entire) configuration form.
* *
* @return array * @return array
* The form definition for the field instance settings. * The form definition for the field settings.
*/ */
public function instanceSettingsForm(array $form, FormStateInterface $form_state); public function fieldSettingsForm(array $form, FormStateInterface $form_state);
} }

View File

@ -192,7 +192,7 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
/** /**
* Returns a form for the default value input. * Returns a form for the default value input.
* *
* Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure instance-level default value. * administrators to configure instance-level default value.
* *
* @param array $form * @param array $form
@ -201,14 +201,14 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
* The form state of the (entire) configuration form. * The form state of the (entire) configuration form.
* *
* @return array * @return array
* The form definition for the field instance default value. * The form definition for the field default value.
*/ */
public function defaultValuesForm(array &$form, FormStateInterface $form_state); public function defaultValuesForm(array &$form, FormStateInterface $form_state);
/** /**
* Validates the submitted default value. * Validates the submitted default value.
* *
* Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure instance-level default value. * administrators to configure instance-level default value.
* *
* @param array $element * @param array $element
@ -223,7 +223,7 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
/** /**
* Processes the submitted default value. * Processes the submitted default value.
* *
* Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure instance-level default value. * administrators to configure instance-level default value.
* *
* @param array $element * @param array $element
@ -234,7 +234,7 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
* The form state of the (entire) configuration form. * The form state of the (entire) configuration form.
* *
* @return array * @return array
* The field instance default value. * The field default value.
*/ */
public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state); public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state);

View File

@ -49,11 +49,11 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePl
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDefaultSettings($type) { public function getDefaultStorageSettings($type) {
$plugin_definition = $this->getDefinition($type, FALSE); $plugin_definition = $this->getDefinition($type, FALSE);
if (!empty($plugin_definition['class'])) { if (!empty($plugin_definition['class'])) {
$plugin_class = DefaultFactory::getPluginClass($type, $plugin_definition); $plugin_class = DefaultFactory::getPluginClass($type, $plugin_definition);
return $plugin_class::defaultSettings(); return $plugin_class::defaultStorageSettings();
} }
return array(); return array();
} }
@ -61,11 +61,11 @@ class FieldTypePluginManager extends DefaultPluginManager implements FieldTypePl
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDefaultInstanceSettings($type) { public function getDefaultFieldSettings($type) {
$plugin_definition = $this->getDefinition($type, FALSE); $plugin_definition = $this->getDefinition($type, FALSE);
if (!empty($plugin_definition['class'])) { if (!empty($plugin_definition['class'])) {
$plugin_class = DefaultFactory::getPluginClass($type, $plugin_definition); $plugin_class = DefaultFactory::getPluginClass($type, $plugin_definition);
return $plugin_class::defaultInstanceSettings(); return $plugin_class::defaultFieldSettings();
} }
return array(); return array();
} }

View File

@ -17,19 +17,19 @@ use Drupal\Component\Plugin\PluginManagerInterface;
interface FieldTypePluginManagerInterface extends PluginManagerInterface { interface FieldTypePluginManagerInterface extends PluginManagerInterface {
/** /**
* Returns the default instance-level settings for a field type. * Returns the default field-level settings for a field type.
* *
* @param string $type * @param string $type
* A field type name. * A field type name.
* *
* @return array * @return array
* The instance's default settings, as provided by the plugin definition, or * The field's default settings, as provided by the plugin definition, or
* an empty array if type or settings are undefined. * an empty array if type or settings are undefined.
*/ */
public function getDefaultInstanceSettings($type); public function getDefaultFieldSettings($type);
/** /**
* Returns the default field-level settings for a field type. * Returns the default storage-level settings for a field type.
* *
* @param string $type * @param string $type
* A field type name. * A field type name.
@ -38,7 +38,7 @@ interface FieldTypePluginManagerInterface extends PluginManagerInterface {
* The type's default settings, as provided by the plugin definition, or an * The type's default settings, as provided by the plugin definition, or an
* empty array if type or settings are undefined. * empty array if type or settings are undefined.
*/ */
public function getDefaultSettings($type); public function getDefaultStorageSettings($type);
/** /**
* Gets the definition of all field types that can be added via UI. * Gets the definition of all field types that can be added via UI.

View File

@ -19,7 +19,7 @@ interface FormatterInterface extends PluginSettingsInterface {
/** /**
* Returns a form to configure settings for the formatter. * Returns a form to configure settings for the formatter.
* *
* Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure the formatter. The field_ui module takes care * administrators to configure the formatter. The field_ui module takes care
* of handling submitted form values. * of handling submitted form values.
* *

View File

@ -31,11 +31,11 @@ class BooleanItem extends FieldItemBase implements AllowedValuesInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'on_label' => t('On'), 'on_label' => t('On'),
'off_label' => t('Off'), 'off_label' => t('Off'),
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**
@ -66,7 +66,7 @@ class BooleanItem extends FieldItemBase implements AllowedValuesInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element['on_label'] = array( $element['on_label'] = array(
'#type' => 'textfield', '#type' => 'textfield',
'#title' => $this->t('"On" label'), '#title' => $this->t('"On" label'),

View File

@ -28,11 +28,11 @@ class DecimalItem extends NumericItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'precision' => 10, 'precision' => 10,
'scale' => 2, 'scale' => 2,
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**
@ -65,7 +65,7 @@ class DecimalItem extends NumericItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = array(); $element = array();
$settings = $this->getSettings(); $settings = $this->getSettings();

View File

@ -38,20 +38,20 @@ class EntityReferenceItem extends FieldItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'target_type' => \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'user', 'target_type' => \Drupal::moduleHandler()->moduleExists('node') ? 'node' : 'user',
'target_bundle' => NULL, 'target_bundle' => NULL,
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultInstanceSettings() { public static function defaultFieldSettings() {
return array( return array(
'handler' => 'default', 'handler' => 'default',
) + parent::defaultInstanceSettings(); ) + parent::defaultFieldSettings();
} }
/** /**

View File

@ -27,16 +27,16 @@ class IntegerItem extends NumericItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'unsigned' => FALSE, 'unsigned' => FALSE,
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultInstanceSettings() { public static function defaultFieldSettings() {
return array( return array(
'min' => '', 'min' => '',
'max' => '', 'max' => '',
@ -45,7 +45,7 @@ class IntegerItem extends NumericItemBase {
// Valid size property values include: 'tiny', 'small', 'medium', 'normal' // Valid size property values include: 'tiny', 'small', 'medium', 'normal'
// and 'big'. // and 'big'.
'size' => 'normal', 'size' => 'normal',
) + parent::defaultInstanceSettings(); ) + parent::defaultFieldSettings();
} }
/** /**

View File

@ -18,19 +18,19 @@ abstract class NumericItemBase extends FieldItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultInstanceSettings() { public static function defaultFieldSettings() {
return array( return array(
'min' => '', 'min' => '',
'max' => '', 'max' => '',
'prefix' => '', 'prefix' => '',
'suffix' => '', 'suffix' => '',
) + parent::defaultInstanceSettings(); ) + parent::defaultFieldSettings();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function instanceSettingsForm(array $form, FormStateInterface $form_state) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array(); $element = array();
$settings = $this->getSettings(); $settings = $this->getSettings();

View File

@ -31,10 +31,10 @@ class StringItem extends FieldItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'max_length' => 255, 'max_length' => 255,
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**

View File

@ -29,10 +29,10 @@ class UriItem extends StringItem {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'max_length' => 2048, 'max_length' => 2048,
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**

View File

@ -26,10 +26,10 @@ class UuidItem extends StringItem {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'max_length' => 128, 'max_length' => 128,
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**

View File

@ -463,9 +463,9 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
*/ */
protected static function getWidgetStateParents(array $parents, $field_name) { protected static function getWidgetStateParents(array $parents, $field_name) {
// Field processing data is placed at // Field processing data is placed at
// $form_state->get(['field', '#parents', ...$parents..., '#fields', $field_name]), // $form_state->get(['field_storage', '#parents', ...$parents..., '#fields', $field_name]),
// to avoid clashes between field names and $parents parts. // to avoid clashes between field names and $parents parts.
return array_merge(array('field', '#parents'), $parents, array('#fields', $field_name)); return array_merge(array('field_storage', '#parents'), $parents, array('#fields', $field_name));
} }
/** /**

View File

@ -25,7 +25,7 @@ interface WidgetInterface extends WidgetBaseInterface {
/** /**
* Returns a form to configure settings for the widget. * Returns a form to configure settings for the widget.
* *
* Invoked from \Drupal\field_ui\Form\FieldInstanceEditForm to allow * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure the widget. The field_ui module takes care of * administrators to configure the widget. The field_ui module takes care of
* handling submitted form values. * handling submitted form values.
* *
@ -86,10 +86,9 @@ interface WidgetInterface extends WidgetBaseInterface {
* $form_state->getValues(), and is used to access processing * $form_state->getValues(), and is used to access processing
* information for the field through the getWidgetState() and * information for the field through the getWidgetState() and
* setWidgetState() methods. * setWidgetState() methods.
* - #title: The sanitized element label for the field instance, ready for * - #title: The sanitized element label for the field, ready for output.
* output. * - #description: The sanitized element description for the field, ready
* - #description: The sanitized element description for the field instance, * for output.
* ready for output.
* - #required: A Boolean indicating whether the element value is required; * - #required: A Boolean indicating whether the element value is required;
* for required multiple value fields, only the first widget's values are * for required multiple value fields, only the first widget's values are
* required. * required.

View File

@ -6,7 +6,7 @@
*/ */
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
/** /**
@ -73,12 +73,12 @@ function block_content_entity_type_alter(array &$entity_types) {
* (optional) The label for the body instance. Defaults to 'Body' * (optional) The label for the body instance. Defaults to 'Body'
* *
* @return array() * @return array()
* Body field instance. * Body field.
*/ */
function block_content_add_body_field($block_type_id, $label = 'Body') { function block_content_add_body_field($block_type_id, $label = 'Body') {
// Add or remove the body field, as needed. // Add or remove the body field, as needed.
$field_storage = FieldStorageConfig::loadByName('block_content', 'body'); $field_storage = FieldStorageConfig::loadByName('block_content', 'body');
$instance = FieldInstanceConfig::loadByName('block_content', $block_type_id, 'body'); $field = FieldConfig::loadByName('block_content', $block_type_id, 'body');
if (empty($field_storage)) { if (empty($field_storage)) {
$field_storage = entity_create('field_storage_config', array( $field_storage = entity_create('field_storage_config', array(
'name' => 'body', 'name' => 'body',
@ -87,14 +87,14 @@ function block_content_add_body_field($block_type_id, $label = 'Body') {
)); ));
$field_storage->save(); $field_storage->save();
} }
if (empty($instance)) { if (empty($field)) {
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => $block_type_id, 'bundle' => $block_type_id,
'label' => $label, 'label' => $label,
'settings' => array('display_summary' => FALSE), 'settings' => array('display_summary' => FALSE),
)); ));
$instance->save(); $field->save();
// Assign widget settings for the 'default' form mode. // Assign widget settings for the 'default' form mode.
entity_get_form_display('block_content', $block_type_id, 'default') entity_get_form_display('block_content', $block_type_id, 'default')
@ -112,5 +112,5 @@ function block_content_add_body_field($block_type_id, $label = 'Body') {
->save(); ->save();
} }
return $instance; return $field;
} }

View File

@ -31,11 +31,11 @@ class BlockContentFieldTest extends BlockContentTestBase {
protected $fieldStorage; protected $fieldStorage;
/** /**
* The created instance. * The created field.
* *
* @var \Drupal\field\Entity\FieldInstanceConfig * @var \Drupal\field\Entity\FieldConfig
*/ */
protected $instance; protected $field;
/** /**
* The block type. * The block type.
@ -61,14 +61,14 @@ class BlockContentFieldTest extends BlockContentTestBase {
'cardinality' => 2, 'cardinality' => 2,
)); ));
$this->fieldStorage->save(); $this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array( $this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage, 'field_storage' => $this->fieldStorage,
'bundle' => 'link', 'bundle' => 'link',
'settings' => array( 'settings' => array(
'title' => DRUPAL_OPTIONAL, 'title' => DRUPAL_OPTIONAL,
), ),
)); ));
$this->instance->save(); $this->field->save();
entity_get_form_display('block_content', 'link', 'default') entity_get_form_display('block_content', 'link', 'default')
->setComponent($this->fieldStorage->getName(), array( ->setComponent($this->fieldStorage->getName(), array(
'type' => 'link_default', 'type' => 'link_default',

View File

@ -26,7 +26,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
use Drupal\file\FileInterface; use Drupal\file\FileInterface;
use Drupal\user\EntityOwnerInterface; use Drupal\user\EntityOwnerInterface;
@ -139,16 +139,16 @@ function comment_theme() {
} }
/** /**
* Implements hook_ENTITY_TYPE_create() for 'field_instance_config'. * Implements hook_ENTITY_TYPE_create() for 'field_config'.
*/ */
function comment_field_instance_config_create(FieldInstanceConfigInterface $instance) { function comment_field_config_create(FieldConfigInterface $field) {
if ($instance->getType() == 'comment' && !$instance->isSyncing()) { if ($field->getType() == 'comment' && !$field->isSyncing()) {
// Assign default values for the field instance. // Assign default values for the field.
if (!isset($instance->default_value)) { if (!isset($field->default_value)) {
$instance->default_value = array(); $field->default_value = array();
} }
$instance->default_value += array(array()); $field->default_value += array(array());
$instance->default_value[0] += array( $field->default_value[0] += array(
'status' => CommentItemInterface::OPEN, 'status' => CommentItemInterface::OPEN,
'cid' => 0, 'cid' => 0,
'last_comment_timestamp' => 0, 'last_comment_timestamp' => 0,
@ -160,10 +160,10 @@ function comment_field_instance_config_create(FieldInstanceConfigInterface $inst
} }
/** /**
* Implements hook_ENTITY_TYPE_update() for 'field_instance_config'. * Implements hook_ENTITY_TYPE_update() for 'field_config'.
*/ */
function comment_field_instance_config_update(FieldInstanceConfigInterface $instance) { function comment_field_config_update(FieldConfigInterface $field) {
if ($instance->getType() == 'comment') { if ($field->getType() == 'comment') {
// Comment field settings also affects the rendering of *comment* entities, // Comment field settings also affects the rendering of *comment* entities,
// not only the *commented* entities. // not only the *commented* entities.
\Drupal::entityManager()->getViewBuilder('comment')->resetCache(); \Drupal::entityManager()->getViewBuilder('comment')->resetCache();
@ -184,14 +184,14 @@ function comment_field_storage_config_insert(FieldStorageConfigInterface $field_
} }
/** /**
* Implements hook_ENTITY_TYPE_delete() for 'field_instance_config'. * Implements hook_ENTITY_TYPE_delete() for 'field_config'.
*/ */
function comment_field_instance_config_delete(FieldInstanceConfigInterface $instance) { function comment_field_config_delete(FieldConfigInterface $field) {
if ($instance->getType() == 'comment') { if ($field->getType() == 'comment') {
// Delete all comments that used by the entity bundle. // Delete all comments that used by the entity bundle.
$entity_query = \Drupal::entityQuery('comment'); $entity_query = \Drupal::entityQuery('comment');
$entity_query->condition('entity_type', $instance->getEntityTypeId()); $entity_query->condition('entity_type', $field->getEntityTypeId());
$entity_query->condition('field_name', $instance->getName()); $entity_query->condition('field_name', $field->getName());
$cids = $entity_query->execute(); $cids = $entity_query->execute();
entity_delete_multiple('comment', $cids); entity_delete_multiple('comment', $cids);
} }

View File

@ -60,7 +60,7 @@ comment.type.*:
type: text type: text
label: 'Description' label: 'Description'
field.comment.settings: field.comment.storage_settings:
type: sequence type: sequence
label: 'Settings' label: 'Settings'
sequence: sequence:
@ -93,7 +93,7 @@ field.comment.value:
type: integer type: integer
label: 'Count' label: 'Count'
field.comment.instance_settings: field.comment.field_settings:
type: mapping type: mapping
label: 'Comment settings' label: 'Comment settings'
mapping: mapping:

View File

@ -20,7 +20,7 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface; use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
/** /**
* Comment manager contains common functions to manage comment fields. * Comment manager contains common functions to manage comment fields.
@ -157,7 +157,7 @@ class CommentManager implements CommentManagerInterface {
} }
// Make sure the instance doesn't already exist. // Make sure the instance doesn't already exist.
if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) { if (!array_key_exists($field_name, $this->entityManager->getFieldDefinitions($entity_type, $bundle))) {
$instance = $this->entityManager->getStorage('field_instance_config')->create(array( $field = $this->entityManager->getStorage('field_config')->create(array(
'label' => 'Comments', 'label' => 'Comments',
'description' => '', 'description' => '',
'field_name' => $field_name, 'field_name' => $field_name,
@ -174,7 +174,7 @@ class CommentManager implements CommentManagerInterface {
), ),
), ),
)); ));
$instance->save(); $field->save();
// Assign widget settings for the 'default' form mode. // Assign widget settings for the 'default' form mode.
entity_get_form_display($entity_type, $bundle, 'default') entity_get_form_display($entity_type, $bundle, 'default')
@ -227,16 +227,16 @@ class CommentManager implements CommentManagerInterface {
)); ));
$field_storage->save(); $field_storage->save();
} }
if (!FieldInstanceConfig::loadByName('comment', $comment_type_id, 'comment_body')) { if (!FieldConfig::loadByName('comment', $comment_type_id, 'comment_body')) {
// Attaches the body field by default. // Attaches the body field by default.
$field_instance = $this->entityManager->getStorage('field_instance_config')->create(array( $field = $this->entityManager->getStorage('field_config')->create(array(
'field_name' => 'comment_body', 'field_name' => 'comment_body',
'label' => 'Comment', 'label' => 'Comment',
'entity_type' => 'comment', 'entity_type' => 'comment',
'bundle' => $comment_type_id, 'bundle' => $comment_type_id,
'required' => TRUE, 'required' => TRUE,
)); ));
$field_instance->save(); $field->save();
// Assign widget settings for the 'default' form mode. // Assign widget settings for the 'default' form mode.
entity_get_form_display('comment', $comment_type_id, 'default') entity_get_form_display('comment', $comment_type_id, 'default')

View File

@ -52,7 +52,7 @@ interface CommentManagerInterface {
* @param string $entity_type * @param string $entity_type
* The entity type to attach the default comment field to. * The entity type to attach the default comment field to.
* @param string $bundle * @param string $bundle
* The bundle to attach the default comment field instance to. * The bundle to attach the default comment field to.
* @param string $field_name * @param string $field_name
* (optional) Field name to use for the comment field. Defaults to * (optional) Field name to use for the comment field. Defaults to
* 'comment'. * 'comment'.
@ -66,7 +66,7 @@ interface CommentManagerInterface {
public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment'); public function addDefaultField($entity_type, $bundle, $field_name = 'comment', $default_value = CommentItemInterface::OPEN, $comment_type_id = 'comment');
/** /**
* Creates a comment_body field instance. * Creates a comment_body field.
* *
* @param string $comment_type * @param string $comment_type
* The comment bundle. * The comment bundle.

View File

@ -132,14 +132,14 @@ class CommentStorage extends SqlContentEntityStorage implements CommentStorageIn
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getNewCommentPageNumber($total_comments, $new_comments, ContentEntityInterface $entity, $field_name = 'comment') { public function getNewCommentPageNumber($total_comments, $new_comments, ContentEntityInterface $entity, $field_name = 'comment') {
$instance = $entity->getFieldDefinition($field_name); $field = $entity->getFieldDefinition($field_name);
$comments_per_page = $instance->getSetting('per_page'); $comments_per_page = $field->getSetting('per_page');
if ($total_comments <= $comments_per_page) { if ($total_comments <= $comments_per_page) {
// Only one page of comments. // Only one page of comments.
$count = 0; $count = 0;
} }
elseif ($instance->getSetting('default_mode') == CommentManagerInterface::COMMENT_MODE_FLAT) { elseif ($field->getSetting('default_mode') == CommentManagerInterface::COMMENT_MODE_FLAT) {
// Flat comments. // Flat comments.
$count = $total_comments - $new_comments; $count = $total_comments - $new_comments;
} }

View File

@ -31,23 +31,23 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'comment_type' => '', 'comment_type' => '',
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultInstanceSettings() { public static function defaultFieldSettings() {
return array( return array(
'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED, 'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED,
'per_page' => 50, 'per_page' => 50,
'form_location' => CommentItemInterface::FORM_BELOW, 'form_location' => CommentItemInterface::FORM_BELOW,
'anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT, 'anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
'preview' => DRUPAL_OPTIONAL, 'preview' => DRUPAL_OPTIONAL,
) + parent::defaultInstanceSettings(); ) + parent::defaultFieldSettings();
} }
/** /**
@ -99,7 +99,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function instanceSettingsForm(array $form, FormStateInterface $form_state) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array(); $element = array();
$settings = $this->getSettings(); $settings = $this->getSettings();
@ -110,9 +110,6 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
'#type' => 'details', '#type' => 'details',
'#title' => t('Comment form settings'), '#title' => t('Comment form settings'),
'#open' => TRUE, '#open' => TRUE,
'#attributes' => array(
'class' => array('comment-instance-settings-form'),
),
'#attached' => array( '#attached' => array(
'library' => array('comment/drupal.comment'), 'library' => array('comment/drupal.comment'),
), ),
@ -167,7 +164,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
*/ */
public function __get($name) { public function __get($name) {
if ($name == 'status' && !isset($this->values[$name])) { if ($name == 'status' && !isset($this->values[$name])) {
// Get default value from field instance when no data saved in entity. // Get default value from the field when no data saved in entity.
$field_default_values = $this->getFieldDefinition()->getDefaultValue($this->getEntity()); $field_default_values = $this->getFieldDefinition()->getDefaultValue($this->getEntity());
return $field_default_values[0]['status']; return $field_default_values[0]['status'];
} }
@ -189,7 +186,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = array(); $element = array();
// @todo Inject entity storage once typed-data supports container injection. // @todo Inject entity storage once typed-data supports container injection.

View File

@ -63,7 +63,7 @@ class CommentWidget extends WidgetBase {
// second column on wide-resolutions), place the field as a details element // second column on wide-resolutions), place the field as a details element
// in this tab-set. // in this tab-set.
if (isset($form['advanced'])) { if (isset($form['advanced'])) {
// Get default value from the field instance. // Get default value from the field.
$field_default_values = $this->fieldDefinition->getDefaultValue($entity); $field_default_values = $this->fieldDefinition->getDefaultValue($entity);
// Override widget title to be helpful for end users. // Override widget title to be helpful for end users.
@ -72,7 +72,7 @@ class CommentWidget extends WidgetBase {
$element += array( $element += array(
'#type' => 'details', '#type' => 'details',
// Open the details when the selected value is different to the stored // Open the details when the selected value is different to the stored
// default values for the field instance. // default values for the field.
'#open' => ($items->status != $field_default_values[0]['status']), '#open' => ($items->status != $field_default_values[0]['status']),
'#group' => 'advanced', '#group' => 'advanced',
'#attributes' => array( '#attributes' => array(

View File

@ -9,7 +9,7 @@ namespace Drupal\comment\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
/** /**
* Tests fields on comments. * Tests fields on comments.
@ -35,10 +35,10 @@ class CommentFieldsTest extends CommentTestBase {
$this->container->get('comment.manager')->addDefaultField('node', 'test_node_type'); $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type');
// Check that the 'comment_body' field is present on the comment bundle. // Check that the 'comment_body' field is present on the comment bundle.
$instance = FieldInstanceConfig::loadByName('comment', 'comment', 'comment_body'); $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$this->assertTrue(!empty($instance), 'The comment_body field is added when a comment bundle is created'); $this->assertTrue(!empty($field), 'The comment_body field is added when a comment bundle is created');
$instance->delete(); $field->delete();
// Check that the 'comment_body' field is deleted. // Check that the 'comment_body' field is deleted.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
@ -53,13 +53,13 @@ class CommentFieldsTest extends CommentTestBase {
// new comment bundle. // new comment bundle.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body'); $field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field_storage, 'The comment_body field exists'); $this->assertTrue($field_storage, 'The comment_body field exists');
$instance = FieldInstanceConfig::loadByName('comment', 'comment', 'comment_body'); $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$this->assertTrue(isset($instance), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name))); $this->assertTrue(isset($field), format_string('The comment_body field is present for comments on type @type', array('@type' => $type_name)));
// Test adding a field that defaults to CommentItemInterface::CLOSED. // Test adding a field that defaults to CommentItemInterface::CLOSED.
$this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies'); $this->container->get('comment.manager')->addDefaultField('node', 'test_node_type', 'who_likes_ponies', CommentItemInterface::CLOSED, 'who_likes_ponies');
$field_storage = entity_load('field_instance_config', 'node.test_node_type.who_likes_ponies'); $field = entity_load('field_config', 'node.test_node_type.who_likes_ponies');
$this->assertEqual($field_storage->default_value[0]['status'], CommentItemInterface::CLOSED); $this->assertEqual($field->default_value[0]['status'], CommentItemInterface::CLOSED);
} }
/** /**

View File

@ -25,13 +25,13 @@ class CommentNodeChangesTest extends CommentTestBase {
$this->assertTrue($comment->id(), 'The comment could be loaded.'); $this->assertTrue($comment->id(), 'The comment could be loaded.');
$this->node->delete(); $this->node->delete();
$this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.'); $this->assertFalse(Comment::load($comment->id()), 'The comment could not be loaded after the node was deleted.');
// Make sure the comment field and all its instances are deleted when node // Make sure the comment field storage and all its fields are deleted when
// type is deleted. // the node type is deleted.
$this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field exists'); $this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field storage exists');
$this->assertNotNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance exists'); $this->assertNotNull(entity_load('field_config', 'node.article.comment'), 'Comment field exists');
// Delete the node type. // Delete the node type.
entity_delete_multiple('node_type', array($this->node->bundle())); entity_delete_multiple('node_type', array($this->node->bundle()));
$this->assertNull(entity_load('field_storage_config', 'node.comment'), 'Comment field deleted'); $this->assertNull(entity_load('field_storage_config', 'node.comment'), 'Comment field storage deleted');
$this->assertNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance deleted'); $this->assertNull(entity_load('field_config', 'node.article.comment'), 'Comment field deleted');
} }
} }

View File

@ -10,7 +10,7 @@ namespace Drupal\comment\Tests;
use Drupal\comment\CommentInterface; use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
@ -94,8 +94,8 @@ class CommentNonNodeTest extends WebTestBase {
$edit = array(); $edit = array();
$edit['comment_body[0][value]'] = $comment; $edit['comment_body[0][value]'] = $comment;
$instance = FieldInstanceConfig::loadByName('entity_test', 'entity_test', 'comment'); $field = FieldConfig::loadByName('entity_test', 'entity_test', 'comment');
$preview_mode = $instance->getSetting('preview'); $preview_mode = $field->getSetting('preview');
// Must get the page before we test for fields. // Must get the page before we test for fields.
if ($entity !== NULL) { if ($entity !== NULL) {
@ -375,7 +375,7 @@ class CommentNonNodeTest extends WebTestBase {
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalPostForm(NULL, array( $this->drupalPostForm(NULL, array(
'field[settings][comment_type]' => 'foobar', 'field_storage[settings][comment_type]' => 'foobar',
), t('Save field settings')); ), t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings')); $this->drupalPostForm(NULL, array(), t('Save settings'));
@ -391,7 +391,7 @@ class CommentNonNodeTest extends WebTestBase {
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
// Re-use another comment type. // Re-use another comment type.
$this->drupalPostForm(NULL, array( $this->drupalPostForm(NULL, array(
'field[settings][comment_type]' => 'foobar', 'field_storage[settings][comment_type]' => 'foobar',
), t('Save field settings')); ), t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings')); $this->drupalPostForm(NULL, array(), t('Save settings'));
$this->assertRaw(t('Saved %name configuration', array('%name' => 'Barfoo'))); $this->assertRaw(t('Saved %name configuration', array('%name' => 'Barfoo')));

View File

@ -10,8 +10,8 @@ namespace Drupal\comment\Tests;
use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\CommentType;
use Drupal\comment\Entity\Comment; use Drupal\comment\Entity\Comment;
use Drupal\comment\CommentInterface; use Drupal\comment\CommentInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
@ -109,12 +109,12 @@ abstract class CommentTestBase extends WebTestBase {
$edit['comment_body[0][value]'] = $comment; $edit['comment_body[0][value]'] = $comment;
if ($entity !== NULL) { if ($entity !== NULL) {
$instance = FieldInstanceConfig::loadByName('node', $entity->bundle(), $field_name); $field = FieldConfig::loadByName('node', $entity->bundle(), $field_name);
} }
else { else {
$instance = FieldInstanceConfig::loadByName('node', 'article', $field_name); $field = FieldConfig::loadByName('node', 'article', $field_name);
} }
$preview_mode = $instance->settings['preview']; $preview_mode = $field->settings['preview'];
// Must get the page before we test for fields. // Must get the page before we test for fields.
if ($entity !== NULL) { if ($entity !== NULL) {
@ -309,9 +309,9 @@ abstract class CommentTestBase extends WebTestBase {
* Defaults to 'comment'. * Defaults to 'comment'.
*/ */
public function setCommentSettings($name, $value, $message, $field_name = 'comment') { public function setCommentSettings($name, $value, $message, $field_name = 'comment') {
$instance = FieldInstanceConfig::loadByName('node', 'article', $field_name); $field = FieldConfig::loadByName('node', 'article', $field_name);
$instance->settings[$name] = $value; $field->settings[$name] = $value;
$instance->save(); $field->save();
// Display status message. // Display status message.
$this->pass($message); $this->pass($message);
} }

View File

@ -10,7 +10,7 @@ use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
/** /**
@ -95,8 +95,8 @@ class CommentTypeTest extends CommentTestBase {
public function testCommentTypeEditing() { public function testCommentTypeEditing() {
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
$instance = FieldInstanceConfig::loadByName('comment', 'comment', 'comment_body'); $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$this->assertEqual($instance->getLabel(), 'Comment', 'Comment body field was found.'); $this->assertEqual($field->getLabel(), 'Comment', 'Comment body field was found.');
// Change the comment type name. // Change the comment type name.
$this->drupalGet('admin/structure/comment'); $this->drupalGet('admin/structure/comment');

View File

@ -61,8 +61,8 @@ class CommentValidationTest extends EntityUnitTestBase {
'name' => 'page', 'name' => 'page',
))->save(); ))->save();
// Add comment field instance to page content. // Add comment field to page content.
$this->entityManager->getStorage('field_instance_config')->create(array( $this->entityManager->getStorage('field_config')->create(array(
'field_name' => 'comment', 'field_name' => 'comment',
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => 'page', 'bundle' => 'page',

View File

@ -26,12 +26,12 @@ class ConfigEntityStorageTest extends DrupalUnitTestBase {
public static $modules = array('config_test'); public static $modules = array('config_test');
/** /**
* Tests importing fields and instances with changed IDs or UUIDs. * Tests creating configuration entities with changed UUIDs.
*/ */
public function testUUIDConflict() { public function testUUIDConflict() {
$entity_type = 'config_test'; $entity_type = 'config_test';
$id = 'test_1'; $id = 'test_1';
// Load the original field and instance entities. // Load the original configuration entity.
entity_create($entity_type, array('id' => $id))->save(); entity_create($entity_type, array('id' => $id))->save();
$entity = entity_load($entity_type, $id); $entity = entity_load($entity_type, $id);

View File

@ -70,7 +70,7 @@ class ConfigExportImportUITest extends WebTestBase {
'type' => 'text', 'type' => 'text',
)); ));
$this->fieldStorage->save(); $this->fieldStorage->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'field_storage' => $this->fieldStorage, 'field_storage' => $this->fieldStorage,
'bundle' => $this->content_type->type, 'bundle' => $this->content_type->type,
))->save(); ))->save();
@ -96,10 +96,10 @@ class ConfigExportImportUITest extends WebTestBase {
$this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->originalSlogan); $this->assertEqual(\Drupal::config('system.site')->get('slogan'), $this->originalSlogan);
// Delete the custom field. // Delete the custom field.
$field_instances = entity_load_multiple('field_instance_config'); $fields = entity_load_multiple('field_config');
foreach ($field_instances as $field_instance) { foreach ($fields as $field) {
if ($field_instance->field_name == $this->fieldName) { if ($field->field_name == $this->fieldName) {
$field_instance->delete(); $field->delete();
} }
} }
$field_storages = entity_load_multiple('field_storage_config'); $field_storages = entity_load_multiple('field_storage_config');

View File

@ -73,7 +73,7 @@ class ConfigImportRecreateTest extends DrupalUnitTestBase {
$config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id(); $config_name = $content_type->getEntityType()->getConfigPrefix() . '.' . $content_type->id();
$this->copyConfig($active, $staging); $this->copyConfig($active, $staging);
// Delete the content type. This will also delete a field, a field instance, // Delete the content type. This will also delete a field storage, a field,
// an entity view display and an entity form display. // an entity view display and an entity form display.
$content_type->delete(); $content_type->delete();
$this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.'); $this->assertFalse($active->exists($config_name), 'Content type\'s old name does not exist active store.');
@ -85,7 +85,7 @@ class ConfigImportRecreateTest extends DrupalUnitTestBase {
$content_type->save(); $content_type->save();
$this->configImporter->reset(); $this->configImporter->reset();
// A node type, a field, a field instance an entity view display and an // A node type, a field storage, a field, an entity view display and an
// entity form display will be recreated. // entity form display will be recreated.
$creates = $this->configImporter->getUnprocessedConfiguration('create'); $creates = $this->configImporter->getUnprocessedConfiguration('create');
$deletes = $this->configImporter->getUnprocessedConfiguration('delete'); $deletes = $this->configImporter->getUnprocessedConfiguration('delete');

View File

@ -36,13 +36,13 @@ function hook_config_translation_info(&$info) {
$route_provider = \Drupal::service('router.route_provider'); $route_provider = \Drupal::service('router.route_provider');
// If field UI is not enabled, the base routes of the type // If field UI is not enabled, the base routes of the type
// "field_ui.instance_edit_$entity_type" are not defined. // "field_ui.field_edit_$entity_type" are not defined.
if (\Drupal::moduleHandler()->moduleExists('field_ui')) { if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
// Add fields entity mappers to all fieldable entity types defined. // Add fields entity mappers to all fieldable entity types defined.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) { foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
$base_route = NULL; $base_route = NULL;
try { try {
$base_route = $route_provider->getRouteByName('field_ui.instance_edit_' . $entity_type_id); $base_route = $route_provider->getRouteByName('field_ui.field_edit_' . $entity_type_id);
} }
catch (RouteNotFoundException $e) { catch (RouteNotFoundException $e) {
// Ignore non-existent routes. // Ignore non-existent routes.
@ -51,10 +51,10 @@ function hook_config_translation_info(&$info) {
// Make sure entity type is fieldable and has a base route. // Make sure entity type is fieldable and has a base route.
if ($entity_type->isFieldable() && !empty($base_route)) { if ($entity_type->isFieldable() && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array( $info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id, 'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_instance_config', 'entity_type' => 'field_config',
'title' => t('!label field'), 'title' => t('!label field'),
'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper', 'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_entity_type' => $entity_type_id, 'base_entity_type' => $entity_type_id,
'weight' => 10, 'weight' => 10,
); );

View File

@ -80,9 +80,9 @@ function config_translation_entity_type_alter(array &$entity_types) {
if ($entity_type_id == 'block') { if ($entity_type_id == 'block') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListBuilder'; $class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListBuilder';
} }
elseif ($entity_type_id == 'field_instance_config') { elseif ($entity_type_id == 'field_config') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationFieldInstanceListBuilder'; $class = 'Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder';
// Will be filled in dynamically, see \Drupal\field\Entity\FieldInstanceConfig::linkTemplates(). // Will be filled in dynamically, see \Drupal\field\Entity\FieldConfig::linkTemplates().
$entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.'); $entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.');
} }
else { else {
@ -105,17 +105,17 @@ function config_translation_config_translation_info(&$info) {
$route_provider = \Drupal::service('router.route_provider'); $route_provider = \Drupal::service('router.route_provider');
// If field UI is not enabled, the base routes of the type // If field UI is not enabled, the base routes of the type
// "field_ui.instance_edit_$entity_type" are not defined. // "field_ui.field_edit_$entity_type" are not defined.
if (\Drupal::moduleHandler()->moduleExists('field_ui')) { if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
// Add fields entity mappers to all fieldable entity types defined. // Add fields entity mappers to all fieldable entity types defined.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) { foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
$base_route = NULL; $base_route = NULL;
try { try {
$base_route = $route_provider->getRouteByName('field_ui.instance_edit_' . $entity_type_id); $base_route = $route_provider->getRouteByName('field_ui.field_edit_' . $entity_type_id);
} }
catch (RouteNotFoundException $e) { catch (RouteNotFoundException $e) {
if ($collection = \Drupal::service('router.builder')->getCollectionDuringRebuild()) { if ($collection = \Drupal::service('router.builder')->getCollectionDuringRebuild()) {
$base_route = $collection->get('field_ui.instance_edit_' . $entity_type_id); $base_route = $collection->get('field_ui.field_edit_' . $entity_type_id);
} }
// Ignore non-existent routes. // Ignore non-existent routes.
} }
@ -123,10 +123,10 @@ function config_translation_config_translation_info(&$info) {
// Make sure entity type is fieldable and has a base route. // Make sure entity type is fieldable and has a base route.
if ($entity_type->isFieldable() && !empty($base_route)) { if ($entity_type->isFieldable() && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array( $info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id, 'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_instance_config', 'entity_type' => 'field_config',
'title' => '!label field', 'title' => '!label field',
'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper', 'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_entity_type' => $entity_type_id, 'base_entity_type' => $entity_type_id,
'weight' => 10, 'weight' => 10,
); );
@ -145,7 +145,7 @@ function config_translation_config_translation_info(&$info) {
// Do not record this entity mapper if the entity type does not // Do not record this entity mapper if the entity type does not
// provide a base route. We'll surely not be able to do anything with // provide a base route. We'll surely not be able to do anything with
// it anyway. Configuration entities with a dynamic base path, such as // it anyway. Configuration entities with a dynamic base path, such as
// field instances, need special treatment. See above. // fields, need special treatment. See above.
continue; continue;
} }

View File

@ -2,26 +2,25 @@
/** /**
* @file * @file
* Contains \Drupal\config_translation\ConfigFieldInstanceMapper. * Contains \Drupal\config_translation\ConfigFieldMapper.
*/ */
namespace Drupal\config_translation; namespace Drupal\config_translation;
/** /**
* Configuration mapper for field instances. * Configuration mapper for fields.
* *
* On top of plugin definition values on ConfigEntityMapper, the plugin * On top of plugin definition values on ConfigEntityMapper, the plugin
* definition for field instance mappers are required to contain the following * definition for field mappers are required to contain the following
* additional keys: * additional keys:
* - base_entity_type: The name of the entity type the field instances are * - base_entity_type: The name of the entity type the fields are attached to.
* attached to.
*/ */
class ConfigFieldInstanceMapper extends ConfigEntityMapper { class ConfigFieldMapper extends ConfigEntityMapper {
/** /**
* Loaded entity instance to help produce the translation interface. * Loaded entity instance to help produce the translation interface.
* *
* @var \Drupal\field\FieldInstanceConfigInterface * @var \Drupal\field\FieldConfigInterface
*/ */
protected $entity; protected $entity;

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains \Drupal\config_translation\Controller\ConfigTranslationFieldInstanceListBuilder. * Contains \Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder.
*/ */
namespace Drupal\config_translation\Controller; namespace Drupal\config_translation\Controller;
@ -16,12 +16,12 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Defines the config translation list builder for field instance entities. * Defines the config translation list builder for field entities.
*/ */
class ConfigTranslationFieldInstanceListBuilder extends ConfigTranslationEntityListBuilder { class ConfigTranslationFieldListBuilder extends ConfigTranslationEntityListBuilder {
/** /**
* The name of the entity type the field instances are attached to. * The name of the entity type the fields are attached to.
* *
* @var string * @var string
*/ */
@ -61,7 +61,7 @@ class ConfigTranslationFieldInstanceListBuilder extends ConfigTranslationEntityL
} }
/** /**
* Constructs a new ConfigTranslationFieldInstanceListBuilder object. * Constructs a new ConfigTranslationFieldListBuilder object.
* *
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition. * The entity type definition.
@ -90,8 +90,8 @@ class ConfigTranslationFieldInstanceListBuilder extends ConfigTranslationEntityL
*/ */
public function load() { public function load() {
// It is not possible to use the standard load method, because this needs // It is not possible to use the standard load method, because this needs
// all field instance entities only for the given baseEntityType. // all field entities only for the given baseEntityType.
$ids = \Drupal::entityQuery('field_instance_config') $ids = \Drupal::entityQuery('field_config')
->condition('id', $this->baseEntityType . '.', 'STARTS_WITH') ->condition('id', $this->baseEntityType . '.', 'STARTS_WITH')
->execute(); ->execute();
return $this->storage->loadMultiple($ids); return $this->storage->loadMultiple($ids);
@ -143,7 +143,7 @@ class ConfigTranslationFieldInstanceListBuilder extends ConfigTranslationEntityL
} }
/** /**
* Controls the visibility of the bundle column on field instance list pages. * Controls the visibility of the bundle column on field list pages.
* *
* @return bool * @return bool
* Whenever the bundle is displayed or not. * Whenever the bundle is displayed or not.

View File

@ -63,8 +63,8 @@ class ConfigTranslationListController extends ControllerBase {
throw new NotFoundHttpException(); throw new NotFoundHttpException();
} }
$entity_type = $mapper->getType(); $entity_type = $mapper->getType();
// If the mapper, for example the mapper for field instances, has a custom // If the mapper, for example the mapper for fields, has a custom list
// list controller defined, use it. Other mappers, for examples the ones for // controller defined, use it. Other mappers, for examples the ones for
// node_type and block, fallback to the generic configuration translation // node_type and block, fallback to the generic configuration translation
// list controller. // list controller.
$build = $this->entityManager() $build = $this->entityManager()

View File

@ -45,7 +45,7 @@ class ContactFieldsTest extends ViewTestBase {
'label' => 'Test contact form', 'label' => 'Test contact form',
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'field_storage' => $this->field_storage, 'field_storage' => $this->field_storage,
'bundle' => 'contact_message', 'bundle' => 'contact_message',
))->save(); ))->save();

View File

@ -12,7 +12,6 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\field\FieldInstanceConfigInterface;
/** /**
* Returns a form element to configure field synchronization. * Returns a form element to configure field synchronization.

View File

@ -81,9 +81,9 @@
} }
}); });
// When a bundle is made translatable all of its field instances should // When a bundle is made translatable all of its fields should inherit
// inherit this setting. Instead when it is made non translatable its field // this setting. Instead when it is made non translatable its fields are
// instances are hidden, since their translatability no longer matters. // hidden, since their translatability no longer matters.
$('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', function (e) { $('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', function (e) {
var $target = $(e.target); var $target = $(e.target);
var $bundleSettings = $target.closest('.bundle-settings'); var $bundleSettings = $target.closest('.bundle-settings');

View File

@ -12,7 +12,6 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
/** /**
@ -550,19 +549,19 @@ function content_translation_entity_extra_field_info() {
} }
/** /**
* Implements hook_form_FORM_ID_alter() for 'field_ui_instance_edit_form'. * Implements hook_form_FORM_ID_alter() for 'field_ui_field_edit_form'.
*/ */
function content_translation_form_field_ui_field_instance_edit_form_alter(array &$form, FormStateInterface $form_state) { function content_translation_form_field_ui_field_edit_form_alter(array &$form, FormStateInterface $form_state) {
$instance = $form_state->get('instance'); $field = $form_state->get('field');
$bundle_is_translatable = content_translation_enabled($instance->entity_type, $instance->bundle); $bundle_is_translatable = content_translation_enabled($field->entity_type, $field->bundle);
$form['instance']['translatable'] = array( $form['field']['translatable'] = array(
'#type' => 'checkbox', '#type' => 'checkbox',
'#title' => t('Users may translate this field'), '#title' => t('Users may translate this field'),
'#default_value' => $instance->isTranslatable(), '#default_value' => $field->isTranslatable(),
'#weight' => -1, '#weight' => -1,
'#disabled' => !$bundle_is_translatable, '#disabled' => !$bundle_is_translatable,
'#access' => $instance->getFieldStorageDefinition()->isTranslatable(), '#access' => $field->getFieldStorageDefinition()->isTranslatable(),
); );
// Provide helpful pointers for administrators. // Provide helpful pointers for administrators.
@ -570,17 +569,17 @@ function content_translation_form_field_ui_field_instance_edit_form_alter(array
$toggle_url = url('admin/config/regional/content-language', array( $toggle_url = url('admin/config/regional/content-language', array(
'query' => drupal_get_destination(), 'query' => drupal_get_destination(),
)); ));
$form['instance']['translatable']['#description'] = t('To configure translation for this field, <a href="@language-settings-url">enable language support</a> for this type.', array( $form['field']['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, '@language-settings-url' => $toggle_url,
)); ));
} }
if ($instance->isTranslatable()) { if ($field->isTranslatable()) {
module_load_include('inc', 'content_translation', 'content_translation.admin'); module_load_include('inc', 'content_translation', 'content_translation.admin');
$element = content_translation_field_sync_widget($instance); $element = content_translation_field_sync_widget($field);
if ($element) { if ($element) {
$form['instance']['third_party_settings']['content_translation']['translation_sync'] = $element; $form['field']['third_party_settings']['content_translation']['translation_sync'] = $element;
$form['instance']['third_party_settings']['content_translation']['translation_sync']['#weight'] = -10; $form['field']['third_party_settings']['content_translation']['translation_sync']['#weight'] = -10;
} }
} }
} }

View File

@ -86,7 +86,7 @@ class ContentTranslationContextualLinksTest extends WebTestBase {
'cardinality' => 1, 'cardinality' => 1,
'translatable' => TRUE, 'translatable' => TRUE,
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'entity_type' => 'node', 'entity_type' => 'node',
'field_name' => 'field_test_text', 'field_name' => 'field_test_text',
'bundle' => $this->bundle, 'bundle' => $this->bundle,

View File

@ -10,7 +10,7 @@ namespace Drupal\content_translation\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Field\Entity\BaseFieldOverride; use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
@ -30,7 +30,7 @@ class ContentTranslationSettingsTest extends WebTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
// Set up two content types to test field instances shared between different // Set up two content types to test fields shared between different
// bundles. // bundles.
$this->drupalCreateContentType(array('type' => 'article')); $this->drupalCreateContentType(array('type' => 'article'));
$this->drupalCreateContentType(array('type' => 'page')); $this->drupalCreateContentType(array('type' => 'page'));
@ -163,20 +163,20 @@ class ContentTranslationSettingsTest extends WebTestBase {
// Test that configurable field translatability is correctly switched. // Test that configurable field translatability is correctly switched.
$edit = array('settings[node][article][fields][body]' => $translatable); $edit = array('settings[node][article][fields][body]' => $translatable);
$this->assertSettings('node', 'article', TRUE, $edit); $this->assertSettings('node', 'article', TRUE, $edit);
$instance = FieldInstanceConfig::loadByName('node', 'article', 'body'); $field = FieldConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article'); $definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.'); $this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
$this->assertEqual($instance->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.'); $this->assertEqual($field->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
// Test that also the Field UI form behaves correctly. // Test that also the Field UI form behaves correctly.
$translatable = !$translatable; $translatable = !$translatable;
$edit = array('instance[translatable]' => $translatable); $edit = array('field[translatable]' => $translatable);
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body', $edit, t('Save settings')); $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body', $edit, t('Save settings'));
\Drupal::entityManager()->clearCachedFieldDefinitions(); \Drupal::entityManager()->clearCachedFieldDefinitions();
$instance = FieldInstanceConfig::loadByName('node', 'article', 'body'); $field = FieldConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article'); $definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.'); $this->assertEqual($definitions['body']->isTranslatable(), $translatable, 'Field translatability correctly switched.');
$this->assertEqual($instance->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.'); $this->assertEqual($field->isTranslatable(), $definitions['body']->isTranslatable(), 'Configurable field translatability correctly switched.');
} }
} }
@ -221,34 +221,33 @@ class ContentTranslationSettingsTest extends WebTestBase {
} }
/** /**
* Tests that field instance setting depends on bundle translatability. * Tests that field setting depends on bundle translatability.
*/ */
function testFieldTranslatableSettingsUI() { function testFieldTranslatableSettingsUI() {
// At least one field needs to be translatable to enable article for // At least one field needs to be translatable to enable article for
// translation. Create an extra field to be used for this purpose. // translation. Create an extra field to be used for this purpose.
$field = array( $field_storage = array(
'name' => 'article_text', 'name' => 'article_text',
'entity_type' => 'node', 'entity_type' => 'node',
'type' => 'text', 'type' => 'text',
); );
entity_create('field_storage_config', $field)->save(); entity_create('field_storage_config', $field_storage)->save();
$instance = array( $field = array(
'field_name' => 'article_text', 'field_name' => 'article_text',
'entity_type' => 'node', 'entity_type' => 'node',
'bundle' => 'article', 'bundle' => 'article',
); );
entity_create('field_instance_config', $instance)->save(); entity_create('field_config', $field)->save();
// Tests that field instance doesn't have translatable setting if bundle // Tests that field doesn't have translatable setting if bundle is not
// is not translatable. // translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.body'; $path = 'admin/structure/types/manage/article/fields/node.article.body';
$this->drupalGet($path); $this->drupalGet($path);
$this->assertText('To configure translation for 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 // Tests that field has translatable setting if bundle is translatable.
// translatable. Note: this field instance is not translatable when // Note: this field is not translatable when enable bundle translatability.
// enable bundle translatability.
$edit = array( $edit = array(
'entity_types[node]' => TRUE, 'entity_types[node]' => TRUE,
'settings[node][article][settings][language][language_show]' => TRUE, 'settings[node][article][settings][language][language_show]' => TRUE,

View File

@ -57,7 +57,7 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
'translatable' => TRUE, 'translatable' => TRUE,
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'entity_type' => $this->entityTypeId, 'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName, 'field_name' => $this->fieldName,
'bundle' => $this->entityTypeId, 'bundle' => $this->entityTypeId,
@ -89,11 +89,11 @@ class ContentTranslationSyncImageTest extends ContentTranslationTestBase {
// Check that the alt and title fields are enabled for the image field. // Check that the alt and title fields are enabled for the image field.
$this->drupalLogin($this->editor); $this->drupalLogin($this->editor);
$this->drupalGet('entity_test_mul/structure/' . $this->entityTypeId . '/fields/' . $this->entityTypeId . '.' . $this->entityTypeId . '.' . $this->fieldName); $this->drupalGet('entity_test_mul/structure/' . $this->entityTypeId . '/fields/' . $this->entityTypeId . '.' . $this->entityTypeId . '.' . $this->fieldName);
$this->assertFieldChecked('edit-instance-third-party-settings-content-translation-translation-sync-alt'); $this->assertFieldChecked('edit-field-third-party-settings-content-translation-translation-sync-alt');
$this->assertFieldChecked('edit-instance-third-party-settings-content-translation-translation-sync-title'); $this->assertFieldChecked('edit-field-third-party-settings-content-translation-translation-sync-title');
$edit = array( $edit = array(
'instance[third_party_settings][content_translation][translation_sync][alt]' => FALSE, 'field[third_party_settings][content_translation][translation_sync][alt]' => FALSE,
'instance[third_party_settings][content_translation][translation_sync][title]' => FALSE, 'field[third_party_settings][content_translation][translation_sync][title]' => FALSE,
); );
$this->drupalPostForm(NULL, $edit, t('Save settings')); $this->drupalPostForm(NULL, $edit, t('Save settings'));

View File

@ -185,7 +185,7 @@ abstract class ContentTranslationTestBase extends WebTestBase {
'cardinality' => 1, 'cardinality' => 1,
'translatable' => TRUE, 'translatable' => TRUE,
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'entity_type' => $this->entityTypeId, 'entity_type' => $this->entityTypeId,
'field_name' => $this->fieldName, 'field_name' => $this->fieldName,
'bundle' => $this->bundle, 'bundle' => $this->bundle,

View File

@ -1,6 +1,6 @@
# Schema for the configuration files of the Datetime module. # Schema for the configuration files of the Datetime module.
field.datetime.settings: field.datetime.storage_settings:
type: mapping type: mapping
label: 'Datetime settings' label: 'Datetime settings'
mapping: mapping:
@ -8,7 +8,7 @@ field.datetime.settings:
type: string type: string
label: 'Date type' label: 'Date type'
field.datetime.instance_settings: field.datetime.field_settings:
type: sequence type: sequence
label: 'Settings' label: 'Settings'
sequence: sequence:

View File

@ -30,10 +30,10 @@ class DateTimeItem extends FieldItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
return array( return array(
'datetime_type' => 'datetime', 'datetime_type' => 'datetime',
) + parent::defaultSettings(); ) + parent::defaultStorageSettings();
} }
/** /**
@ -85,7 +85,7 @@ class DateTimeItem extends FieldItemBase {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = array(); $element = array();
$element['datetime_type'] = array( $element['datetime_type'] = array(

View File

@ -33,11 +33,11 @@ class DateTimeFieldTest extends WebTestBase {
protected $fieldStorage; protected $fieldStorage;
/** /**
* The instance used in this test class. * The field used in this test class.
* *
* @var \Drupal\field\Entity\FieldInstanceConfig * @var \Drupal\field\Entity\FieldConfig
*/ */
protected $instance; protected $field;
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
@ -59,14 +59,14 @@ class DateTimeFieldTest extends WebTestBase {
'settings' => array('datetime_type' => 'date'), 'settings' => array('datetime_type' => 'date'),
)); ));
$this->fieldStorage->save(); $this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array( $this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage, 'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'required' => TRUE, 'required' => TRUE,
)); ));
$this->instance->save(); $this->field->save();
entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') entity_get_form_display($this->field->entity_type, $this->field->bundle, 'default')
->setComponent($this->fieldStorage->name, array( ->setComponent($this->fieldStorage->name, array(
'type' => 'datetime_default', 'type' => 'datetime_default',
)) ))
@ -77,7 +77,7 @@ class DateTimeFieldTest extends WebTestBase {
'label' => 'hidden', 'label' => 'hidden',
'settings' => array('format_type' => 'medium'), 'settings' => array('format_type' => 'medium'),
); );
entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($this->fieldStorage->name, $this->display_options) ->setComponent($this->fieldStorage->name, $this->display_options)
->save(); ->save();
} }
@ -123,7 +123,7 @@ class DateTimeFieldTest extends WebTestBase {
foreach ($values as $new_value) { foreach ($values as $new_value) {
// Update the entity display settings. // Update the entity display settings.
$this->display_options['settings'] = array($setting => $new_value); $this->display_options['settings'] = array($setting => $new_value);
entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($field_name, $this->display_options) ->setComponent($field_name, $this->display_options)
->save(); ->save();
@ -141,7 +141,7 @@ class DateTimeFieldTest extends WebTestBase {
// Verify that the plain formatter works. // Verify that the plain formatter works.
$this->display_options['type'] = 'datetime_plain'; $this->display_options['type'] = 'datetime_plain';
entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($field_name, $this->display_options) ->setComponent($field_name, $this->display_options)
->save(); ->save();
$expected = $date->format(DATETIME_DATE_STORAGE_FORMAT); $expected = $date->format(DATETIME_DATE_STORAGE_FORMAT);
@ -190,7 +190,7 @@ class DateTimeFieldTest extends WebTestBase {
foreach ($values as $new_value) { foreach ($values as $new_value) {
// Update the entity display settings. // Update the entity display settings.
$this->display_options['settings'] = array($setting => $new_value); $this->display_options['settings'] = array($setting => $new_value);
entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($field_name, $this->display_options) ->setComponent($field_name, $this->display_options)
->save(); ->save();
@ -208,7 +208,7 @@ class DateTimeFieldTest extends WebTestBase {
// Verify that the plain formatter works. // Verify that the plain formatter works.
$this->display_options['type'] = 'datetime_plain'; $this->display_options['type'] = 'datetime_plain';
entity_get_display($this->instance->entity_type, $this->instance->bundle, 'full') entity_get_display($this->field->entity_type, $this->field->bundle, 'full')
->setComponent($field_name, $this->display_options) ->setComponent($field_name, $this->display_options)
->save(); ->save();
$expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT); $expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
@ -226,7 +226,7 @@ class DateTimeFieldTest extends WebTestBase {
$this->fieldStorage->save(); $this->fieldStorage->save();
// Change the widget to a datelist widget. // Change the widget to a datelist widget.
entity_get_form_display($this->instance->entity_type, $this->instance->bundle, 'default') entity_get_form_display($this->field->entity_type, $this->field->bundle, 'default')
->setComponent($field_name, array( ->setComponent($field_name, array(
'type' => 'datetime_datelist', 'type' => 'datetime_datelist',
'settings' => array( 'settings' => array(
@ -297,17 +297,17 @@ class DateTimeFieldTest extends WebTestBase {
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'date_content', 'bundle' => 'date_content',
)); ));
$instance->save(); $field->save();
// Set now as default_value. // Set now as default_value.
$instance_edit = array( $field_edit = array(
'default_value_input[default_date_type]' => 'now', 'default_value_input[default_date_type]' => 'now',
); );
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $instance_edit, t('Save settings')); $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form. // Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name); $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name);
@ -315,7 +315,7 @@ class DateTimeFieldTest extends WebTestBase {
$this->assertFieldByName('default_value_input[default_date]', '', 'The relative default value is empty in instance settings page'); $this->assertFieldByName('default_value_input[default_date]', '', 'The relative default value is empty in instance settings page');
// Check if default_date has been stored successfully. // Check if default_date has been stored successfully.
$config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field_storage->name)->get(); $config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_storage->name)->get();
$this->assertEqual($config_entity['default_value'][0], array('default_date_type' => 'now', 'default_date' => 'now'), 'Default value has been stored successfully'); $this->assertEqual($config_entity['default_value'][0], array('default_date_type' => 'now', 'default_date' => 'now'), 'Default value has been stored successfully');
// Clear field cache in order to avoid stale cache values. // Clear field cache in order to avoid stale cache values.
@ -327,20 +327,20 @@ class DateTimeFieldTest extends WebTestBase {
$this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT)); $this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
// Set an invalid relative default_value to test validation. // Set an invalid relative default_value to test validation.
$instance_edit = array( $field_edit = array(
'default_value_input[default_date_type]' => 'relative', 'default_value_input[default_date_type]' => 'relative',
'default_value_input[default_date]' => 'invalid date', 'default_value_input[default_date]' => 'invalid date',
); );
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $instance_edit, t('Save settings')); $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
$this->assertText('The relative date value entered is invalid.'); $this->assertText('The relative date value entered is invalid.');
// Set a relative default_value. // Set a relative default_value.
$instance_edit = array( $field_edit = array(
'default_value_input[default_date_type]' => 'relative', 'default_value_input[default_date_type]' => 'relative',
'default_value_input[default_date]' => '+90 days', 'default_value_input[default_date]' => '+90 days',
); );
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $instance_edit, t('Save settings')); $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form. // Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name); $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name);
@ -348,7 +348,7 @@ class DateTimeFieldTest extends WebTestBase {
$this->assertFieldByName('default_value_input[default_date]', '+90 days', 'The relative default value is displayed in instance settings page'); $this->assertFieldByName('default_value_input[default_date]', '+90 days', 'The relative default value is displayed in instance settings page');
// Check if default_date has been stored successfully. // Check if default_date has been stored successfully.
$config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field_storage->name)->get(); $config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_storage->name)->get();
$this->assertEqual($config_entity['default_value'][0], array('default_date_type' => 'relative', 'default_date' => '+90 days'), 'Default value has been stored successfully'); $this->assertEqual($config_entity['default_value'][0], array('default_date_type' => 'relative', 'default_date' => '+90 days'), 'Default value has been stored successfully');
// Clear field cache in order to avoid stale cache values. // Clear field cache in order to avoid stale cache values.
@ -360,10 +360,10 @@ class DateTimeFieldTest extends WebTestBase {
$this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT)); $this->assertEqual($new_node->get($field_storage->name)->offsetGet(0)->value, $expected_date->format(DATETIME_DATE_STORAGE_FORMAT));
// Remove default value. // Remove default value.
$instance_edit = array( $field_edit = array(
'default_value_input[default_date_type]' => '', 'default_value_input[default_date_type]' => '',
); );
$this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $instance_edit, t('Save settings')); $this->drupalPostForm('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form. // Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name); $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_storage->name);
@ -371,7 +371,7 @@ class DateTimeFieldTest extends WebTestBase {
$this->assertFieldByName('default_value_input[default_date]', '', 'The relative default value is empty in instance settings page'); $this->assertFieldByName('default_value_input[default_date]', '', 'The relative default value is empty in instance settings page');
// Check if default_date has been stored successfully. // Check if default_date has been stored successfully.
$config_entity = $this->container->get('config.factory')->get('field.instance.node.date_content.' . $field_storage->name)->get(); $config_entity = $this->container->get('config.factory')->get('field.field.node.date_content.' . $field_storage->name)->get();
$this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully'); $this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully');
// Clear field cache in order to avoid stale cache values. // Clear field cache in order to avoid stale cache values.

View File

@ -36,14 +36,14 @@ class DateTimeItemTest extends FieldUnitTestBase {
'settings' => array('datetime_type' => 'date'), 'settings' => array('datetime_type' => 'date'),
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'entity_test', 'bundle' => 'entity_test',
'settings' => array( 'settings' => array(
'default_value' => 'blank', 'default_value' => 'blank',
), ),
)); ));
$instance->save(); $field->save();
} }
/** /**

View File

@ -72,7 +72,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
// Create a field. // Create a field.
$this->field_name = 'field_textarea'; $this->field_name = 'field_textarea';
$this->createFieldWithInstance( $this->createFieldWithStorage(
$this->field_name, 'text', 1, 'Long text field', $this->field_name, 'text', 1, 'Long text field',
// Instance settings. // Instance settings.
array(), array(),

View File

@ -1,6 +1,6 @@
# Schema for the configuration files of the Entity Reference module. # Schema for the configuration files of the Entity Reference module.
field.entity_reference.settings: field.entity_reference.storage_settings:
type: mapping type: mapping
label: 'Entity reference settings' label: 'Entity reference settings'
mapping: mapping:
@ -8,7 +8,7 @@ field.entity_reference.settings:
type: string type: string
label: 'Type of item to reference' label: 'Type of item to reference'
field.entity_reference.instance_settings: field.entity_reference.field_settings:
type: mapping type: mapping
label: 'Entity reference settings' label: 'Entity reference settings'
mapping: mapping:

View File

@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element; use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
/** /**
@ -85,7 +85,7 @@ function entity_reference_field_storage_config_update(FieldStorageConfigInterfac
} }
if (empty($field_storage->bundles)) { if (empty($field_storage->bundles)) {
// Field has no instances. // Field storage has no fields.
return; return;
} }
@ -93,31 +93,31 @@ function entity_reference_field_storage_config_update(FieldStorageConfigInterfac
foreach ($field_storage->bundles() as $entity_type => $bundles) { foreach ($field_storage->bundles() as $entity_type => $bundles) {
foreach ($bundles as $bundle) { foreach ($bundles as $bundle) {
$instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); $field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
$instance->settings['handler_settings'] = array(); $field->settings['handler_settings'] = array();
$instance->save(); $field->save();
} }
} }
} }
/** /**
* Render API callback: Processes the field instance settings form and allows * Render API callback: Processes the field settings form and allows access to
* access to the form state. * the form state.
* *
* @see entity_reference_field_instance_settings_form() * @see entity_reference_field_field_settings_form()
*/ */
function _entity_reference_field_instance_settings_ajax_process($form, FormStateInterface $form_state) { function _entity_reference_field_field_settings_ajax_process($form, FormStateInterface $form_state) {
_entity_reference_field_instance_settings_ajax_process_element($form, $form); _entity_reference_field_field_settings_ajax_process_element($form, $form);
return $form; return $form;
} }
/** /**
* Adds entity_reference specific properties to AJAX form elements from the * Adds entity_reference specific properties to AJAX form elements from the
* field instance settings form. * field settings form.
* *
* @see _entity_reference_field_instance_settings_ajax_process() * @see _entity_reference_field_field_settings_ajax_process()
*/ */
function _entity_reference_field_instance_settings_ajax_process_element(&$element, $main_form) { function _entity_reference_field_field_settings_ajax_process_element(&$element, $main_form) {
if (!empty($element['#ajax'])) { if (!empty($element['#ajax'])) {
$element['#ajax'] = array( $element['#ajax'] = array(
'callback' => 'entity_reference_settings_ajax', 'callback' => 'entity_reference_settings_ajax',
@ -127,7 +127,7 @@ function _entity_reference_field_instance_settings_ajax_process_element(&$elemen
} }
foreach (Element::children($element) as $key) { foreach (Element::children($element) as $key) {
_entity_reference_field_instance_settings_ajax_process_element($element[$key], $main_form); _entity_reference_field_field_settings_ajax_process_element($element[$key], $main_form);
} }
} }
@ -156,7 +156,7 @@ function _entity_reference_element_validate_filter(&$element, FormStateInterface
/** /**
* Ajax callback for the handler settings form. * Ajax callback for the handler settings form.
* *
* @see entity_reference_field_instance_settings_form() * @see entity_reference_field_field_settings_form()
*/ */
function entity_reference_settings_ajax($form, FormStateInterface $form_state) { function entity_reference_settings_ajax($form, FormStateInterface $form_state) {
return NestedArray::getValue($form, $form_state->getTriggeringElement()['#ajax']['element']); return NestedArray::getValue($form, $form_state->getTriggeringElement()['#ajax']['element']);
@ -165,7 +165,7 @@ function entity_reference_settings_ajax($form, FormStateInterface $form_state) {
/** /**
* Submit handler for the non-JS case. * Submit handler for the non-JS case.
* *
* @see entity_reference_field_instance_settings_form() * @see entity_reference_field_field_settings_form()
*/ */
function entity_reference_settings_ajax_submit($form, FormStateInterface $form_state) { function entity_reference_settings_ajax_submit($form, FormStateInterface $form_state) {
$form_state->setRebuild(); $form_state->setRebuild();
@ -180,17 +180,17 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
} }
/** /**
* Creates an instance of a entity reference field on the specified bundle. * Creates a field of an entity reference field storage on the specified bundle.
* *
* @param string $entity_type * @param string $entity_type
* The type of entity the field instance will be attached to. * The type of entity the field will be attached to.
* @param string $bundle * @param string $bundle
* The bundle name of the entity the field instance will be attached to. * The bundle name of the entity the field will be attached to.
* @param string $field_name * @param string $field_name
* The name of the field; if it already exists, a new instance of the existing * The name of the field; if it already exists, a new instance of the existing
* field will be created. * field will be created.
* @param string $field_label * @param string $field_label
* The label of the field instance. * The label of the field.
* @param string $target_entity_type * @param string $target_entity_type
* The type of the referenced entity. * The type of the referenced entity.
* @param string $selection_handler * @param string $selection_handler
@ -203,10 +203,10 @@ function entity_reference_query_entity_reference_alter(AlterableInterface $query
* *
* @see \Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase::settingsForm() * @see \Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase::settingsForm()
*/ */
function entity_reference_create_instance($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) { function entity_reference_create_field($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = array(), $cardinality = 1) {
// Look for or add the specified field to the requested entity bundle. // Look for or add the specified field to the requested entity bundle.
$field_storage = FieldStorageConfig::loadByName($entity_type, $field_name); $field_storage = FieldStorageConfig::loadByName($entity_type, $field_name);
$instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name); $field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
if (empty($field_storage)) { if (empty($field_storage)) {
$field_storage = array( $field_storage = array(
@ -221,8 +221,8 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f
entity_create('field_storage_config', $field_storage)->save(); entity_create('field_storage_config', $field_storage)->save();
} }
if (empty($instance)) { if (empty($field)) {
$instance = array( $field = array(
'field_name' => $field_name, 'field_name' => $field_name,
'entity_type' => $entity_type, 'entity_type' => $entity_type,
'bundle' => $bundle, 'bundle' => $bundle,
@ -232,7 +232,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f
'handler_settings' => $selection_handler_settings, 'handler_settings' => $selection_handler_settings,
), ),
); );
entity_create('field_instance_config', $instance)->save(); entity_create('field_config', $field)->save();
} }
} }

View File

@ -34,8 +34,8 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultSettings() { public static function defaultStorageSettings() {
$settings = parent::defaultSettings(); $settings = parent::defaultStorageSettings();
// The target bundle is handled by the 'target_bundles' property in the // The target bundle is handled by the 'target_bundles' property in the
// 'handler_settings' instance setting. // 'handler_settings' instance setting.
unset($settings['target_bundle']); unset($settings['target_bundle']);
@ -45,10 +45,10 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function defaultInstanceSettings() { public static function defaultFieldSettings() {
return array( return array(
'handler_settings' => array(), 'handler_settings' => array(),
) + parent::defaultInstanceSettings(); ) + parent::defaultFieldSettings();
} }
/** /**
@ -160,7 +160,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element['target_type'] = array( $element['target_type'] = array(
'#type' => 'select', '#type' => 'select',
'#title' => t('Type of item to reference'), '#title' => t('Type of item to reference'),
@ -177,8 +177,8 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function instanceSettingsForm(array $form, FormStateInterface $form_state) { public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$instance = $form_state->get('instance'); $field = $form_state->get('field');
// Get all selection plugins for this entity type. // Get all selection plugins for this entity type.
$selection_plugins = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionGroups($this->getSetting('target_type')); $selection_plugins = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionGroups($this->getSetting('target_type'));
@ -198,9 +198,9 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
$form = array( $form = array(
'#type' => 'container', '#type' => 'container',
'#process' => array( '#process' => array(
'_entity_reference_field_instance_settings_ajax_process', '_entity_reference_field_field_settings_ajax_process',
), ),
'#element_validate' => array(array(get_class($this), 'instanceSettingsFormValidate')), '#element_validate' => array(array(get_class($this), 'fieldSettingsFormValidate')),
); );
$form['handler'] = array( $form['handler'] = array(
'#type' => 'details', '#type' => 'details',
@ -214,7 +214,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
'#type' => 'select', '#type' => 'select',
'#title' => t('Reference method'), '#title' => t('Reference method'),
'#options' => $handlers_options, '#options' => $handlers_options,
'#default_value' => $instance->getSetting('handler'), '#default_value' => $field->getSetting('handler'),
'#required' => TRUE, '#required' => TRUE,
'#ajax' => TRUE, '#ajax' => TRUE,
'#limit_validation_errors' => array(), '#limit_validation_errors' => array(),
@ -234,8 +234,8 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
'#attributes' => array('class' => array('entity_reference-settings')), '#attributes' => array('class' => array('entity_reference-settings')),
); );
$handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($instance); $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($field);
$form['handler']['handler_settings'] += $handler->settingsForm($instance); $form['handler']['handler_settings'] += $handler->settingsForm($field);
return $form; return $form;
} }
@ -248,10 +248,10 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
* @param \Drupal\Core\Form\FormStateInterface $form_state * @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state of the (entire) configuration form. * The form state of the (entire) configuration form.
*/ */
public static function instanceSettingsFormValidate(array $form, FormStateInterface $form_state) { public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {
if ($form_state->hasValue('instance')) { if ($form_state->hasValue('field')) {
$form_state->unsetValue(array('instance', 'settings', 'handler_submit')); $form_state->unsetValue(array('field', 'settings', 'handler_submit'));
$form_state->get('instance')->settings = $form_state->getValue(['instance', 'settings']); $form_state->get('field')->settings = $form_state->getValue(['field', 'settings']);
} }
} }

View File

@ -11,7 +11,7 @@ use Drupal\Component\Utility\Tags;
use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\entity_reference\Plugin\Type\SelectionPluginManager; use Drupal\entity_reference\Plugin\Type\SelectionPluginManager;
use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/** /**
@ -47,7 +47,7 @@ class EntityReferenceAutocomplete {
} }
/** /**
* Returns matched labels based on a given field, instance and search string. * Returns matched labels based on a given search string.
* *
* This function can be used by other modules that wish to pass a mocked * This function can be used by other modules that wish to pass a mocked
* definition of the field on instance. * definition of the field on instance.

View File

@ -64,7 +64,7 @@ class EntityReferenceController extends ControllerBase {
* Defaults to ''. * Defaults to ''.
* *
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* Throws access denied when either the field or field instance does not * Throws access denied when either the field storage or field does not
* exists or the user does not have access to edit the field. * exists or the user does not have access to edit the field.
* *
* @return \Symfony\Component\HttpFoundation\JsonResponse * @return \Symfony\Component\HttpFoundation\JsonResponse

View File

@ -117,7 +117,7 @@ class SelectionBase implements SelectionInterface {
$bundle_fields = array_filter($entity_manager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) { $bundle_fields = array_filter($entity_manager->getFieldDefinitions($entity_type_id, $bundle), function ($field_definition) {
return !$field_definition->isComputed(); return !$field_definition->isComputed();
}); });
foreach ($bundle_fields as $instance_name => $field_definition) { foreach ($bundle_fields as $field_name => $field_definition) {
/* @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */ /* @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
$columns = $field_definition->getFieldStorageDefinition()->getColumns(); $columns = $field_definition->getFieldStorageDefinition()->getColumns();
// If there is more than one column, display them all, otherwise just // If there is more than one column, display them all, otherwise just
@ -125,11 +125,11 @@ class SelectionBase implements SelectionInterface {
// @todo: Use property labels instead of the column name. // @todo: Use property labels instead of the column name.
if (count($columns) > 1) { if (count($columns) > 1) {
foreach ($columns 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)); $fields[$field_name . '.' . $column_name] = t('@label (@column)', array('@label' => $field_definition->getLabel(), '@column' => $column_name));
} }
} }
else { else {
$fields[$instance_name] = t('@label', array('@label' => $field_definition->getLabel())); $fields[$field_name] = t('@label', array('@label' => $field_definition->getLabel()));
} }
} }
} }

View File

@ -54,48 +54,48 @@ class EntityReferenceAdminTest extends WebTestBase {
), t('Save')); ), t('Save'));
// Node should be selected by default. // Node should be selected by default.
$this->assertFieldByName('field[settings][target_type]', 'node'); $this->assertFieldByName('field_storage[settings][target_type]', 'node');
// Check that all entity types can be referenced. // Check that all entity types can be referenced.
$this->assertFieldSelectOptions('field[settings][target_type]', array_keys(\Drupal::entityManager()->getDefinitions())); $this->assertFieldSelectOptions('field_storage[settings][target_type]', array_keys(\Drupal::entityManager()->getDefinitions()));
// Second step: 'Instance settings' form. // Second step: 'Field settings' form.
$this->drupalPostForm(NULL, array(), t('Save field settings')); $this->drupalPostForm(NULL, array(), t('Save field settings'));
// The base handler should be selected by default. // The base handler should be selected by default.
$this->assertFieldByName('instance[settings][handler]', 'default'); $this->assertFieldByName('field[settings][handler]', 'default');
// The base handler settings should be displayed. // The base handler settings should be displayed.
$entity_type_id = 'node'; $entity_type_id = 'node';
$bundles = entity_get_bundles($entity_type_id); $bundles = entity_get_bundles($entity_type_id);
foreach ($bundles as $bundle_name => $bundle_info) { foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertFieldByName('instance[settings][handler_settings][target_bundles][' . $bundle_name . ']'); $this->assertFieldByName('field[settings][handler_settings][target_bundles][' . $bundle_name . ']');
} }
reset($bundles); reset($bundles);
// Test the sort settings. // Test the sort settings.
// Option 0: no sort. // Option 0: no sort.
$this->assertFieldByName('instance[settings][handler_settings][sort][field]', '_none'); $this->assertFieldByName('field[settings][handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('instance[settings][handler_settings][sort][direction]'); $this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
// Option 1: sort by field. // Option 1: sort by field.
$this->drupalPostAjaxForm(NULL, array('instance[settings][handler_settings][sort][field]' => 'nid'), 'instance[settings][handler_settings][sort][field]'); $this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => 'nid'), 'field[settings][handler_settings][sort][field]');
$this->assertFieldByName('instance[settings][handler_settings][sort][direction]', 'ASC'); $this->assertFieldByName('field[settings][handler_settings][sort][direction]', 'ASC');
// Test that a non-translatable base field is a sort option. // Test that a non-translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='instance[settings][handler_settings][sort][field]']/option[@value='nid']"); $this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='nid']");
// Test that a translatable base field is a sort option. // Test that a translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='instance[settings][handler_settings][sort][field]']/option[@value='title']"); $this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='title']");
// Test that a configurable field is a sort option. // Test that a configurable field is a sort option.
$this->assertFieldByXPath("//select[@name='instance[settings][handler_settings][sort][field]']/option[@value='body.value']"); $this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='body.value']");
// Set back to no sort. // Set back to no sort.
$this->drupalPostAjaxForm(NULL, array('instance[settings][handler_settings][sort][field]' => '_none'), 'instance[settings][handler_settings][sort][field]'); $this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => '_none'), 'field[settings][handler_settings][sort][field]');
$this->assertNoFieldByName('instance[settings][handler_settings][sort][direction]'); $this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
// Third step: confirm. // Third step: confirm.
$this->drupalPostForm(NULL, array( $this->drupalPostForm(NULL, array(
'instance[settings][handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles), 'field[settings][handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles),
), t('Save settings')); ), t('Save settings'));
// Check that the field appears in the overview form. // Check that the field appears in the overview form.
@ -191,12 +191,12 @@ class EntityReferenceAdminTest extends WebTestBase {
), t('Save')); ), t('Save'));
// Select the correct target type given in the parameters and save field settings. // Select the correct target type given in the parameters and save field settings.
$this->drupalPostForm(NULL, array('field[settings][target_type]' => $target_type), t('Save field settings')); $this->drupalPostForm(NULL, array('field_storage[settings][target_type]' => $target_type), t('Save field settings'));
// Select required fields if there are any. // Select required fields if there are any.
$edit = array(); $edit = array();
if($bundle) { if($bundle) {
$edit['instance[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE; $edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
} }
// Save settings. // Save settings.

View File

@ -41,7 +41,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'label' => 'Entity reference field', 'label' => 'Entity reference field',
'field_name' => 'test_field', 'field_name' => 'test_field',
'entity_type' => 'node', 'entity_type' => 'node',

View File

@ -53,7 +53,7 @@ class EntityReferenceAutocompleteTest extends EntityUnitTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
entity_reference_create_instance($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType); entity_reference_create_field($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);
} }
/** /**

View File

@ -49,7 +49,7 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
'settings' => array('target_type' => 'node'), 'settings' => array('target_type' => 'node'),
)); ));
$this->fieldStorage->save(); $this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array( $this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage, 'field_storage' => $this->fieldStorage,
'bundle' => 'reference_content', 'bundle' => 'reference_content',
'settings' => array( 'settings' => array(
@ -60,20 +60,20 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
), ),
), ),
)); ));
$this->instance->save(); $this->field->save();
// Set created node as default_value. // Set created node as default_value.
$instance_edit = array( $field_edit = array(
'default_value_input[' . $this->fieldStorage->name . '][0][target_id]' => $referenced_node->getTitle() . ' (' .$referenced_node->id() . ')', 'default_value_input[' . $this->fieldStorage->name . '][0][target_id]' => $referenced_node->getTitle() . ' (' .$referenced_node->id() . ')',
); );
$this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name, $instance_edit, t('Save settings')); $this->drupalPostForm('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name, $field_edit, t('Save settings'));
// Check that default value is selected in default value form. // Check that default value is selected in default value form.
$this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name); $this->drupalGet('admin/structure/types/manage/reference_content/fields/node.reference_content.' . $this->fieldStorage->name);
$this->assertRaw('name="default_value_input[' . $this->fieldStorage->name . '][0][target_id]" value="' . $referenced_node->getTitle() .' (' .$referenced_node->id() . ')', 'The default value is selected in instance settings page'); $this->assertRaw('name="default_value_input[' . $this->fieldStorage->name . '][0][target_id]" value="' . $referenced_node->getTitle() .' (' .$referenced_node->id() . ')', 'The default value is selected in instance settings page');
// Check if the ID has been converted to UUID in config entity. // Check if the ID has been converted to UUID in config entity.
$config_entity = $this->container->get('config.factory')->get('field.instance.node.reference_content.' . $this->fieldStorage->name)->get(); $config_entity = $this->container->get('config.factory')->get('field.field.node.reference_content.' . $this->fieldStorage->name)->get();
$this->assertTrue(isset($config_entity['default_value'][0]['target_uuid']), 'Default value contains target_uuid property'); $this->assertTrue(isset($config_entity['default_value'][0]['target_uuid']), 'Default value contains target_uuid property');
$this->assertEqual($config_entity['default_value'][0]['target_uuid'], $referenced_node->uuid(), 'Content uuid and config entity uuid are the same'); $this->assertEqual($config_entity['default_value'][0]['target_uuid'], $referenced_node->uuid(), 'Content uuid and config entity uuid are the same');

View File

@ -57,8 +57,8 @@ class EntityReferenceFieldTest extends EntityUnitTestBase {
$this->installEntitySchema('entity_test_rev'); $this->installEntitySchema('entity_test_rev');
// Setup a field and instance. // Create a field.
entity_reference_create_instance( entity_reference_create_field(
$this->entityType, $this->entityType,
$this->bundle, $this->bundle,
$this->fieldName, $this->fieldName,

View File

@ -54,7 +54,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
entity_reference_create_instance($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType); entity_reference_create_field($this->entityType, $this->bundle, $this->fieldName, 'Field test', $this->entityType);
// Set up a field, so that the entity that'll be referenced bubbles up a // Set up a field, so that the entity that'll be referenced bubbles up a
// cache tag when rendering it entirely. // cache tag when rendering it entirely.
@ -64,7 +64,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
'type' => 'text', 'type' => 'text',
'settings' => array(), 'settings' => array(),
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'entity_type' => $this->entityType, 'entity_type' => $this->entityType,
'bundle' => $this->bundle, 'bundle' => $this->bundle,
'field_name' => 'body', 'field_name' => 'body',

View File

@ -64,7 +64,7 @@ class EntityReferenceIntegrationTest extends WebTestBase {
$this->fieldName = 'field_test_' . $referenced_entities[0]->getEntityTypeId(); $this->fieldName = 'field_test_' . $referenced_entities[0]->getEntityTypeId();
// Create an Entity reference field. // Create an Entity reference field.
entity_reference_create_instance($this->entityType, $this->bundle, $this->fieldName, $this->fieldName, $referenced_entities[0]->getEntityTypeId(), 'default', array(), 2); entity_reference_create_field($this->entityType, $this->bundle, $this->fieldName, $this->fieldName, $referenced_entities[0]->getEntityTypeId(), 'default', array(), 2);
// Test the default 'entity_reference_autocomplete' widget. // Test the default 'entity_reference_autocomplete' widget.
entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save(); entity_get_form_display($this->entityType, $this->bundle, 'default')->setComponent($this->fieldName)->save();

View File

@ -63,8 +63,8 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$this->term->save(); $this->term->save();
// Use the util to create an instance. // Use the util to create an instance.
entity_reference_create_instance('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term'); entity_reference_create_field('entity_test', 'entity_test', 'field_test_taxonomy_term', 'Test content entity reference', 'taxonomy_term');
entity_reference_create_instance('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary'); entity_reference_create_field('entity_test', 'entity_test', 'field_test_taxonomy_vocabulary', 'Test config entity reference', 'taxonomy_vocabulary');
} }
/** /**

View File

@ -55,7 +55,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
* Test the node-specific overrides of the entity handler. * Test the node-specific overrides of the entity handler.
*/ */
public function testNodeHandler() { public function testNodeHandler() {
// Create a field storage and instance. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = entity_create('field_storage_config', array(
'name' => 'test_field', 'name' => 'test_field',
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
@ -68,7 +68,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'cardinality' => '1', 'cardinality' => '1',
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'test_bundle', 'bundle' => 'test_bundle',
'settings' => array( 'settings' => array(
@ -78,7 +78,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
)); ));
$instance->save(); $field->save();
// Build a set of test data. // Build a set of test data.
// Titles contain HTML-special characters to test escaping. // Titles contain HTML-special characters to test escaping.
@ -162,7 +162,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'result' => array(), 'result' => array(),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'Node handler'); $this->assertReferenceable($field, $referenceable_tests, 'Node handler');
// Test as an admin. // Test as an admin.
$admin_user = $this->drupalCreateUser(array('access content', 'bypass node access')); $admin_user = $this->drupalCreateUser(array('access content', 'bypass node access'));
@ -191,14 +191,14 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'Node handler (admin)'); $this->assertReferenceable($field, $referenceable_tests, 'Node handler (admin)');
} }
/** /**
* Test the user-specific overrides of the entity handler. * Test the user-specific overrides of the entity handler.
*/ */
public function testUserHandler() { public function testUserHandler() {
// Create a field storage and instance. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = entity_create('field_storage_config', array(
'name' => 'test_field', 'name' => 'test_field',
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
@ -210,7 +210,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'cardinality' => '1', 'cardinality' => '1',
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'test_bundle', 'bundle' => 'test_bundle',
'settings' => array( 'settings' => array(
@ -220,7 +220,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
)); ));
$instance->save(); $field->save();
// Build a set of test data. // Build a set of test data.
$user_values = array( $user_values = array(
@ -296,7 +296,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'result' => array(), 'result' => array(),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'User handler'); $this->assertReferenceable($field, $referenceable_tests, 'User handler');
\Drupal::currentUser()->setAccount($users['admin']); \Drupal::currentUser()->setAccount($users['admin']);
$referenceable_tests = array( $referenceable_tests = array(
@ -335,14 +335,14 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'User handler (admin)'); $this->assertReferenceable($field, $referenceable_tests, 'User handler (admin)');
} }
/** /**
* Test the comment-specific overrides of the entity handler. * Test the comment-specific overrides of the entity handler.
*/ */
public function testCommentHandler() { public function testCommentHandler() {
// Create a field storage and instance. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = entity_create('field_storage_config', array(
'name' => 'test_field', 'name' => 'test_field',
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
@ -355,7 +355,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'cardinality' => '1', 'cardinality' => '1',
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'test_bundle', 'bundle' => 'test_bundle',
'settings' => array( 'settings' => array(
@ -365,7 +365,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
)); ));
$instance->save(); $field->save();
// Build a set of test data. // Build a set of test data.
$node_values = array( $node_values = array(
@ -474,7 +474,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'result' => array(), 'result' => array(),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'Comment handler'); $this->assertReferenceable($field, $referenceable_tests, 'Comment handler');
// Test as a comment admin. // Test as a comment admin.
$admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments')); $admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments'));
@ -492,7 +492,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'Comment handler (comment admin)'); $this->assertReferenceable($field, $referenceable_tests, 'Comment handler (comment admin)');
// Test as a node and comment admin. // Test as a node and comment admin.
$admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments', 'bypass node access')); $admin_user = $this->drupalCreateUser(array('access content', 'access comments', 'administer comments', 'bypass node access'));
@ -511,6 +511,6 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
), ),
), ),
); );
$this->assertReferenceable($instance, $referenceable_tests, 'Comment handler (comment + node admin)'); $this->assertReferenceable($field, $referenceable_tests, 'Comment handler (comment + node admin)');
} }
} }

View File

@ -38,7 +38,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
'entity_types' => array('node'), 'entity_types' => array('node'),
))->save(); ))->save();
entity_create('field_instance_config', array( entity_create('field_config', array(
'label' => 'Text Field', 'label' => 'Text Field',
'field_name' => 'field_text', 'field_name' => 'field_text',
'entity_type' => 'node', 'entity_type' => 'node',
@ -48,7 +48,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
))->save(); ))->save();
// Create a field storage and instance. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = entity_create('field_storage_config', array(
'name' => 'test_field', 'name' => 'test_field',
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
@ -60,7 +60,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
'cardinality' => 1, 'cardinality' => 1,
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'bundle' => 'test_bundle', 'bundle' => 'test_bundle',
@ -76,7 +76,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
), ),
), ),
)); ));
$instance->save(); $field->save();
// Build a set of test data. // Build a set of test data.
$node_values = array( $node_values = array(
@ -117,7 +117,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
$normal_user = $this->drupalCreateUser(array('access content')); $normal_user = $this->drupalCreateUser(array('access content'));
\Drupal::currentUser()->setAccount($normal_user); \Drupal::currentUser()->setAccount($normal_user);
$handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance); $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($field);
// Not only assert the result, but make sure the keys are sorted as // Not only assert the result, but make sure the keys are sorted as
// expected. // expected.
@ -129,11 +129,11 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
$this->assertIdentical($result['article'], $expected_result, 'Query sorted by field returned expected values.'); $this->assertIdentical($result['article'], $expected_result, 'Query sorted by field returned expected values.');
// Assert sort by property. // Assert sort by property.
$instance->settings['handler_settings']['sort'] = array( $field->settings['handler_settings']['sort'] = array(
'field' => 'nid', 'field' => 'nid',
'direction' => 'ASC', 'direction' => 'ASC',
); );
$handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance); $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($field);
$result = $handler->getReferenceableEntities(); $result = $handler->getReferenceableEntities();
$expected_result = array( $expected_result = array(
$nodes['published1']->id() => $node_labels['published1'], $nodes['published1']->id() => $node_labels['published1'],

View File

@ -9,7 +9,7 @@ namespace Drupal\entity_reference\Tests\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig; use Drupal\field\Entity\FieldConfig;
use Drupal\views\Tests\ViewTestData; use Drupal\views\Tests\ViewTestData;
use Drupal\views\Tests\ViewUnitTestBase; use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Views; use Drupal\views\Views;
@ -64,7 +64,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase {
)); ));
$field_storage->save(); $field_storage->save();
$instance = FieldInstanceConfig::create(array( $field = FieldConfig::create(array(
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
'field_name' => 'field_test', 'field_name' => 'field_test',
'bundle' => 'entity_test', 'bundle' => 'entity_test',
@ -73,7 +73,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase {
'handler_settings' => array(), 'handler_settings' => array(),
), ),
)); ));
$instance->save(); $field->save();
// Create some test entities which link each other. // Create some test entities which link each other.
$entity_storage= \Drupal::entityManager()->getStorage('entity_test'); $entity_storage= \Drupal::entityManager()->getStorage('entity_test');

View File

@ -33,7 +33,7 @@ class SelectionTest extends WebTestBase {
$nodes[$node->getType()][$node->id()] = $node->label(); $nodes[$node->getType()][$node->id()] = $node->label();
} }
// Create a field storage and instance. // Create a field.
$field_storage = entity_create('field_storage_config', array( $field_storage = entity_create('field_storage_config', array(
'name' => 'test_field', 'name' => 'test_field',
'entity_type' => 'entity_test', 'entity_type' => 'entity_test',
@ -45,7 +45,7 @@ class SelectionTest extends WebTestBase {
'cardinality' => '1', 'cardinality' => '1',
)); ));
$field_storage->save(); $field_storage->save();
$instance = entity_create('field_instance_config', array( $field = entity_create('field_config', array(
'field_storage' => $field_storage, 'field_storage' => $field_storage,
'bundle' => 'test_bundle', 'bundle' => 'test_bundle',
'settings' => array( 'settings' => array(
@ -60,10 +60,10 @@ class SelectionTest extends WebTestBase {
), ),
), ),
)); ));
$instance->save(); $field->save();
// Get values from selection handler. // Get values from selection handler.
$handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($instance); $handler = $this->container->get('plugin.manager.entity_reference.selection')->getSelectionHandler($field);
$result = $handler->getReferenceableEntities(); $result = $handler->getReferenceableEntities();
$success = FALSE; $success = FALSE;

View File

@ -25,7 +25,7 @@ field.storage.*.*:
type: string type: string
label: 'Type' label: 'Type'
settings: settings:
type: field.[%parent.type].settings type: field.[%parent.type].storage_settings
module: module:
type: string type: string
label: 'Module' label: 'Module'
@ -48,6 +48,6 @@ field.storage.*.*:
- type: ignore - type: ignore
label: 'Index' label: 'Index'
field.instance.*.*.*: field.field.*.*.*:
type: field_config_base type: field_config_base
label: 'Field instance' label: 'Field'

View File

@ -294,19 +294,19 @@ function hook_field_purge_field_storage(\Drupal\field\Entity\FieldStorageConfig
} }
/** /**
* Acts when a field instance is being purged. * Acts when a field is being purged.
* *
* In field_purge_instance(), after the instance definition has been removed * In field_purge_field(), after the field definition has been removed
* from the the system, the entity storage has purged stored field data, and the * from the the system, the entity storage has purged stored field data, and the
* field info cache has been cleared, this hook is invoked on all modules to * field info cache has been cleared, this hook is invoked on all modules to
* allow them to respond to the field instance being purged. * allow them to respond to the field being purged.
* *
* @param $instance * @param $field
* The instance being purged. * The field being purged.
*/ */
function hook_field_purge_instance($instance) { function hook_field_purge_field(\Drupal\field\Entity\FieldConfig $field) {
db_delete('my_module_field_instance_info') db_delete('my_module_field_info')
->condition('id', $instance['id']) ->condition('id', $field->id())
->execute(); ->execute();
} }

View File

@ -29,9 +29,9 @@ require_once __DIR__ . '/field.purge.inc';
* interface for managing custom fields via a web browser as well as a wide and * interface for managing custom fields via a web browser as well as a wide and
* flexible variety of data type, form element, and display format capabilities. * flexible variety of data type, form element, and display format capabilities.
* *
* The Field API defines two primary data structures, Field and Instance, and * The Field API defines two primary data structures, FieldStorage and Field,
* the concept of a Bundle. A Field defines a particular type of data that can * and the concept of a Bundle. A FieldStorage defines a particular type of data
* be attached to entities. A Field Instance is a Field attached to a single * that can be attached to entities. A Field is attached to a single
* Bundle. A Bundle is a set of fields that are treated as a group by the Field * Bundle. A Bundle is a set of fields that are treated as a group by the Field
* Attach API and is related to a single fieldable entity type. * Attach API and is related to a single fieldable entity type.
* *
@ -51,7 +51,7 @@ require_once __DIR__ . '/field.purge.inc';
* and display formatters. * and display formatters.
* *
* - @link field_purge Field API bulk data deletion @endlink: Cleans up after * - @link field_purge Field API bulk data deletion @endlink: Cleans up after
* bulk deletion operations such as deletion of field or field_instance. * bulk deletion operations such as deletion of field storage or field.
*/ */
/** /**
@ -182,15 +182,15 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl
if ($entity_type->isFieldable()) { if ($entity_type->isFieldable()) {
// Query by filtering on the ID as this is more efficient than filtering // Query by filtering on the ID as this is more efficient than filtering
// on the entity_type property directly. // on the entity_type property directly.
$ids = \Drupal::entityQuery('field_instance_config') $ids = \Drupal::entityQuery('field_config')
->condition('id', $entity_type->id() . '.' . $bundle . '.', 'STARTS_WITH') ->condition('id', $entity_type->id() . '.' . $bundle . '.', 'STARTS_WITH')
->execute(); ->execute();
// Fetch all fields and key them by field name. // Fetch all fields and key them by field name.
$field_instance_configs = entity_load_multiple('field_instance_config', $ids); $field_configs = entity_load_multiple('field_config', $ids);
$result = array(); $result = array();
foreach ($field_instance_configs as $field_instance) { foreach ($field_configs as $field) {
$result[$field_instance->getName()] = $field_instance; $result[$field->getName()] = $field;
} }
return $result; return $result;
} }
@ -200,22 +200,22 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl
* Implements hook_entity_bundle_rename(). * Implements hook_entity_bundle_rename().
*/ */
function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
$instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old, 'include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old, 'include_deleted' => TRUE));
foreach ($instances as $instance) { foreach ($fields as $field) {
$id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->field_name; $id_new = $field->entity_type . '.' . $bundle_new . '.' . $field->field_name;
$instance->set('id', $id_new); $field->set('id', $id_new);
$instance->bundle = $bundle_new; $field->bundle = $bundle_new;
// Save non-deleted instances. // Save non-deleted fields.
if (!$instance->isDeleted()) { if (!$field->isDeleted()) {
$instance->allowBundleRename(); $field->allowBundleRename();
$instance->save(); $field->save();
} }
// Update deleted instances directly in the state storage. // Update deleted fields directly in the state storage.
else { else {
$state = \Drupal::state(); $state = \Drupal::state();
$deleted_instances = $state->get('field.instance.deleted') ?: array(); $deleted_fields = $state->get('field.field.deleted') ?: array();
$deleted_instances[$instance->uuid] = $instance->toArray(); $deleted_fields[$field->uuid] = $field->toArray();
$state->set('field.instance.deleted', $deleted_instances); $state->set('field.field.deleted', $deleted_fields);
} }
} }
} }
@ -223,20 +223,18 @@ function field_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
/** /**
* Implements hook_entity_bundle_delete(). * Implements hook_entity_bundle_delete().
* *
* This deletes the data for the field instances as well as the field instances * This deletes the data for the field as well as the field themselves. This
* themselves. This function actually just marks the data and field instances as * function actually just marks the data and fields as deleted, leaving the
* deleted, leaving the garbage collection for a separate process, because it is * garbage collection for a separate process, because it is not always
* not always possible to delete this much data in a single page request * possible to delete this much data in a single page request (particularly
* (particularly since for some field types, the deletion is more than just a * since for some field types, the deletion is more than just a simple DELETE
* simple DELETE query). * query).
*/ */
function field_entity_bundle_delete($entity_type, $bundle) { function field_entity_bundle_delete($entity_type, $bundle) {
// Get the instances on the bundle. entity_load_multiple_by_properties() must // Get the fields on the bundle.
// be used here since field_info_instances() does not return instances for $fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle));
// disabled entity types or bundles. foreach ($fields as $field) {
$instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle)); $field->delete();
foreach ($instances as $instance) {
$instance->delete();
} }
} }

View File

@ -8,6 +8,7 @@
use Drupal\Core\Field\FieldException; use Drupal\Core\Field\FieldException;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldConfigInterface;
/** /**
* @defgroup field_purge Field API bulk data deletion * @defgroup field_purge Field API bulk data deletion
@ -15,7 +16,7 @@ use Drupal\field\FieldStorageConfigInterface;
* Cleans up after Field API bulk deletion operations. * Cleans up after Field API bulk deletion operations.
* *
* Field API provides functions for deleting data attached to individual * Field API provides functions for deleting data attached to individual
* entities as well as deleting entire fields or field instances in a single * entities as well as deleting entire fields or field storages in a single
* operation. * operation.
* *
* When a single entity is deleted, the Entity storage performs the * When a single entity is deleted, the Entity storage performs the
@ -30,14 +31,14 @@ use Drupal\field\FieldStorageConfigInterface;
* *
* Similar operations are performed on deletion of a single entity revision. * Similar operations are performed on deletion of a single entity revision.
* *
* When a field, bundle, or field instance is deleted, it is not practical to * When a bundle, field or field storage is deleted, it is not practical to
* perform those operations immediately on every affected entity in a single * perform those operations immediately on every affected entity in a single
* page request; there could be thousands or millions of them. Instead, the * page request; there could be thousands or millions of them. Instead, the
* appropriate field data items, instances, and/or fields are marked as deleted * appropriate field data items, fields, and/or field storages are marked as
* so that subsequent load or query operations will not return them. Later, a * deleted so that subsequent load or query operations will not return them.
* separate process cleans up, or "purges", the marked-as-deleted data by going * Later, a separate process cleans up, or "purges", the marked-as-deleted data
* through the three-step process described above and, finally, removing deleted * by going through the three-step process described above and, finally,
* field and instance records. * removing deleted field storage and field records.
* *
* Purging field data is made somewhat tricky by the fact that, while * Purging field data is made somewhat tricky by the fact that, while
* $entity->delete() has a complete entity to pass to the various deletion * $entity->delete() has a complete entity to pass to the various deletion
@ -50,22 +51,21 @@ use Drupal\field\FieldStorageConfigInterface;
* Field API resolves this problem by using stub entities during purge * Field API resolves this problem by using stub entities during purge
* operations, containing only the information from the original entity that * operations, containing only the information from the original entity that
* Field API knows about: entity type, ID, revision ID, and bundle. It also * Field API knows about: entity type, ID, revision ID, and bundle. It also
* contains the field data for whichever field instance is currently being * contains the field data for whichever field is currently being purged.
* purged.
* *
* See @link field Field API @endlink for information about the other parts of * See @link field Field API @endlink for information about the other parts of
* the Field API. * the Field API.
*/ */
/** /**
* Purges a batch of deleted Field API data, instances, or fields. * Purges a batch of deleted Field API data, field storages, or fields.
* *
* This function will purge deleted field data in batches. The batch size * This function will purge deleted field data in batches. The batch size
* is defined as an argument to the function, and once each batch is finished, * is defined as an argument to the function, and once each batch is finished,
* it continues with the next batch until all have completed. If a deleted field * it continues with the next batch until all have completed. If a deleted field
* instance with no remaining data records is found, the instance itself will * with no remaining data records is found, the field itself will
* be purged. If a deleted field with no remaining field instances is found, the * be purged. If a deleted field storage with no remaining fields is found, the
* field itself will be purged. * field storage itself will be purged.
* *
* @param $batch_size * @param $batch_size
* The maximum number of field data records to purge before returning. * The maximum number of field data records to purge before returning.
@ -80,11 +80,11 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
if ($field_storage_uuid) { if ($field_storage_uuid) {
$properties['field_storage_uuid'] = $field_storage_uuid; $properties['field_storage_uuid'] = $field_storage_uuid;
} }
$instances = entity_load_multiple_by_properties('field_instance_config', $properties); $fields = entity_load_multiple_by_properties('field_config', $properties);
$info = \Drupal::entityManager()->getDefinitions(); $info = \Drupal::entityManager()->getDefinitions();
foreach ($instances as $instance) { foreach ($fields as $field) {
$entity_type = $instance->entity_type; $entity_type = $field->entity_type;
// We cannot purge anything if the entity type is unknown (e.g. the // We cannot purge anything if the entity type is unknown (e.g. the
// providing module was uninstalled). // providing module was uninstalled).
@ -93,10 +93,10 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
continue; continue;
} }
$count_purged = \Drupal::entityManager()->getStorage($entity_type)->purgeFieldData($instance, $batch_size); $count_purged = \Drupal::entityManager()->getStorage($entity_type)->purgeFieldData($field, $batch_size);
if ($count_purged < $batch_size || $count_purged == 0) { if ($count_purged < $batch_size || $count_purged == 0) {
// No field data remains for the instance, so we can remove it. // No field data remains for the field, so we can remove it.
field_purge_instance($instance); field_purge_field($field);
} }
$batch_size -= $count_purged; $batch_size -= $count_purged;
// Only delete up to the maximum number of records. // Only delete up to the maximum number of records.
@ -105,8 +105,7 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
} }
} }
// Retrieve all deleted field storages. Any that have no instances can be // Retrieve all deleted field storages. Any that have no fields can be purged.
// purged.
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array(); $deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array();
foreach ($deleted_storages as $field_storage) { foreach ($deleted_storages as $field_storage) {
$field_storage = new FieldStorageConfig($field_storage); $field_storage = new FieldStorageConfig($field_storage);
@ -122,45 +121,47 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
continue; continue;
} }
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
if (empty($instances)) { if (empty($fields)) {
field_purge_field_storage($field_storage); field_purge_field_storage($field_storage);
} }
} }
} }
/** /**
* Purges a field instance record from the database. * Purges a field record from the database.
* *
* This function assumes all data for the instance has already been purged and * This function assumes all data for the field has already been purged and
* should only be called by field_purge_batch(). * should only be called by field_purge_batch().
* *
* @param $instance * @param $field
* The instance record to purge. * The field record to purge.
*/ */
function field_purge_instance($instance) { function field_purge_field(FieldConfigInterface $field) {
$state = \Drupal::state(); $state = \Drupal::state();
$deleted_instances = $state->get('field.instance.deleted'); $deleted_fields = $state->get('field.field.deleted');
unset($deleted_instances[$instance->uuid()]); unset($deleted_fields[$field->uuid()]);
$state->set('field.instance.deleted', $deleted_instances); $state->set('field.field.deleted', $deleted_fields);
// Invoke external hooks after the cache is cleared for API consistency. // Invoke external hooks after the cache is cleared for API consistency.
\Drupal::moduleHandler()->invokeAll('field_purge_instance', array($instance)); \Drupal::moduleHandler()->invokeAll('field_purge_field', array($field));
} }
/** /**
* Purges a field record from the database. * Purges a field record from the database.
* *
* This function assumes all instances for the field has already been purged, * This function assumes all fields for the field storage has already been
* and should only be called by field_purge_batch(). * purged, and should only be called by field_purge_batch().
* *
* @param \Drupal\field\FieldStorageConfigInterface $field_storage * @param \Drupal\field\FieldStorageConfigInterface $field_storage
* The field storage to purge. * The field storage to purge.
*
* @throws Drupal\field\FieldException
*/ */
function field_purge_field_storage(FieldStorageConfigInterface $field_storage) { function field_purge_field_storage(FieldStorageConfigInterface $field_storage) {
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE)); $fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
if (count($instances) > 0) { if (count($fields) > 0) {
throw new FieldException(t('Attempt to purge a field storage @field_name that still has instances.', array('@field_name' => $field_storage->getName()))); throw new FieldException(t('Attempt to purge a field storage @field_name that still has fields.', array('@field_name' => $field_storage->getName())));
} }
$state = \Drupal::state(); $state = \Drupal::state();

View File

@ -9,7 +9,7 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface;
/** /**
* Implements hook_views_data(). * Implements hook_views_data().
@ -79,19 +79,19 @@ function _field_views_get_entity_type_storage(FieldStorageConfigInterface $field
/** /**
* Returns the label of a certain field. * Returns the label of a certain field.
* *
* Therefore it looks up in all bundles to find the most used instance. * Therefore it looks up in all bundles to find the most used field.
*/ */
function field_views_field_label($entity_type, $field_name) { function field_views_field_label($entity_type, $field_name) {
$label_counter = array(); $label_counter = array();
$all_labels = array(); $all_labels = array();
// Count the amount of instances per label per field. // Count the amount of fields per label per field storage.
foreach (array_keys(\Drupal::entityManager()->getBundleInfo($entity_type)) as $bundle) { foreach (array_keys(\Drupal::entityManager()->getBundleInfo($entity_type)) as $bundle) {
$bundle_instances = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) { $bundle_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
return $field_definition instanceof FieldInstanceConfigInterface; return $field_definition instanceof FieldConfigInterface;
}); });
if (isset($bundle_instances[$field_name])) { if (isset($bundle_fields[$field_name])) {
$instance = $bundle_instances[$field_name]; $field = $bundle_fields[$field_name];
$label = $instance->getLabel(); $label = $field->getLabel();
$label_counter[$label] = isset($label_counter[$label]) ? ++$label_counter[$label] : 1; $label_counter[$label] = isset($label_counter[$label]) ? ++$label_counter[$label] : 1;
$all_labels[$label] = TRUE; $all_labels[$label] = TRUE;
} }
@ -121,7 +121,7 @@ function field_views_field_default_views_data(FieldStorageConfigInterface $field
if (!\Drupal::service('plugin.manager.field.field_type')->hasDefinition($field_storage->getType())) { if (!\Drupal::service('plugin.manager.field.field_type')->hasDefinition($field_storage->getType())) {
return $data; return $data;
} }
// Check the field has instances. // Check the field storage has fields.
if (!$field_storage->getBundles()) { if (!$field_storage->getBundles()) {
return $data; return $data;
} }
@ -236,7 +236,7 @@ function field_views_field_default_views_data(FieldStorageConfigInterface $field
$add_fields[] = $table_mapping->getFieldColumnName($field_storage, $column); $add_fields[] = $table_mapping->getFieldColumnName($field_storage, $column);
} }
// Determine the label to use for the field. We don't have a label available // Determine the label to use for the field. We don't have a label available
// at the field level, so we just go through all instances and take the one // at the field level, so we just go through all fields and take the one
// which is used the most frequently. // which is used the most frequently.
list($label, $all_labels) = field_views_field_label($entity_type_id, $field_name); list($label, $all_labels) = field_views_field_label($entity_type_id, $field_name);

View File

@ -87,7 +87,7 @@ class ConfigImporterFieldPurger {
} }
} }
// Each field possibly needs one last field_purge_batch() call to remove the // Each field possibly needs one last field_purge_batch() call to remove the
// last instance and the field itself. // last field and the field storage itself.
$context['sandbox']['field']['steps_to_delete'] += count($fields); $context['sandbox']['field']['steps_to_delete'] += count($fields);
$context['sandbox']['field']['current_progress'] = 0; $context['sandbox']['field']['current_progress'] = 0;

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains \Drupal\field\Entity\FieldInstanceConfig. * Contains \Drupal\field\Entity\FieldConfig.
*/ */
namespace Drupal\field\Entity; namespace Drupal\field\Entity;
@ -12,36 +12,36 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldConfigBase; use Drupal\Core\Field\FieldConfigBase;
use Drupal\Core\Field\FieldException; use Drupal\Core\Field\FieldException;
use Drupal\field\FieldStorageConfigInterface; use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldInstanceConfigInterface; use Drupal\field\FieldConfigInterface;
/** /**
* Defines the Field instance entity. * Defines the Field entity.
* *
* @ConfigEntityType( * @ConfigEntityType(
* id = "field_instance_config", * id = "field_config",
* label = @Translation("Field instance"), * label = @Translation("Field"),
* handlers = { * handlers = {
* "access" = "Drupal\field\FieldInstanceConfigAccessControlHandler", * "access" = "Drupal\field\FieldConfigAccessControlHandler",
* "storage" = "Drupal\field\FieldInstanceConfigStorage" * "storage" = "Drupal\field\FieldConfigStorage"
* }, * },
* config_prefix = "instance", * config_prefix = "field",
* entity_keys = { * entity_keys = {
* "id" = "id", * "id" = "id",
* "label" = "label" * "label" = "label"
* } * }
* ) * )
*/ */
class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfigInterface { class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
/** /**
* Flag indicating whether the instance is deleted. * Flag indicating whether the field is deleted.
* *
* The delete() method marks the instance as "deleted" and removes the * The delete() method marks the field as "deleted" and removes the
* corresponding entry from the config storage, but keeps its definition in * corresponding entry from the config storage, but keeps its definition in
* the state storage while field data is purged by a separate * the state storage while field data is purged by a separate
* garbage-collection process. * garbage-collection process.
* *
* Deleted instances stay out of the regular entity lifecycle (notably, their * Deleted fields stay out of the regular entity lifecycle (notably, their
* values are not populated in loaded entities, and are not saved back). * values are not populated in loaded entities, and are not saved back).
* *
* @var bool * @var bool
@ -49,40 +49,40 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
public $deleted = FALSE; public $deleted = FALSE;
/** /**
* The field ConfigEntity object this is an instance of. * The associated FieldStorageConfig entity.
* *
* @var \Drupal\field\Entity\FieldStorageConfig * @var \Drupal\field\Entity\FieldStorageConfig
*/ */
protected $fieldStorage; protected $fieldStorage;
/** /**
* Constructs a FieldInstanceConfig object. * Constructs a FieldConfig object.
* *
* In most cases, Field instance entities are created via * In most cases, Field entities are created via
* entity_create('field_instance_config', $values), where $values is the same * entity_create('field_config', $values), where $values is the same
* parameter as in this constructor. * parameter as in this constructor.
* *
* @param array $values * @param array $values
* An array of field instance properties, keyed by property name. The * An array of field properties, keyed by property name. The
* storage associated to the instance can be specified either with: * storage associated to the field can be specified either with:
* - field_storage: the FieldStorageConfigInterface object, * - field_storage: the FieldStorageConfigInterface object,
* or by referring to an existing field storage in the current configuration * or by referring to an existing field storage in the current configuration
* with: * with:
* - field_name: The field name. * - field_name: The field name.
* - entity_type: The entity type. * - entity_type: The entity type.
* Additionally, a 'bundle' property is required to indicate the entity * Additionally, a 'bundle' property is required to indicate the entity
* bundle to which the instance is attached to. Other array elements will be * bundle to which the field is attached to. Other array elements will be
* used to set the corresponding properties on the class; see the class * used to set the corresponding properties on the class; see the class
* property documentation for details. * property documentation for details.
* *
* @see entity_create() * @see entity_create()
*/ */
public function __construct(array $values, $entity_type = 'field_instance_config') { public function __construct(array $values, $entity_type = 'field_config') {
// Allow either an injected FieldStorageConfig object, or a field_name and // Allow either an injected FieldStorageConfig object, or a field_name and
// entity_type. // entity_type.
if (isset($values['field_storage'])) { if (isset($values['field_storage'])) {
if (!$values['field_storage'] instanceof FieldStorageConfigInterface) { if (!$values['field_storage'] instanceof FieldStorageConfigInterface) {
throw new FieldException('Attempt to create a configurable field instance for a non-configurable field storage.'); throw new FieldException('Attempt to create a configurable field for a non-configurable field storage.');
} }
$field_storage = $values['field_storage']; $field_storage = $values['field_storage'];
$values['field_name'] = $field_storage->getName(); $values['field_name'] = $field_storage->getName();
@ -93,15 +93,15 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
} }
else { else {
if (empty($values['field_name'])) { if (empty($values['field_name'])) {
throw new FieldException('Attempt to create a field instance without a field_name.'); throw new FieldException('Attempt to create a field without a field_name.');
} }
if (empty($values['entity_type'])) { if (empty($values['entity_type'])) {
throw new FieldException(String::format('Attempt to create a field instance @field_name without an entity_type.', array('@field_name' => $values['field_name']))); throw new FieldException(String::format('Attempt to create a field @field_name without an entity_type.', array('@field_name' => $values['field_name'])));
} }
} }
// 'bundle' is required in either case. // 'bundle' is required in either case.
if (empty($values['bundle'])) { if (empty($values['bundle'])) {
throw new FieldException(String::format('Attempt to create a field instance @field_name without a bundle.', array('@field_name' => $values['field_name']))); throw new FieldException(String::format('Attempt to create a field @field_name without a bundle.', array('@field_name' => $values['field_name'])));
} }
parent::__construct($values, $entity_type); parent::__construct($values, $entity_type);
@ -113,12 +113,12 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
public function postCreate(EntityStorageInterface $storage) { public function postCreate(EntityStorageInterface $storage) {
parent::postCreate($storage); parent::postCreate($storage);
// Validate that we have a valid storage for this instance. This throws an // Validate that we have a valid storage for this field. This throws an
// exception if the storage is invalid. // exception if the storage is invalid.
$this->getFieldStorageDefinition(); $this->getFieldStorageDefinition();
// 'Label' defaults to the field name (mostly useful for field instances // 'Label' defaults to the field name (mostly useful for fields created in
// created in tests). // tests).
if (empty($this->label)) { if (empty($this->label)) {
$this->label = $this->getName(); $this->label = $this->getName();
} }
@ -128,7 +128,7 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
* Overrides \Drupal\Core\Entity\Entity::preSave(). * Overrides \Drupal\Core\Entity\Entity::preSave().
* *
* @throws \Drupal\Core\Field\FieldException * @throws \Drupal\Core\Field\FieldException
* If the field instance definition is invalid. * If the field definition is invalid.
* @throws \Drupal\Core\Entity\EntityStorageException * @throws \Drupal\Core\Entity\EntityStorageException
* In case of failures at the configuration storage level. * In case of failures at the configuration storage level.
*/ */
@ -139,24 +139,24 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
$storage_definition = $this->getFieldStorageDefinition(); $storage_definition = $this->getFieldStorageDefinition();
if ($this->isNew()) { if ($this->isNew()) {
// Set the default instance settings. // Set the default field settings.
$this->settings += $field_type_manager->getDefaultInstanceSettings($storage_definition->type); $this->settings += $field_type_manager->getDefaultFieldSettings($storage_definition->type);
// Notify the entity storage. // Notify the entity storage.
$entity_manager->getStorage($this->entity_type)->onFieldDefinitionCreate($this); $entity_manager->getStorage($this->entity_type)->onFieldDefinitionCreate($this);
} }
else { else {
// Some updates are always disallowed. // Some updates are always disallowed.
if ($this->entity_type != $this->original->entity_type) { if ($this->entity_type != $this->original->entity_type) {
throw new FieldException("Cannot change an existing instance's entity_type."); throw new FieldException("Cannot change an existing field's entity_type.");
} }
if ($this->bundle != $this->original->bundle && empty($this->bundleRenameAllowed)) { if ($this->bundle != $this->original->bundle && empty($this->bundleRenameAllowed)) {
throw new FieldException("Cannot change an existing instance's bundle."); throw new FieldException("Cannot change an existing field's bundle.");
} }
if ($storage_definition->uuid() != $this->original->getFieldStorageDefinition()->uuid()) { if ($storage_definition->uuid() != $this->original->getFieldStorageDefinition()->uuid()) {
throw new FieldException("Cannot change an existing instance's storage."); throw new FieldException("Cannot change an existing field's storage.");
} }
// Set the default instance settings. // Set the default field settings.
$this->settings += $field_type_manager->getDefaultInstanceSettings($storage_definition->type); $this->settings += $field_type_manager->getDefaultFieldSettings($storage_definition->type);
// Notify the entity storage. // Notify the entity storage.
$entity_manager->getStorage($this->entity_type)->onFieldDefinitionUpdate($this, $this->original); $entity_manager->getStorage($this->entity_type)->onFieldDefinitionUpdate($this, $this->original);
} }
@ -177,49 +177,49 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function preDelete(EntityStorageInterface $storage, array $instances) { public static function preDelete(EntityStorageInterface $storage, array $fields) {
$state = \Drupal::state(); $state = \Drupal::state();
// Keep the instance definitions in the state storage so we can use them // Keep the field definitions in the state storage so we can use them
// later during field_purge_batch(). // later during field_purge_batch().
$deleted_instances = $state->get('field.instance.deleted') ?: array(); $deleted_fields = $state->get('field.field.deleted') ?: array();
foreach ($instances as $instance) { foreach ($fields as $field) {
if (!$instance->deleted) { if (!$field->deleted) {
$config = $instance->toArray(); $config = $field->toArray();
$config['deleted'] = TRUE; $config['deleted'] = TRUE;
$config['field_storage_uuid'] = $instance->getFieldStorageDefinition()->uuid(); $config['field_storage_uuid'] = $field->getFieldStorageDefinition()->uuid();
$deleted_instances[$instance->uuid()] = $config; $deleted_fields[$field->uuid()] = $config;
} }
} }
$state->set('field.instance.deleted', $deleted_instances); $state->set('field.field.deleted', $deleted_fields);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function postDelete(EntityStorageInterface $storage, array $instances) { public static function postDelete(EntityStorageInterface $storage, array $fields) {
// Clear the cache upfront, to refresh the results of getBundles(). // Clear the cache upfront, to refresh the results of getBundles().
\Drupal::entityManager()->clearCachedFieldDefinitions(); \Drupal::entityManager()->clearCachedFieldDefinitions();
// Notify the entity storage. // Notify the entity storage.
foreach ($instances as $instance) { foreach ($fields as $field) {
if (!$instance->deleted) { if (!$field->deleted) {
\Drupal::entityManager()->getStorage($instance->entity_type)->onFieldDefinitionDelete($instance); \Drupal::entityManager()->getStorage($field->entity_type)->onFieldDefinitionDelete($field);
} }
} }
// If this is part of a configuration synchronization then the following // If this is part of a configuration synchronization then the following
// configuration updates are not necessary. // configuration updates are not necessary.
$entity = reset($instances); $entity = reset($fields);
if ($entity->isSyncing()) { if ($entity->isSyncing()) {
return; return;
} }
// Delete field storages that have no more instances. // Delete field storages that have no more fields.
$storages_to_delete = array(); $storages_to_delete = array();
foreach ($instances as $instance) { foreach ($fields as $field) {
$storage_definition = $instance->getFieldStorageDefinition(); $storage_definition = $field->getFieldStorageDefinition();
if (!$instance->deleted && empty($instance->noFieldDelete) && !$instance->isUninstalling() && count($storage_definition->getBundles()) == 0) { if (!$field->deleted && empty($field->noFieldDelete) && !$field->isUninstalling() && count($storage_definition->getBundles()) == 0) {
// Key by field UUID to avoid deleting the same storage twice. // Key by field UUID to avoid deleting the same storage twice.
$storages_to_delete[$storage_definition->uuid()] = $storage_definition; $storages_to_delete[$storage_definition->uuid()] = $storage_definition;
} }
@ -230,15 +230,15 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
// Cleanup entity displays. // Cleanup entity displays.
$displays_to_update = array(); $displays_to_update = array();
foreach ($instances as $instance) { foreach ($fields as $field) {
if (!$instance->deleted) { if (!$field->deleted) {
$view_modes = \Drupal::entityManager()->getViewModeOptions($instance->entity_type, TRUE); $view_modes = \Drupal::entityManager()->getViewModeOptions($field->entity_type, TRUE);
foreach (array_keys($view_modes) as $mode) { foreach (array_keys($view_modes) as $mode) {
$displays_to_update['entity_view_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->getName(); $displays_to_update['entity_view_display'][$field->entity_type . '.' . $field->bundle . '.' . $mode][] = $field->getName();
} }
$form_modes = \Drupal::entityManager()->getFormModeOptions($instance->entity_type, TRUE); $form_modes = \Drupal::entityManager()->getFormModeOptions($field->entity_type, TRUE);
foreach (array_keys($form_modes) as $mode) { foreach (array_keys($form_modes) as $mode) {
$displays_to_update['entity_form_display'][$instance->entity_type . '.' . $instance->bundle . '.' . $mode][] = $instance->getName(); $displays_to_update['entity_form_display'][$field->entity_type . '.' . $field->bundle . '.' . $mode][] = $field->getName();
} }
} }
} }
@ -258,7 +258,7 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
protected function linkTemplates() { protected function linkTemplates() {
$link_templates = parent::linkTemplates(); $link_templates = parent::linkTemplates();
if (\Drupal::moduleHandler()->moduleExists('field_ui')) { if (\Drupal::moduleHandler()->moduleExists('field_ui')) {
$link_templates['edit-form'] = 'field_ui.instance_edit_' . $this->entity_type; $link_templates['edit-form'] = 'field_ui.field_edit_' . $this->entity_type;
$link_templates['storage-edit-form'] = 'field_ui.storage_edit_' . $this->entity_type; $link_templates['storage-edit-form'] = 'field_ui.storage_edit_' . $this->entity_type;
$link_templates['delete-form'] = 'field_ui.delete_' . $this->entity_type; $link_templates['delete-form'] = 'field_ui.delete_' . $this->entity_type;
@ -293,10 +293,9 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
if (!$this->fieldStorage) { if (!$this->fieldStorage) {
$fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type); $fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type);
if (!isset($fields[$this->field_name])) { if (!isset($fields[$this->field_name])) {
throw new FieldException(String::format('Attempt to create an instance of field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); throw new FieldException(String::format('Attempt to create a field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); }
}
if (!$fields[$this->field_name] instanceof FieldStorageConfigInterface) { if (!$fields[$this->field_name] instanceof FieldStorageConfigInterface) {
throw new FieldException(String::format('Attempt to create a configurable instance of non-configurable field @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); throw new FieldException(String::format('Attempt to create a configurable field of non-configurable field storage @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type)));
} }
$this->fieldStorage = $fields[$this->field_name]; $this->fieldStorage = $fields[$this->field_name];
} }
@ -344,11 +343,11 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
* Name of the field. * Name of the field.
* *
* @return static * @return static
* The field instance config entity if one exists for the provided field * The field config entity if one exists for the provided field
* name, otherwise NULL. * name, otherwise NULL.
*/ */
public static function loadByName($entity_type_id, $bundle, $field_name) { public static function loadByName($entity_type_id, $bundle, $field_name) {
return \Drupal::entityManager()->getStorage('field_instance_config')->load($entity_type_id . '.' . $bundle . '.' . $field_name); return \Drupal::entityManager()->getStorage('field_config')->load($entity_type_id . '.' . $bundle . '.' . $field_name);
} }
} }

View File

@ -123,8 +123,8 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* If TRUE, some actions not available though the UI (but are still possible * If TRUE, some actions not available though the UI (but are still possible
* through direct API manipulation): * through direct API manipulation):
* - field settings cannot be changed, * - field settings cannot be changed,
* - new instances cannot be created * - new fields cannot be created
* - existing instances cannot be deleted. * - existing fields cannot be deleted.
* Defaults to FALSE. * Defaults to FALSE.
* *
* @var bool * @var bool
@ -254,7 +254,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* *
* @throws \Drupal\Core\Field\FieldException If the field definition is invalid. * @throws \Drupal\Core\Field\FieldException If the field definition is invalid.
*/ */
protected function preSaveNew(EntityStorageInterface $storage) { protected function preSaveNew(EntityStorageInterface $storage) {
$entity_manager = \Drupal::entityManager(); $entity_manager = \Drupal::entityManager();
$field_type_manager = \Drupal::service('plugin.manager.field.field_type'); $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
@ -288,7 +288,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
// Make sure all settings are present, so that a complete field // Make sure all settings are present, so that a complete field
// definition is passed to the various hooks and written to config. // definition is passed to the various hooks and written to config.
$this->settings += $field_type_manager->getDefaultSettings($this->type); $this->settings += $field_type_manager->getDefaultStorageSettings($this->type);
// Notify the entity manager. // Notify the entity manager.
$entity_manager->onFieldStorageDefinitionCreate($this); $entity_manager->onFieldStorageDefinitionCreate($this);
@ -328,7 +328,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
// Make sure all settings are present, so that a complete field // Make sure all settings are present, so that a complete field
// definition is passed to the various hooks and written to config. // definition is passed to the various hooks and written to config.
$this->settings += $field_type_manager->getDefaultSettings($this->type); $this->settings += $field_type_manager->getDefaultStorageSettings($this->type);
// See if any module forbids the update by throwing an exception. This // See if any module forbids the update by throwing an exception. This
// invokes hook_field_storage_config_update_forbid(). // invokes hook_field_storage_config_update_forbid().
@ -357,39 +357,39 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function preDelete(EntityStorageInterface $storage, array $fields) { public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
$state = \Drupal::state(); $state = \Drupal::state();
$instance_storage = \Drupal::entityManager()->getStorage('field_instance_config'); $field_config_storage = \Drupal::entityManager()->getStorage('field_config');
// Delete instances first. Note: when deleting a field through // Delete fields first. Note: when deleting a field storage through
// FieldInstanceConfig::postDelete(), the instances have been deleted already, so // FieldConfig::postDelete(), the fields have been deleted already, so
// no instances will be found here. // no fields will be found here.
$instance_ids = array(); $field_ids = array();
foreach ($fields as $field) { foreach ($field_storages as $field_storage) {
if (!$field->deleted) { if (!$field_storage->deleted) {
foreach ($field->getBundles() as $bundle) { foreach ($field_storage->getBundles() as $bundle) {
$instance_ids[] = "{$field->entity_type}.$bundle.{$field->name}"; $field_ids[] = "{$field_storage->entity_type}.$bundle.{$field_storage->name}";
} }
} }
} }
if ($instance_ids) { if ($field_ids) {
$instances = $instance_storage->loadMultiple($instance_ids); $fields = $field_config_storage->loadMultiple($field_ids);
// Tag the objects to preserve recursive deletion of the field. // Tag the objects to preserve recursive deletion of the field.
foreach ($instances as $instance) { foreach ($fields as $field) {
$instance->noFieldDelete = TRUE; $field->noFieldDelete = TRUE;
} }
$instance_storage->delete($instances); $field_config_storage->delete($fields);
} }
// Keep the field definitions in the state storage so we can use them later // Keep the field definitions in the state storage so we can use them later
// during field_purge_batch(). // during field_purge_batch().
$deleted_storages = $state->get('field.storage.deleted') ?: array(); $deleted_storages = $state->get('field.storage.deleted') ?: array();
foreach ($fields as $field) { foreach ($field_storages as $field_storage) {
if (!$field->deleted) { if (!$field_storage->deleted) {
$config = $field->toArray(); $config = $field_storage->toArray();
$config['deleted'] = TRUE; $config['deleted'] = TRUE;
$config['bundles'] = $field->getBundles(); $config['bundles'] = $field_storage->getBundles();
$deleted_storages[$field->uuid()] = $config; $deleted_storages[$field_storage->uuid()] = $config;
} }
} }
@ -495,11 +495,11 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
public function getSettings() { public function getSettings() {
// @todo FieldTypePluginManager maintains its own static cache. However, do // @todo FieldTypePluginManager maintains its own static cache. However, do
// some CPU and memory profiling to see if it's worth statically caching // some CPU and memory profiling to see if it's worth statically caching
// $field_type_info, or the default field and instance settings, within // $field_type_info, or the default field storage and field settings,
// $this. // within $this.
$field_type_manager = \Drupal::service('plugin.manager.field.field_type'); $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
$settings = $field_type_manager->getDefaultSettings($this->type); $settings = $field_type_manager->getDefaultStorageSettings($this->type);
return $this->settings + $settings; return $this->settings + $settings;
} }

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains \Drupal\field\FieldInstanceConfigAccessControlHandler. * Contains \Drupal\field\FieldConfigAccessControlHandler.
*/ */
namespace Drupal\field; namespace Drupal\field;
@ -13,11 +13,11 @@ use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface; use Drupal\Core\Session\AccountInterface;
/** /**
* Defines the access control handler for the field instance entity type. * Defines the access control handler for the field entity type.
* *
* @see \Drupal\field\Entity\FieldInstanceConfig * @see \Drupal\field\Entity\FieldConfig
*/ */
class FieldInstanceConfigAccessControlHandler extends EntityAccessControlHandler { class FieldConfigAccessControlHandler extends EntityAccessControlHandler {
/** /**
* {@inheritdoc} * {@inheritdoc}

View File

@ -0,0 +1,26 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldConfigInterface.
*/
namespace Drupal\field;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Provides an interface defining a field entity.
*/
interface FieldConfigInterface extends ConfigEntityInterface, FieldDefinitionInterface {
/**
* Gets the deleted flag of the field.
*
* @return bool
* Returns TRUE if the field is deleted.
*/
public function isDeleted();
}

View File

@ -2,7 +2,7 @@
/** /**
* @file * @file
* Contains \Drupal\field\FieldInstanceConfigStorage. * Contains \Drupal\field\FieldConfigStorage.
*/ */
namespace Drupal\field; namespace Drupal\field;
@ -19,9 +19,9 @@ use Drupal\Component\Uuid\UuidInterface;
use Drupal\Core\State\StateInterface; use Drupal\Core\State\StateInterface;
/** /**
* Storage class for field instances. * Controller class for fields.
*/ */
class FieldInstanceConfigStorage extends FieldConfigStorageBase { class FieldConfigStorage extends FieldConfigStorageBase {
/** /**
* The entity manager. * The entity manager.
@ -38,7 +38,14 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
protected $state; protected $state;
/** /**
* Constructs a FieldInstanceConfigStorage object. * The field type plugin manager.
*
* @var \Drupal\Core\Field\FieldTypePluginManagerInterface
*/
protected $fieldTypeManager;
/**
* Constructs a FieldConfigStorage object.
* *
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type definition. * The entity type definition.
@ -81,8 +88,8 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function importDelete($name, Config $new_config, Config $old_config) { public function importDelete($name, Config $new_config, Config $old_config) {
// If the field has been deleted in the same import, the instance will be // If the field storage has been deleted in the same import, the field will
// deleted by then, and there is nothing left to do. Just return TRUE so // be deleted by then, and there is nothing left to do. Just return TRUE so
// that the file does not get written to active store. // that the file does not get written to active store.
if (!$old_config->get()) { if (!$old_config->get()) {
return TRUE; return TRUE;
@ -94,47 +101,47 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function loadByProperties(array $conditions = array()) { public function loadByProperties(array $conditions = array()) {
// Include deleted instances if specified in the $conditions parameters. // Include deleted fields if specified in the $conditions parameters.
$include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE; $include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE;
unset($conditions['include_deleted']); unset($conditions['include_deleted']);
$instances = array(); $fields = array();
// Get instances stored in configuration. If we are explicitly looking for // Get fields stored in configuration. If we are explicitly looking for
// deleted instances only, this can be skipped, because they will be // deleted fields only, this can be skipped, because they will be
// retrieved from state below. // retrieved from state below.
if (empty($conditions['deleted'])) { if (empty($conditions['deleted'])) {
if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) { if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) {
// Optimize for the most frequent case where we do have a specific ID. // Optimize for the most frequent case where we do have a specific ID.
$id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name']; $id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name'];
$instances = $this->loadMultiple(array($id)); $fields = $this->loadMultiple(array($id));
} }
else { else {
// No specific ID, we need to examine all existing instances. // No specific ID, we need to examine all existing fields.
$instances = $this->loadMultiple(); $fields = $this->loadMultiple();
} }
} }
// Merge deleted instances (stored in state) if needed. // Merge deleted fields (stored in state) if needed.
if ($include_deleted || !empty($conditions['deleted'])) { if ($include_deleted || !empty($conditions['deleted'])) {
$deleted_instances = $this->state->get('field.instance.deleted') ?: array(); $deleted_fields = $this->state->get('field.field.deleted') ?: array();
$deleted_storages = $this->state->get('field.storage.deleted') ?: array(); $deleted_storages = $this->state->get('field.storage.deleted') ?: array();
foreach ($deleted_instances as $id => $config) { foreach ($deleted_fields as $id => $config) {
// If the field itself is deleted, inject it directly in the instance. // If the field storage itself is deleted, inject it directly in the field.
if (isset($deleted_storages[$config['field_storage_uuid']])) { if (isset($deleted_storages[$config['field_storage_uuid']])) {
$config['field_storage'] = $this->entityManager->getStorage('field_storage_config')->create($deleted_storages[$config['field_storage_uuid']]); $config['field_storage'] = $this->entityManager->getStorage('field_storage_config')->create($deleted_storages[$config['field_storage_uuid']]);
} }
$instances[$id] = $this->create($config); $fields[$id] = $this->create($config);
} }
} }
// Collect matching instances. // Collect matching fields.
$matching_instances = array(); $matching_fields = array();
foreach ($instances as $instance) { foreach ($fields as $field) {
// Some conditions are checked against the field. // Some conditions are checked against the field.
$field_storage = $instance->getFieldStorageDefinition(); $field_storage = $field->getFieldStorageDefinition();
// Only keep the instance if it matches all conditions. // Only keep the field if it matches all conditions.
foreach ($conditions as $key => $value) { foreach ($conditions as $key => $value) {
// Extract the actual value against which the condition is checked. // Extract the actual value against which the condition is checked.
switch ($key) { switch ($key) {
@ -148,27 +155,27 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
break; break;
case 'uuid'; case 'uuid';
$checked_value = $instance->uuid(); $checked_value = $field->uuid();
break; break;
default: default:
$checked_value = $instance->$key; $checked_value = $field->$key;
break; break;
} }
// Skip to the next instance as soon as one condition does not match. // Skip to the next field as soon as one condition does not match.
if ($checked_value != $value) { if ($checked_value != $value) {
continue 2; continue 2;
} }
} }
// When returning deleted instances, key the results by UUID since they // When returning deleted fields, key the results by UUID since they
// can include several instances with the same ID. // can include several fields with the same ID.
$key = $include_deleted ? $instance->uuid() : $instance->id(); $key = $include_deleted ? $field->uuid() : $field->id();
$matching_instances[$key] = $instance; $matching_fields[$key] = $field;
} }
return $matching_instances; return $matching_fields;
} }
} }

View File

@ -1,26 +0,0 @@
<?php
/**
* @file
* Contains \Drupal\field\FieldInstanceConfigInterface.
*/
namespace Drupal\field;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Provides an interface defining a field instance entity.
*/
interface FieldInstanceConfigInterface extends ConfigEntityInterface, FieldDefinitionInterface {
/**
* Gets the deleted flag of the field instance.
*
* @return bool
* Returns TRUE if the instance is deleted.
*/
public function isDeleted();
}

Some files were not shown because too many files have changed in this diff Show More