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

View File

@ -822,7 +822,7 @@ class ConfigImporter {
// result of a secondary configuration write. Change the operation
// into an update. This is the desired behavior since renames often
// 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);
return FALSE;
}

View File

@ -215,8 +215,8 @@ class ConfigManager implements ConfigManagerInterface {
// dependencies on the to-be-removed entities.
$extension_dependent_entities = $this->findConfigEntityDependentsAsEntities($type, array($name));
// Reverse the array to that entities are removed in the correct order of
// dependence. For example, this ensures that field instances are removed
// before fields.
// dependence. For example, this ensures that fields are removed before
// field storages.
foreach (array_reverse($extension_dependent_entities) as $extension_dependent_entity) {
$extension_dependent_entity->setUninstalling(TRUE);
$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
* entities. The dependency system is used during configuration installation to
* ensure that configuration entities are imported in the correct order. For
* example, node types are created before their fields and the fields are
* created before their field instances.
* example, node types are created before their field storages and the field
* storages are created before their fields.
*
* Dependencies are stored to the configuration entity's configuration object so
* 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.
*
* The list of deletes is sorted so that dependencies are deleted after
* configuration entities that depend on them. For example, field instances
* should be deleted after fields.
* configuration entities that depend on them. For example, fields should be
* deleted after field storages.
*
* @param string $collection
* The storage collection to operate on.
@ -234,8 +234,8 @@ class StorageComparer implements StorageComparerInterface {
* Creates the create changelist.
*
* The list of creates is sorted so that dependencies are created before
* configuration entities that depend on them. For example, fields
* should be created before field instances.
* configuration entities that depend on them. For example, field storages
* should be created before fields.
*
* @param string $collection
* The storage collection to operate on.
@ -249,8 +249,8 @@ class StorageComparer implements StorageComparerInterface {
* Creates the update changelist.
*
* The list of updates is sorted so that dependencies are created before
* configuration entities that depend on them. For example, fields
* should be updated before field instances.
* configuration entities that depend on them. For example, field storages
* should be updated before fields.
*
* @param string $collection
* The storage collection to operate on.

View File

@ -10,8 +10,6 @@ namespace Drupal\Core\Entity;
use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Cache\Cache;
use Drupal\field\FieldInstanceConfigInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
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.
*
* 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
* The field definition.

View File

@ -64,7 +64,7 @@ interface EntityFormDisplayInterface extends EntityDisplayInterface {
* // One sub-array per copy of the widget, keyed by delta.
* 0 => array(
* '#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,
* '#delta' => 0,
* '#weight' => 0,

View File

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

View File

@ -109,7 +109,7 @@ interface EntityViewBuilderInterface {
* @param array $display_options
* Can be either:
* - 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
* are found for the view mode, the settings for the 'default' view mode
* will be used.

View File

@ -1554,7 +1554,7 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
// configurable fields, so we use the specific API.
// @todo Use the unified store of deleted field definitions instead in
// 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();
foreach ($field_definitions as $field_definition) {

View File

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

View File

@ -62,7 +62,7 @@ class BaseFieldDefinition extends ListDataDefinition implements FieldDefinitionI
// settings for the field type.
// @todo Cleanup in https://drupal.org/node/2116341.
$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);
return $field_definition;
}

View File

@ -155,7 +155,7 @@ class BaseFieldOverride extends FieldConfigBase {
*/
public function preSave(EntityStorageInterface $storage) {
// 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
// dependencies.

View File

@ -21,7 +21,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
use ThirdPartySettingsTrait;
/**
* The instance ID.
* The field ID.
*
* 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;
/**
* 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
*/
@ -52,38 +52,38 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
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
*/
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
*/
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
* 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
* instances created in tests).
* If not specified, this defaults to the field_name (mostly useful for fields
* created in tests).
*
* @var string
*/
public $label;
/**
* The instance description.
* The field description.
*
* 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
* this instance in entity edit forms.
* this field in entity edit forms.
*
* @var string
*/

View File

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

View File

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

View File

@ -28,16 +28,16 @@ use Drupal\Core\TypedData\ListDataDefinitionInterface;
* information comes from. For example, field.module provides an implementation
* 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"
* 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
* 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
* from either itself, or from the corresponding "field_storage_config"
* configuration, as appropriate.
*
* 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
* different objects based on the class \Drupal\Core\Field\BaseFieldDefinition,
* which implements this interface as well.

View File

@ -28,14 +28,14 @@ abstract class FieldItemBase extends Map implements FieldItemInterface {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
public static function defaultStorageSettings() {
return array();
}
/**
* {@inheritdoc}
*/
public static function defaultInstanceSettings() {
public static function defaultFieldSettings() {
return array();
}
@ -250,42 +250,42 @@ abstract class FieldItemBase extends Map implements FieldItemInterface {
/**
* {@inheritdoc}
*/
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) {
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
return array();
}
/**
* {@inheritdoc}
*/
public function instanceSettingsForm(array $form, FormStateInterface $form_state) {
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
return array();
}
/**
* {@inheritdoc}
*/
public static function settingsToConfigData(array $settings) {
public static function storageSettingsToConfigData(array $settings) {
return $settings;
}
/**
* {@inheritdoc}
*/
public static function settingsFromConfigData(array $settings) {
public static function storageSettingsFromConfigData(array $settings) {
return $settings;
}
/**
* {@inheritdoc}
*/
public static function instanceSettingsToConfigData(array $settings) {
public static function fieldSettingsToConfigData(array $settings) {
return $settings;
}
/**
* {@inheritdoc}
*/
public static function instanceSettingsFromConfigData(array $settings) {
public static function fieldSettingsFromConfigData(array $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
* 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.
*
@ -230,21 +230,21 @@ interface FieldItemInterface extends ComplexDataInterface {
*/
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.
*
* @return array
* A list of default settings, keyed by the setting name.
*/
public static function defaultSettings();
/**
* Defines the instance-level settings for this plugin.
*
* @return array
* A list of default settings, keyed by the setting name.
*/
public static function defaultInstanceSettings();
public static function defaultFieldSettings();
/**
* 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()
*/
public static function settingsToConfigData(array $settings);
public static function storageSettingsToConfigData(array $settings);
/**
* 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.
*
* @param array $settings
@ -293,58 +293,56 @@ interface FieldItemInterface extends ComplexDataInterface {
* The settings, in the representation expected by the field type and code
* 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.
*
* Same as static::settingsToConfigData(), but for the field's instance
* settings.
* Same as static::storageSettingsToConfigData(), but for the field's settings.
*
* @param array $settings
* The field's instance settings in the field type's canonical
* representation.
* The field's settings in the field type's canonical representation.
*
* @return array
* An array (either the unmodified $settings or a modified representation)
* 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.
*
* This function does the inverse of static::instanceSettingsToConfigData().
* It's called when loading a field's instance settings from a configuration
* This function does the inverse of static::fieldSettingsToConfigData().
* It's called when loading a field's settings from a configuration
* object.
*
* @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.
*
* @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.
*
* @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
* administrators to configure field-level settings.
* administrators to configure storage-level settings.
*
* Field storage might reject field definition changes that affect the field
* storage schema if the field already has data. When the $has_data parameter
* is TRUE, the form should not allow changing the settings that take part in
* the schema() method. It is recommended to set #access to FALSE on the
* corresponding elements.
* Field storage might reject settings changes that affect the field
* storage schema if the storage already has data. When the $has_data
* parameter is TRUE, the form should not allow changing the settings that
* take part in the schema() method. It is recommended to set #access to
* FALSE on the corresponding elements.
*
* @param array $form
* The form where the settings form is being included in.
@ -356,13 +354,13 @@ interface FieldItemInterface extends ComplexDataInterface {
* @return
* 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
* administrators to configure instance-level settings.
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* administrators to configure field-level settings.
*
* @param array $form
* 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.
*
* @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.
*
* 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.
*
* @param array $form
@ -201,14 +201,14 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
* The form state of the (entire) configuration form.
*
* @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);
/**
* 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.
*
* @param array $element
@ -223,7 +223,7 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
/**
* 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.
*
* @param array $element
@ -234,7 +234,7 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
* The form state of the (entire) configuration form.
*
* @return array
* The field instance default value.
* The field default value.
*/
public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state);

View File

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

View File

@ -17,19 +17,19 @@ use Drupal\Component\Plugin\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
* A field type name.
*
* @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.
*/
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
* 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
* 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.

View File

@ -19,7 +19,7 @@ interface FormatterInterface extends PluginSettingsInterface {
/**
* 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
* of handling submitted form values.
*

View File

@ -31,11 +31,11 @@ class BooleanItem extends FieldItemBase implements AllowedValuesInterface {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
public static function defaultStorageSettings() {
return array(
'on_label' => t('On'),
'off_label' => t('Off'),
) + parent::defaultSettings();
) + parent::defaultStorageSettings();
}
/**
@ -66,7 +66,7 @@ class BooleanItem extends FieldItemBase implements AllowedValuesInterface {
/**
* {@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(
'#type' => 'textfield',
'#title' => $this->t('"On" label'),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,10 +26,10 @@ class UuidItem extends StringItem {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
public static function defaultStorageSettings() {
return array(
'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) {
// 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.
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.
*
* 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
* handling submitted form values.
*
@ -86,10 +86,9 @@ interface WidgetInterface extends WidgetBaseInterface {
* $form_state->getValues(), and is used to access processing
* information for the field through the getWidgetState() and
* setWidgetState() methods.
* - #title: The sanitized element label for the field instance, ready for
* output.
* - #description: The sanitized element description for the field instance,
* ready for output.
* - #title: The sanitized element label for the field, ready for output.
* - #description: The sanitized element description for the field, ready
* for output.
* - #required: A Boolean indicating whether the element value is required;
* for required multiple value fields, only the first widget's values are
* required.

View File

@ -6,7 +6,7 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
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'
*
* @return array()
* Body field instance.
* Body field.
*/
function block_content_add_body_field($block_type_id, $label = 'Body') {
// Add or remove the body field, as needed.
$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)) {
$field_storage = entity_create('field_storage_config', array(
'name' => 'body',
@ -87,14 +87,14 @@ function block_content_add_body_field($block_type_id, $label = 'Body') {
));
$field_storage->save();
}
if (empty($instance)) {
$instance = entity_create('field_instance_config', array(
if (empty($field)) {
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => $block_type_id,
'label' => $label,
'settings' => array('display_summary' => FALSE),
));
$instance->save();
$field->save();
// Assign widget settings for the 'default' form mode.
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();
}
return $instance;
return $field;
}

View File

@ -31,11 +31,11 @@ class BlockContentFieldTest extends BlockContentTestBase {
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.
@ -61,14 +61,14 @@ class BlockContentFieldTest extends BlockContentTestBase {
'cardinality' => 2,
));
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array(
$this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage,
'bundle' => 'link',
'settings' => array(
'title' => DRUPAL_OPTIONAL,
),
));
$this->instance->save();
$this->field->save();
entity_get_form_display('block_content', 'link', 'default')
->setComponent($this->fieldStorage->getName(), array(
'type' => 'link_default',

View File

@ -26,7 +26,7 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Url;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\file\FileInterface;
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) {
if ($instance->getType() == 'comment' && !$instance->isSyncing()) {
// Assign default values for the field instance.
if (!isset($instance->default_value)) {
$instance->default_value = array();
function comment_field_config_create(FieldConfigInterface $field) {
if ($field->getType() == 'comment' && !$field->isSyncing()) {
// Assign default values for the field.
if (!isset($field->default_value)) {
$field->default_value = array();
}
$instance->default_value += array(array());
$instance->default_value[0] += array(
$field->default_value += array(array());
$field->default_value[0] += array(
'status' => CommentItemInterface::OPEN,
'cid' => 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) {
if ($instance->getType() == 'comment') {
function comment_field_config_update(FieldConfigInterface $field) {
if ($field->getType() == 'comment') {
// Comment field settings also affects the rendering of *comment* entities,
// not only the *commented* entities.
\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) {
if ($instance->getType() == 'comment') {
function comment_field_config_delete(FieldConfigInterface $field) {
if ($field->getType() == 'comment') {
// Delete all comments that used by the entity bundle.
$entity_query = \Drupal::entityQuery('comment');
$entity_query->condition('entity_type', $instance->getEntityTypeId());
$entity_query->condition('field_name', $instance->getName());
$entity_query->condition('entity_type', $field->getEntityTypeId());
$entity_query->condition('field_name', $field->getName());
$cids = $entity_query->execute();
entity_delete_multiple('comment', $cids);
}

View File

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

View File

@ -20,7 +20,7 @@ use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
/**
* 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.
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',
'description' => '',
'field_name' => $field_name,
@ -174,7 +174,7 @@ class CommentManager implements CommentManagerInterface {
),
),
));
$instance->save();
$field->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display($entity_type, $bundle, 'default')
@ -227,16 +227,16 @@ class CommentManager implements CommentManagerInterface {
));
$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.
$field_instance = $this->entityManager->getStorage('field_instance_config')->create(array(
$field = $this->entityManager->getStorage('field_config')->create(array(
'field_name' => 'comment_body',
'label' => 'Comment',
'entity_type' => 'comment',
'bundle' => $comment_type_id,
'required' => TRUE,
));
$field_instance->save();
$field->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display('comment', $comment_type_id, 'default')

View File

@ -52,7 +52,7 @@ interface CommentManagerInterface {
* @param string $entity_type
* The entity type to attach the default comment field to.
* @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
* (optional) Field name to use for the comment field. Defaults to
* 'comment'.
@ -66,7 +66,7 @@ interface CommentManagerInterface {
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
* The comment bundle.

View File

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

View File

@ -31,23 +31,23 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
/**
* {@inheritdoc}
*/
public static function defaultSettings() {
public static function defaultStorageSettings() {
return array(
'comment_type' => '',
) + parent::defaultSettings();
) + parent::defaultStorageSettings();
}
/**
* {@inheritdoc}
*/
public static function defaultInstanceSettings() {
public static function defaultFieldSettings() {
return array(
'default_mode' => CommentManagerInterface::COMMENT_MODE_THREADED,
'per_page' => 50,
'form_location' => CommentItemInterface::FORM_BELOW,
'anonymous' => COMMENT_ANONYMOUS_MAYNOT_CONTACT,
'preview' => DRUPAL_OPTIONAL,
) + parent::defaultInstanceSettings();
) + parent::defaultFieldSettings();
}
/**
@ -99,7 +99,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
/**
* {@inheritdoc}
*/
public function instanceSettingsForm(array $form, FormStateInterface $form_state) {
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = array();
$settings = $this->getSettings();
@ -110,9 +110,6 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
'#type' => 'details',
'#title' => t('Comment form settings'),
'#open' => TRUE,
'#attributes' => array(
'class' => array('comment-instance-settings-form'),
),
'#attached' => array(
'library' => array('comment/drupal.comment'),
),
@ -167,7 +164,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
*/
public function __get($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());
return $field_default_values[0]['status'];
}
@ -189,7 +186,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface {
/**
* {@inheritdoc}
*/
public function settingsForm(array &$form, FormStateInterface $form_state, $has_data) {
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$element = array();
// @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
// in this tab-set.
if (isset($form['advanced'])) {
// Get default value from the field instance.
// Get default value from the field.
$field_default_values = $this->fieldDefinition->getDefaultValue($entity);
// Override widget title to be helpful for end users.
@ -72,7 +72,7 @@ class CommentWidget extends WidgetBase {
$element += array(
'#type' => 'details',
// 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']),
'#group' => 'advanced',
'#attributes' => array(

View File

@ -9,7 +9,7 @@ namespace Drupal\comment\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
/**
* Tests fields on comments.
@ -35,10 +35,10 @@ class CommentFieldsTest extends CommentTestBase {
$this->container->get('comment.manager')->addDefaultField('node', 'test_node_type');
// Check that the 'comment_body' field is present on the comment bundle.
$instance = FieldInstanceConfig::loadByName('comment', 'comment', 'comment_body');
$this->assertTrue(!empty($instance), 'The comment_body field is added when a comment bundle is created');
$field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$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.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
@ -53,13 +53,13 @@ class CommentFieldsTest extends CommentTestBase {
// new comment bundle.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
$this->assertTrue($field_storage, 'The comment_body field exists');
$instance = FieldInstanceConfig::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)));
$field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
$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.
$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');
$this->assertEqual($field_storage->default_value[0]['status'], CommentItemInterface::CLOSED);
$field = entity_load('field_config', 'node.test_node_type.who_likes_ponies');
$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->node->delete();
$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
// type is deleted.
$this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field exists');
$this->assertNotNull(entity_load('field_instance_config', 'node.article.comment'), 'Comment instance exists');
// Make sure the comment field storage and all its fields are deleted when
// the node type is deleted.
$this->assertNotNull(entity_load('field_storage_config', 'node.comment'), 'Comment field storage exists');
$this->assertNotNull(entity_load('field_config', 'node.article.comment'), 'Comment field exists');
// Delete the node type.
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_instance_config', 'node.article.comment'), 'Comment instance deleted');
$this->assertNull(entity_load('field_storage_config', 'node.comment'), 'Comment field storage 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\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Entity\EntityInterface;
@ -94,8 +94,8 @@ class CommentNonNodeTest extends WebTestBase {
$edit = array();
$edit['comment_body[0][value]'] = $comment;
$instance = FieldInstanceConfig::loadByName('entity_test', 'entity_test', 'comment');
$preview_mode = $instance->getSetting('preview');
$field = FieldConfig::loadByName('entity_test', 'entity_test', 'comment');
$preview_mode = $field->getSetting('preview');
// Must get the page before we test for fields.
if ($entity !== NULL) {
@ -375,7 +375,7 @@ class CommentNonNodeTest extends WebTestBase {
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalPostForm(NULL, array(
'field[settings][comment_type]' => 'foobar',
'field_storage[settings][comment_type]' => 'foobar',
), t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings'));
@ -391,7 +391,7 @@ class CommentNonNodeTest extends WebTestBase {
$this->drupalPostForm(NULL, $edit, t('Save'));
// Re-use another comment type.
$this->drupalPostForm(NULL, array(
'field[settings][comment_type]' => 'foobar',
'field_storage[settings][comment_type]' => 'foobar',
), t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings'));
$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\Comment;
use Drupal\comment\CommentInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\simpletest\WebTestBase;
/**
@ -109,12 +109,12 @@ abstract class CommentTestBase extends WebTestBase {
$edit['comment_body[0][value]'] = $comment;
if ($entity !== NULL) {
$instance = FieldInstanceConfig::loadByName('node', $entity->bundle(), $field_name);
$field = FieldConfig::loadByName('node', $entity->bundle(), $field_name);
}
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.
if ($entity !== NULL) {
@ -309,9 +309,9 @@ abstract class CommentTestBase extends WebTestBase {
* Defaults to 'comment'.
*/
public function setCommentSettings($name, $value, $message, $field_name = 'comment') {
$instance = FieldInstanceConfig::loadByName('node', 'article', $field_name);
$instance->settings[$name] = $value;
$instance->save();
$field = FieldConfig::loadByName('node', 'article', $field_name);
$field->settings[$name] = $value;
$field->save();
// Display status message.
$this->pass($message);
}

View File

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

View File

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

View File

@ -26,12 +26,12 @@ class ConfigEntityStorageTest extends DrupalUnitTestBase {
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() {
$entity_type = 'config_test';
$id = 'test_1';
// Load the original field and instance entities.
// Load the original configuration entity.
entity_create($entity_type, array('id' => $id))->save();
$entity = entity_load($entity_type, $id);

View File

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

View File

@ -36,13 +36,13 @@ function hook_config_translation_info(&$info) {
$route_provider = \Drupal::service('router.route_provider');
// 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')) {
// Add fields entity mappers to all fieldable entity types defined.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
$base_route = NULL;
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) {
// 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.
if ($entity_type->isFieldable() && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id,
'entity_type' => 'field_instance_config',
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_config',
'title' => t('!label field'),
'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper',
'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_entity_type' => $entity_type_id,
'weight' => 10,
);

View File

@ -80,9 +80,9 @@ function config_translation_entity_type_alter(array &$entity_types) {
if ($entity_type_id == 'block') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListBuilder';
}
elseif ($entity_type_id == 'field_instance_config') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationFieldInstanceListBuilder';
// Will be filled in dynamically, see \Drupal\field\Entity\FieldInstanceConfig::linkTemplates().
elseif ($entity_type_id == 'field_config') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder';
// Will be filled in dynamically, see \Drupal\field\Entity\FieldConfig::linkTemplates().
$entity_type->setLinkTemplate('drupal:config-translation-overview', 'config_translation.item.overview.');
}
else {
@ -105,17 +105,17 @@ function config_translation_config_translation_info(&$info) {
$route_provider = \Drupal::service('router.route_provider');
// 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')) {
// Add fields entity mappers to all fieldable entity types defined.
foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) {
$base_route = NULL;
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) {
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.
}
@ -123,10 +123,10 @@ function config_translation_config_translation_info(&$info) {
// Make sure entity type is fieldable and has a base route.
if ($entity_type->isFieldable() && !empty($base_route)) {
$info[$entity_type_id . '_fields'] = array(
'base_route_name' => 'field_ui.instance_edit_' . $entity_type_id,
'entity_type' => 'field_instance_config',
'base_route_name' => 'field_ui.field_edit_' . $entity_type_id,
'entity_type' => 'field_config',
'title' => '!label field',
'class' => '\Drupal\config_translation\ConfigFieldInstanceMapper',
'class' => '\Drupal\config_translation\ConfigFieldMapper',
'base_entity_type' => $entity_type_id,
'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
// 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
// field instances, need special treatment. See above.
// fields, need special treatment. See above.
continue;
}

View File

@ -2,26 +2,25 @@
/**
* @file
* Contains \Drupal\config_translation\ConfigFieldInstanceMapper.
* Contains \Drupal\config_translation\ConfigFieldMapper.
*/
namespace Drupal\config_translation;
/**
* Configuration mapper for field instances.
* Configuration mapper for fields.
*
* 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:
* - base_entity_type: The name of the entity type the field instances are
* attached to.
* - base_entity_type: The name of the entity type the fields are attached to.
*/
class ConfigFieldInstanceMapper extends ConfigEntityMapper {
class ConfigFieldMapper extends ConfigEntityMapper {
/**
* Loaded entity instance to help produce the translation interface.
*
* @var \Drupal\field\FieldInstanceConfigInterface
* @var \Drupal\field\FieldConfigInterface
*/
protected $entity;

View File

@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\config_translation\Controller\ConfigTranslationFieldInstanceListBuilder.
* Contains \Drupal\config_translation\Controller\ConfigTranslationFieldListBuilder.
*/
namespace Drupal\config_translation\Controller;
@ -16,12 +16,12 @@ use Drupal\Core\Entity\EntityTypeInterface;
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
*/
@ -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
* The entity type definition.
@ -90,8 +90,8 @@ class ConfigTranslationFieldInstanceListBuilder extends ConfigTranslationEntityL
*/
public function load() {
// It is not possible to use the standard load method, because this needs
// all field instance entities only for the given baseEntityType.
$ids = \Drupal::entityQuery('field_instance_config')
// all field entities only for the given baseEntityType.
$ids = \Drupal::entityQuery('field_config')
->condition('id', $this->baseEntityType . '.', 'STARTS_WITH')
->execute();
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
* Whenever the bundle is displayed or not.

View File

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

View File

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

View File

@ -12,7 +12,6 @@ use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Render\Element;
use Drupal\field\FieldInstanceConfigInterface;
/**
* 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
// inherit this setting. Instead when it is made non translatable its field
// instances are hidden, since their translatability no longer matters.
// When a bundle is made translatable all of its fields should inherit
// this setting. Instead when it is made non translatable its fields are
// hidden, since their translatability no longer matters.
$('body').once('translation-entity-admin-bind').on('click', 'table .bundle-settings .translatable :input', function (e) {
var $target = $(e.target);
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\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldInstanceConfig;
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) {
$instance = $form_state->get('instance');
$bundle_is_translatable = content_translation_enabled($instance->entity_type, $instance->bundle);
function content_translation_form_field_ui_field_edit_form_alter(array &$form, FormStateInterface $form_state) {
$field = $form_state->get('field');
$bundle_is_translatable = content_translation_enabled($field->entity_type, $field->bundle);
$form['instance']['translatable'] = array(
$form['field']['translatable'] = array(
'#type' => 'checkbox',
'#title' => t('Users may translate this field'),
'#default_value' => $instance->isTranslatable(),
'#default_value' => $field->isTranslatable(),
'#weight' => -1,
'#disabled' => !$bundle_is_translatable,
'#access' => $instance->getFieldStorageDefinition()->isTranslatable(),
'#access' => $field->getFieldStorageDefinition()->isTranslatable(),
);
// 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(
'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,
));
}
if ($instance->isTranslatable()) {
if ($field->isTranslatable()) {
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) {
$form['instance']['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'] = $element;
$form['field']['third_party_settings']['content_translation']['translation_sync']['#weight'] = -10;
}
}
}

View File

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

View File

@ -10,7 +10,7 @@ namespace Drupal\content_translation\Tests;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Field\Entity\BaseFieldOverride;
use Drupal\Core\Language\Language;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\simpletest\WebTestBase;
/**
@ -30,7 +30,7 @@ class ContentTranslationSettingsTest extends WebTestBase {
protected function 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.
$this->drupalCreateContentType(array('type' => 'article'));
$this->drupalCreateContentType(array('type' => 'page'));
@ -163,20 +163,20 @@ class ContentTranslationSettingsTest extends WebTestBase {
// Test that configurable field translatability is correctly switched.
$edit = array('settings[node][article][fields][body]' => $translatable);
$this->assertSettings('node', 'article', TRUE, $edit);
$instance = FieldInstanceConfig::loadByName('node', 'article', 'body');
$field = FieldConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$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.
$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'));
\Drupal::entityManager()->clearCachedFieldDefinitions();
$instance = FieldInstanceConfig::loadByName('node', 'article', 'body');
$field = FieldConfig::loadByName('node', 'article', 'body');
$definitions = \Drupal::entityManager()->getFieldDefinitions('node', 'article');
$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() {
// At least one field needs to be translatable to enable article for
// translation. Create an extra field to be used for this purpose.
$field = array(
$field_storage = array(
'name' => 'article_text',
'entity_type' => 'node',
'type' => 'text',
);
entity_create('field_storage_config', $field)->save();
$instance = array(
entity_create('field_storage_config', $field_storage)->save();
$field = array(
'field_name' => 'article_text',
'entity_type' => 'node',
'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
// is not translatable.
// Tests that field doesn't have translatable setting if bundle is not
// translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.body';
$this->drupalGet($path);
$this->assertText('To configure translation for this field, enable language support for this type.', 'No translatable setting for field.');
// Tests that field instance has translatable setting if bundle is
// translatable. Note: this field instance is not translatable when
// enable bundle translatability.
// Tests that field has translatable setting if bundle is translatable.
// Note: this field is not translatable when enable bundle translatability.
$edit = array(
'entity_types[node]' => TRUE,
'settings[node][article][settings][language][language_show]' => TRUE,

View File

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

View File

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

View File

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

View File

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

View File

@ -33,11 +33,11 @@ class DateTimeFieldTest extends WebTestBase {
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() {
parent::setUp();
@ -59,14 +59,14 @@ class DateTimeFieldTest extends WebTestBase {
'settings' => array('datetime_type' => 'date'),
));
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array(
$this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage,
'bundle' => 'entity_test',
'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(
'type' => 'datetime_default',
))
@ -77,7 +77,7 @@ class DateTimeFieldTest extends WebTestBase {
'label' => 'hidden',
'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)
->save();
}
@ -123,7 +123,7 @@ class DateTimeFieldTest extends WebTestBase {
foreach ($values as $new_value) {
// Update the entity display settings.
$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)
->save();
@ -141,7 +141,7 @@ class DateTimeFieldTest extends WebTestBase {
// Verify that the plain formatter works.
$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)
->save();
$expected = $date->format(DATETIME_DATE_STORAGE_FORMAT);
@ -190,7 +190,7 @@ class DateTimeFieldTest extends WebTestBase {
foreach ($values as $new_value) {
// Update the entity display settings.
$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)
->save();
@ -208,7 +208,7 @@ class DateTimeFieldTest extends WebTestBase {
// Verify that the plain formatter works.
$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)
->save();
$expected = $date->format(DATETIME_DATETIME_STORAGE_FORMAT);
@ -226,7 +226,7 @@ class DateTimeFieldTest extends WebTestBase {
$this->fieldStorage->save();
// 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(
'type' => 'datetime_datelist',
'settings' => array(
@ -297,17 +297,17 @@ class DateTimeFieldTest extends WebTestBase {
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'date_content',
));
$instance->save();
$field->save();
// Set now as default_value.
$instance_edit = array(
$field_edit = array(
'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.
$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');
// 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');
// 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));
// 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]' => '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.');
// Set a relative default_value.
$instance_edit = array(
$field_edit = array(
'default_value_input[default_date_type]' => 'relative',
'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.
$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');
// 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');
// 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));
// Remove default value.
$instance_edit = array(
$field_edit = array(
'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.
$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');
// 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');
// 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'),
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'settings' => array(
'default_value' => 'blank',
),
));
$instance->save();
$field->save();
}
/**

View File

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

View File

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

View File

@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\FieldStorageConfigInterface;
/**
@ -85,7 +85,7 @@ function entity_reference_field_storage_config_update(FieldStorageConfigInterfac
}
if (empty($field_storage->bundles)) {
// Field has no instances.
// Field storage has no fields.
return;
}
@ -93,31 +93,31 @@ function entity_reference_field_storage_config_update(FieldStorageConfigInterfac
foreach ($field_storage->bundles() as $entity_type => $bundles) {
foreach ($bundles as $bundle) {
$instance = FieldInstanceConfig::loadByName($entity_type, $bundle, $field_name);
$instance->settings['handler_settings'] = array();
$instance->save();
$field = FieldConfig::loadByName($entity_type, $bundle, $field_name);
$field->settings['handler_settings'] = array();
$field->save();
}
}
}
/**
* Render API callback: Processes the field instance settings form and allows
* access to the form state.
* Render API callback: Processes the field settings form and allows access to
* 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) {
_entity_reference_field_instance_settings_ajax_process_element($form, $form);
function _entity_reference_field_field_settings_ajax_process($form, FormStateInterface $form_state) {
_entity_reference_field_field_settings_ajax_process_element($form, $form);
return $form;
}
/**
* 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'])) {
$element['#ajax'] = array(
'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) {
_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.
*
* @see entity_reference_field_instance_settings_form()
* @see entity_reference_field_field_settings_form()
*/
function entity_reference_settings_ajax($form, FormStateInterface $form_state) {
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.
*
* @see entity_reference_field_instance_settings_form()
* @see entity_reference_field_field_settings_form()
*/
function entity_reference_settings_ajax_submit($form, FormStateInterface $form_state) {
$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
* The type of entity the field instance will be attached to.
* The type of entity the field will be attached to.
* @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
* The name of the field; if it already exists, a new instance of the existing
* field will be created.
* @param string $field_label
* The label of the field instance.
* The label of the field.
* @param string $target_entity_type
* The type of the referenced entity.
* @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()
*/
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.
$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)) {
$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();
}
if (empty($instance)) {
$instance = array(
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
@ -232,7 +232,7 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f
'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}
*/
public static function defaultSettings() {
$settings = parent::defaultSettings();
public static function defaultStorageSettings() {
$settings = parent::defaultStorageSettings();
// The target bundle is handled by the 'target_bundles' property in the
// 'handler_settings' instance setting.
unset($settings['target_bundle']);
@ -45,10 +45,10 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/**
* {@inheritdoc}
*/
public static function defaultInstanceSettings() {
public static function defaultFieldSettings() {
return array(
'handler_settings' => array(),
) + parent::defaultInstanceSettings();
) + parent::defaultFieldSettings();
}
/**
@ -160,7 +160,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/**
* {@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(
'#type' => 'select',
'#title' => t('Type of item to reference'),
@ -177,8 +177,8 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
/**
* {@inheritdoc}
*/
public function instanceSettingsForm(array $form, FormStateInterface $form_state) {
$instance = $form_state->get('instance');
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$field = $form_state->get('field');
// Get all selection plugins for this entity 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(
'#type' => 'container',
'#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(
'#type' => 'details',
@ -214,7 +214,7 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
'#type' => 'select',
'#title' => t('Reference method'),
'#options' => $handlers_options,
'#default_value' => $instance->getSetting('handler'),
'#default_value' => $field->getSetting('handler'),
'#required' => TRUE,
'#ajax' => TRUE,
'#limit_validation_errors' => array(),
@ -234,8 +234,8 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
'#attributes' => array('class' => array('entity_reference-settings')),
);
$handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($instance);
$form['handler']['handler_settings'] += $handler->settingsForm($instance);
$handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($field);
$form['handler']['handler_settings'] += $handler->settingsForm($field);
return $form;
}
@ -248,10 +248,10 @@ class ConfigurableEntityReferenceItem extends EntityReferenceItem implements All
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state of the (entire) configuration form.
*/
public static function instanceSettingsFormValidate(array $form, FormStateInterface $form_state) {
if ($form_state->hasValue('instance')) {
$form_state->unsetValue(array('instance', 'settings', 'handler_submit'));
$form_state->get('instance')->settings = $form_state->getValue(['instance', 'settings']);
public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {
if ($form_state->hasValue('field')) {
$form_state->unsetValue(array('field', 'settings', 'handler_submit'));
$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\Field\FieldDefinitionInterface;
use Drupal\entity_reference\Plugin\Type\SelectionPluginManager;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\FieldConfigInterface;
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
* definition of the field on instance.

View File

@ -64,7 +64,7 @@ class EntityReferenceController extends ControllerBase {
* Defaults to ''.
*
* @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.
*
* @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) {
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 */
$columns = $field_definition->getFieldStorageDefinition()->getColumns();
// 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.
if (count($columns) > 1) {
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 {
$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'));
// 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.
$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'));
// 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.
$entity_type_id = 'node';
$bundles = entity_get_bundles($entity_type_id);
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);
// Test the sort settings.
// Option 0: no sort.
$this->assertFieldByName('instance[settings][handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('instance[settings][handler_settings][sort][direction]');
$this->assertFieldByName('field[settings][handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
// Option 1: sort by field.
$this->drupalPostAjaxForm(NULL, array('instance[settings][handler_settings][sort][field]' => 'nid'), 'instance[settings][handler_settings][sort][field]');
$this->assertFieldByName('instance[settings][handler_settings][sort][direction]', 'ASC');
$this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => 'nid'), 'field[settings][handler_settings][sort][field]');
$this->assertFieldByName('field[settings][handler_settings][sort][direction]', 'ASC');
// 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.
$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.
$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.
$this->drupalPostAjaxForm(NULL, array('instance[settings][handler_settings][sort][field]' => '_none'), 'instance[settings][handler_settings][sort][field]');
$this->assertNoFieldByName('instance[settings][handler_settings][sort][direction]');
$this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => '_none'), 'field[settings][handler_settings][sort][field]');
$this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
// Third step: confirm.
$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'));
// Check that the field appears in the overview form.
@ -191,12 +191,12 @@ class EntityReferenceAdminTest extends WebTestBase {
), t('Save'));
// 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.
$edit = array();
if($bundle) {
$edit['instance[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
$edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
}
// Save settings.

View File

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

View File

@ -53,7 +53,7 @@ class EntityReferenceAutocompleteTest extends EntityUnitTestBase {
protected function 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'),
));
$this->fieldStorage->save();
$this->instance = entity_create('field_instance_config', array(
$this->field = entity_create('field_config', array(
'field_storage' => $this->fieldStorage,
'bundle' => 'reference_content',
'settings' => array(
@ -60,20 +60,20 @@ class EntityReferenceFieldDefaultValueTest extends WebTestBase {
),
),
));
$this->instance->save();
$this->field->save();
// 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() . ')',
);
$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.
$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');
// 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->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');
// Setup a field and instance.
entity_reference_create_instance(
// Create a field.
entity_reference_create_field(
$this->entityType,
$this->bundle,
$this->fieldName,

View File

@ -54,7 +54,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
protected function 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
// cache tag when rendering it entirely.
@ -64,7 +64,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
'type' => 'text',
'settings' => array(),
))->save();
entity_create('field_instance_config', array(
entity_create('field_config', array(
'entity_type' => $this->entityType,
'bundle' => $this->bundle,
'field_name' => 'body',

View File

@ -64,7 +64,7 @@ class EntityReferenceIntegrationTest extends WebTestBase {
$this->fieldName = 'field_test_' . $referenced_entities[0]->getEntityTypeId();
// 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.
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();
// 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_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_term', 'Test content entity reference', 'taxonomy_term');
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.
*/
public function testNodeHandler() {
// Create a field storage and instance.
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'entity_type' => 'entity_test',
@ -68,7 +68,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'cardinality' => '1',
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'test_bundle',
'settings' => array(
@ -78,7 +78,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
),
),
));
$instance->save();
$field->save();
// Build a set of test data.
// Titles contain HTML-special characters to test escaping.
@ -162,7 +162,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'result' => array(),
),
);
$this->assertReferenceable($instance, $referenceable_tests, 'Node handler');
$this->assertReferenceable($field, $referenceable_tests, 'Node handler');
// Test as an admin.
$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.
*/
public function testUserHandler() {
// Create a field storage and instance.
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'entity_type' => 'entity_test',
@ -210,7 +210,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'cardinality' => '1',
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'test_bundle',
'settings' => array(
@ -220,7 +220,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
),
),
));
$instance->save();
$field->save();
// Build a set of test data.
$user_values = array(
@ -296,7 +296,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'result' => array(),
),
);
$this->assertReferenceable($instance, $referenceable_tests, 'User handler');
$this->assertReferenceable($field, $referenceable_tests, 'User handler');
\Drupal::currentUser()->setAccount($users['admin']);
$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.
*/
public function testCommentHandler() {
// Create a field storage and instance.
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'entity_type' => 'entity_test',
@ -355,7 +355,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'cardinality' => '1',
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'test_bundle',
'settings' => array(
@ -365,7 +365,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
),
),
));
$instance->save();
$field->save();
// Build a set of test data.
$node_values = array(
@ -474,7 +474,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'result' => array(),
),
);
$this->assertReferenceable($instance, $referenceable_tests, 'Comment handler');
$this->assertReferenceable($field, $referenceable_tests, 'Comment handler');
// Test as a comment admin.
$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.
$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'),
))->save();
entity_create('field_instance_config', array(
entity_create('field_config', array(
'label' => 'Text Field',
'field_name' => 'field_text',
'entity_type' => 'node',
@ -48,7 +48,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
))->save();
// Create a field storage and instance.
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'entity_type' => 'entity_test',
@ -60,7 +60,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
'cardinality' => 1,
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'entity_type' => 'entity_test',
'bundle' => 'test_bundle',
@ -76,7 +76,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
),
),
));
$instance->save();
$field->save();
// Build a set of test data.
$node_values = array(
@ -117,7 +117,7 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
$normal_user = $this->drupalCreateUser(array('access content'));
\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
// expected.
@ -129,11 +129,11 @@ class EntityReferenceSelectionSortTest extends WebTestBase {
$this->assertIdentical($result['article'], $expected_result, 'Query sorted by field returned expected values.');
// Assert sort by property.
$instance->settings['handler_settings']['sort'] = array(
$field->settings['handler_settings']['sort'] = array(
'field' => 'nid',
'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();
$expected_result = array(
$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\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldInstanceConfig;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Views;
@ -64,7 +64,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase {
));
$field_storage->save();
$instance = FieldInstanceConfig::create(array(
$field = FieldConfig::create(array(
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
@ -73,7 +73,7 @@ class EntityReferenceRelationshipTest extends ViewUnitTestBase {
'handler_settings' => array(),
),
));
$instance->save();
$field->save();
// Create some test entities which link each other.
$entity_storage= \Drupal::entityManager()->getStorage('entity_test');

View File

@ -33,7 +33,7 @@ class SelectionTest extends WebTestBase {
$nodes[$node->getType()][$node->id()] = $node->label();
}
// Create a field storage and instance.
// Create a field.
$field_storage = entity_create('field_storage_config', array(
'name' => 'test_field',
'entity_type' => 'entity_test',
@ -45,7 +45,7 @@ class SelectionTest extends WebTestBase {
'cardinality' => '1',
));
$field_storage->save();
$instance = entity_create('field_instance_config', array(
$field = entity_create('field_config', array(
'field_storage' => $field_storage,
'bundle' => 'test_bundle',
'settings' => array(
@ -60,10 +60,10 @@ class SelectionTest extends WebTestBase {
),
),
));
$instance->save();
$field->save();
// 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();
$success = FALSE;

View File

@ -25,7 +25,7 @@ field.storage.*.*:
type: string
label: 'Type'
settings:
type: field.[%parent.type].settings
type: field.[%parent.type].storage_settings
module:
type: string
label: 'Module'
@ -48,6 +48,6 @@ field.storage.*.*:
- type: ignore
label: 'Index'
field.instance.*.*.*:
field.field.*.*.*:
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
* 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
* The instance being purged.
* @param $field
* The field being purged.
*/
function hook_field_purge_instance($instance) {
db_delete('my_module_field_instance_info')
->condition('id', $instance['id'])
function hook_field_purge_field(\Drupal\field\Entity\FieldConfig $field) {
db_delete('my_module_field_info')
->condition('id', $field->id())
->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
* flexible variety of data type, form element, and display format capabilities.
*
* The Field API defines two primary data structures, Field and Instance, and
* the concept of a Bundle. A Field defines a particular type of data that can
* be attached to entities. A Field Instance is a Field attached to a single
* The Field API defines two primary data structures, FieldStorage and Field,
* and the concept of a Bundle. A FieldStorage defines a particular type of data
* 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
* Attach API and is related to a single fieldable entity type.
*
@ -51,7 +51,7 @@ require_once __DIR__ . '/field.purge.inc';
* and display formatters.
*
* - @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()) {
// Query by filtering on the ID as this is more efficient than filtering
// 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')
->execute();
// 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();
foreach ($field_instance_configs as $field_instance) {
$result[$field_instance->getName()] = $field_instance;
foreach ($field_configs as $field) {
$result[$field->getName()] = $field;
}
return $result;
}
@ -200,22 +200,22 @@ function field_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundl
* Implements hook_entity_bundle_rename().
*/
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));
foreach ($instances as $instance) {
$id_new = $instance->entity_type . '.' . $bundle_new . '.' . $instance->field_name;
$instance->set('id', $id_new);
$instance->bundle = $bundle_new;
// Save non-deleted instances.
if (!$instance->isDeleted()) {
$instance->allowBundleRename();
$instance->save();
$fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle_old, 'include_deleted' => TRUE));
foreach ($fields as $field) {
$id_new = $field->entity_type . '.' . $bundle_new . '.' . $field->field_name;
$field->set('id', $id_new);
$field->bundle = $bundle_new;
// Save non-deleted fields.
if (!$field->isDeleted()) {
$field->allowBundleRename();
$field->save();
}
// Update deleted instances directly in the state storage.
// Update deleted fields directly in the state storage.
else {
$state = \Drupal::state();
$deleted_instances = $state->get('field.instance.deleted') ?: array();
$deleted_instances[$instance->uuid] = $instance->toArray();
$state->set('field.instance.deleted', $deleted_instances);
$deleted_fields = $state->get('field.field.deleted') ?: array();
$deleted_fields[$field->uuid] = $field->toArray();
$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().
*
* This deletes the data for the field instances as well as the field instances
* themselves. This function actually just marks the data and field instances as
* deleted, leaving the garbage collection for a separate process, because it is
* not always possible to delete this much data in a single page request
* (particularly since for some field types, the deletion is more than just a
* simple DELETE query).
* This deletes the data for the field as well as the field themselves. This
* function actually just marks the data and fields as deleted, leaving the
* garbage collection for a separate process, because it is not always
* possible to delete this much data in a single page request (particularly
* since for some field types, the deletion is more than just a simple DELETE
* query).
*/
function field_entity_bundle_delete($entity_type, $bundle) {
// Get the instances on the bundle. entity_load_multiple_by_properties() must
// be used here since field_info_instances() does not return instances for
// disabled entity types or bundles.
$instances = entity_load_multiple_by_properties('field_instance_config', array('entity_type' => $entity_type, 'bundle' => $bundle));
foreach ($instances as $instance) {
$instance->delete();
// Get the fields on the bundle.
$fields = entity_load_multiple_by_properties('field_config', array('entity_type' => $entity_type, 'bundle' => $bundle));
foreach ($fields as $field) {
$field->delete();
}
}

View File

@ -8,6 +8,7 @@
use Drupal\Core\Field\FieldException;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldConfigInterface;
/**
* @defgroup field_purge Field API bulk data deletion
@ -15,7 +16,7 @@ use Drupal\field\FieldStorageConfigInterface;
* Cleans up after Field API bulk deletion operations.
*
* 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.
*
* 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.
*
* 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
* page request; there could be thousands or millions of them. Instead, the
* appropriate field data items, instances, and/or fields are marked as deleted
* so that subsequent load or query operations will not return them. Later, a
* separate process cleans up, or "purges", the marked-as-deleted data by going
* through the three-step process described above and, finally, removing deleted
* field and instance records.
* appropriate field data items, fields, and/or field storages are marked as
* deleted so that subsequent load or query operations will not return them.
* Later, a separate process cleans up, or "purges", the marked-as-deleted data
* by going through the three-step process described above and, finally,
* removing deleted field storage and field records.
*
* Purging field data is made somewhat tricky by the fact that, while
* $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
* operations, containing only the information from the original entity that
* Field API knows about: entity type, ID, revision ID, and bundle. It also
* contains the field data for whichever field instance is currently being
* purged.
* contains the field data for whichever field is currently being purged.
*
* See @link field Field API @endlink for information about the other parts of
* 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
* 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
* instance with no remaining data records is found, the instance itself will
* be purged. If a deleted field with no remaining field instances is found, the
* field itself will be purged.
* with no remaining data records is found, the field itself will
* be purged. If a deleted field storage with no remaining fields is found, the
* field storage itself will be purged.
*
* @param $batch_size
* 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) {
$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();
foreach ($instances as $instance) {
$entity_type = $instance->entity_type;
foreach ($fields as $field) {
$entity_type = $field->entity_type;
// We cannot purge anything if the entity type is unknown (e.g. the
// providing module was uninstalled).
@ -93,10 +93,10 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
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) {
// No field data remains for the instance, so we can remove it.
field_purge_instance($instance);
// No field data remains for the field, so we can remove it.
field_purge_field($field);
}
$batch_size -= $count_purged;
// 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
// purged.
// Retrieve all deleted field storages. Any that have no fields can be purged.
$deleted_storages = \Drupal::state()->get('field.storage.deleted') ?: array();
foreach ($deleted_storages as $field_storage) {
$field_storage = new FieldStorageConfig($field_storage);
@ -122,45 +121,47 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
continue;
}
$instances = entity_load_multiple_by_properties('field_instance_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
if (empty($instances)) {
$fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
if (empty($fields)) {
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().
*
* @param $instance
* The instance record to purge.
* @param $field
* The field record to purge.
*/
function field_purge_instance($instance) {
function field_purge_field(FieldConfigInterface $field) {
$state = \Drupal::state();
$deleted_instances = $state->get('field.instance.deleted');
unset($deleted_instances[$instance->uuid()]);
$state->set('field.instance.deleted', $deleted_instances);
$deleted_fields = $state->get('field.field.deleted');
unset($deleted_fields[$field->uuid()]);
$state->set('field.field.deleted', $deleted_fields);
// 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.
*
* This function assumes all instances for the field has already been purged,
* and should only be called by field_purge_batch().
* This function assumes all fields for the field storage has already been
* purged, and should only be called by field_purge_batch().
*
* @param \Drupal\field\FieldStorageConfigInterface $field_storage
* The field storage to purge.
*
* @throws Drupal\field\FieldException
*/
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));
if (count($instances) > 0) {
throw new FieldException(t('Attempt to purge a field storage @field_name that still has instances.', array('@field_name' => $field_storage->getName())));
$fields = entity_load_multiple_by_properties('field_config', array('field_storage_uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
if (count($fields) > 0) {
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();

View File

@ -9,7 +9,7 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\FieldConfigInterface;
/**
* Implements hook_views_data().
@ -79,19 +79,19 @@ function _field_views_get_entity_type_storage(FieldStorageConfigInterface $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) {
$label_counter = 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) {
$bundle_instances = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
return $field_definition instanceof FieldInstanceConfigInterface;
$bundle_fields = array_filter(\Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle), function ($field_definition) {
return $field_definition instanceof FieldConfigInterface;
});
if (isset($bundle_instances[$field_name])) {
$instance = $bundle_instances[$field_name];
$label = $instance->getLabel();
if (isset($bundle_fields[$field_name])) {
$field = $bundle_fields[$field_name];
$label = $field->getLabel();
$label_counter[$label] = isset($label_counter[$label]) ? ++$label_counter[$label] : 1;
$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())) {
return $data;
}
// Check the field has instances.
// Check the field storage has fields.
if (!$field_storage->getBundles()) {
return $data;
}
@ -236,7 +236,7 @@ function field_views_field_default_views_data(FieldStorageConfigInterface $field
$add_fields[] = $table_mapping->getFieldColumnName($field_storage, $column);
}
// 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.
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
// last instance and the field itself.
// last field and the field storage itself.
$context['sandbox']['field']['steps_to_delete'] += count($fields);
$context['sandbox']['field']['current_progress'] = 0;

View File

@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\field\Entity\FieldInstanceConfig.
* Contains \Drupal\field\Entity\FieldConfig.
*/
namespace Drupal\field\Entity;
@ -12,36 +12,36 @@ use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldConfigBase;
use Drupal\Core\Field\FieldException;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\FieldConfigInterface;
/**
* Defines the Field instance entity.
* Defines the Field entity.
*
* @ConfigEntityType(
* id = "field_instance_config",
* label = @Translation("Field instance"),
* id = "field_config",
* label = @Translation("Field"),
* handlers = {
* "access" = "Drupal\field\FieldInstanceConfigAccessControlHandler",
* "storage" = "Drupal\field\FieldInstanceConfigStorage"
* "access" = "Drupal\field\FieldConfigAccessControlHandler",
* "storage" = "Drupal\field\FieldConfigStorage"
* },
* config_prefix = "instance",
* config_prefix = "field",
* entity_keys = {
* "id" = "id",
* "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
* the state storage while field data is purged by a separate
* 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).
*
* @var bool
@ -49,40 +49,40 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
public $deleted = FALSE;
/**
* The field ConfigEntity object this is an instance of.
* The associated FieldStorageConfig entity.
*
* @var \Drupal\field\Entity\FieldStorageConfig
*/
protected $fieldStorage;
/**
* Constructs a FieldInstanceConfig object.
* Constructs a FieldConfig object.
*
* In most cases, Field instance entities are created via
* entity_create('field_instance_config', $values), where $values is the same
* In most cases, Field entities are created via
* entity_create('field_config', $values), where $values is the same
* parameter as in this constructor.
*
* @param array $values
* An array of field instance properties, keyed by property name. The
* storage associated to the instance can be specified either with:
* An array of field properties, keyed by property name. The
* storage associated to the field can be specified either with:
* - field_storage: the FieldStorageConfigInterface object,
* or by referring to an existing field storage in the current configuration
* with:
* - field_name: The field name.
* - entity_type: The entity type.
* 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
* property documentation for details.
*
* @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
// entity_type.
if (isset($values['field_storage'])) {
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'];
$values['field_name'] = $field_storage->getName();
@ -93,15 +93,15 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
}
else {
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'])) {
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.
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);
@ -113,12 +113,12 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
public function postCreate(EntityStorageInterface $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.
$this->getFieldStorageDefinition();
// 'Label' defaults to the field name (mostly useful for field instances
// created in tests).
// 'Label' defaults to the field name (mostly useful for fields created in
// tests).
if (empty($this->label)) {
$this->label = $this->getName();
}
@ -128,7 +128,7 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
* Overrides \Drupal\Core\Entity\Entity::preSave().
*
* @throws \Drupal\Core\Field\FieldException
* If the field instance definition is invalid.
* If the field definition is invalid.
* @throws \Drupal\Core\Entity\EntityStorageException
* In case of failures at the configuration storage level.
*/
@ -139,24 +139,24 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
$storage_definition = $this->getFieldStorageDefinition();
if ($this->isNew()) {
// Set the default instance settings.
$this->settings += $field_type_manager->getDefaultInstanceSettings($storage_definition->type);
// Set the default field settings.
$this->settings += $field_type_manager->getDefaultFieldSettings($storage_definition->type);
// Notify the entity storage.
$entity_manager->getStorage($this->entity_type)->onFieldDefinitionCreate($this);
}
else {
// Some updates are always disallowed.
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)) {
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()) {
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.
$this->settings += $field_type_manager->getDefaultInstanceSettings($storage_definition->type);
// Set the default field settings.
$this->settings += $field_type_manager->getDefaultFieldSettings($storage_definition->type);
// Notify the entity storage.
$entity_manager->getStorage($this->entity_type)->onFieldDefinitionUpdate($this, $this->original);
}
@ -177,49 +177,49 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
/**
* {@inheritdoc}
*/
public static function preDelete(EntityStorageInterface $storage, array $instances) {
public static function preDelete(EntityStorageInterface $storage, array $fields) {
$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().
$deleted_instances = $state->get('field.instance.deleted') ?: array();
foreach ($instances as $instance) {
if (!$instance->deleted) {
$config = $instance->toArray();
$deleted_fields = $state->get('field.field.deleted') ?: array();
foreach ($fields as $field) {
if (!$field->deleted) {
$config = $field->toArray();
$config['deleted'] = TRUE;
$config['field_storage_uuid'] = $instance->getFieldStorageDefinition()->uuid();
$deleted_instances[$instance->uuid()] = $config;
$config['field_storage_uuid'] = $field->getFieldStorageDefinition()->uuid();
$deleted_fields[$field->uuid()] = $config;
}
}
$state->set('field.instance.deleted', $deleted_instances);
$state->set('field.field.deleted', $deleted_fields);
}
/**
* {@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().
\Drupal::entityManager()->clearCachedFieldDefinitions();
// Notify the entity storage.
foreach ($instances as $instance) {
if (!$instance->deleted) {
\Drupal::entityManager()->getStorage($instance->entity_type)->onFieldDefinitionDelete($instance);
foreach ($fields as $field) {
if (!$field->deleted) {
\Drupal::entityManager()->getStorage($field->entity_type)->onFieldDefinitionDelete($field);
}
}
// If this is part of a configuration synchronization then the following
// configuration updates are not necessary.
$entity = reset($instances);
$entity = reset($fields);
if ($entity->isSyncing()) {
return;
}
// Delete field storages that have no more instances.
// Delete field storages that have no more fields.
$storages_to_delete = array();
foreach ($instances as $instance) {
$storage_definition = $instance->getFieldStorageDefinition();
if (!$instance->deleted && empty($instance->noFieldDelete) && !$instance->isUninstalling() && count($storage_definition->getBundles()) == 0) {
foreach ($fields as $field) {
$storage_definition = $field->getFieldStorageDefinition();
if (!$field->deleted && empty($field->noFieldDelete) && !$field->isUninstalling() && count($storage_definition->getBundles()) == 0) {
// Key by field UUID to avoid deleting the same storage twice.
$storages_to_delete[$storage_definition->uuid()] = $storage_definition;
}
@ -230,15 +230,15 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
// Cleanup entity displays.
$displays_to_update = array();
foreach ($instances as $instance) {
if (!$instance->deleted) {
$view_modes = \Drupal::entityManager()->getViewModeOptions($instance->entity_type, TRUE);
foreach ($fields as $field) {
if (!$field->deleted) {
$view_modes = \Drupal::entityManager()->getViewModeOptions($field->entity_type, TRUE);
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) {
$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() {
$link_templates = parent::linkTemplates();
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['delete-form'] = 'field_ui.delete_' . $this->entity_type;
@ -293,10 +293,9 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
if (!$this->fieldStorage) {
$fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type);
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) {
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];
}
@ -344,11 +343,11 @@ class FieldInstanceConfig extends FieldConfigBase implements FieldInstanceConfig
* Name of the field.
*
* @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.
*/
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
* through direct API manipulation):
* - field settings cannot be changed,
* - new instances cannot be created
* - existing instances cannot be deleted.
* - new fields cannot be created
* - existing fields cannot be deleted.
* Defaults to FALSE.
*
* @var bool
@ -254,7 +254,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @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();
$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
// 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.
$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
// 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
// invokes hook_field_storage_config_update_forbid().
@ -357,39 +357,39 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
/**
* {@inheritdoc}
*/
public static function preDelete(EntityStorageInterface $storage, array $fields) {
public static function preDelete(EntityStorageInterface $storage, array $field_storages) {
$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
// FieldInstanceConfig::postDelete(), the instances have been deleted already, so
// no instances will be found here.
$instance_ids = array();
foreach ($fields as $field) {
if (!$field->deleted) {
foreach ($field->getBundles() as $bundle) {
$instance_ids[] = "{$field->entity_type}.$bundle.{$field->name}";
// Delete fields first. Note: when deleting a field storage through
// FieldConfig::postDelete(), the fields have been deleted already, so
// no fields will be found here.
$field_ids = array();
foreach ($field_storages as $field_storage) {
if (!$field_storage->deleted) {
foreach ($field_storage->getBundles() as $bundle) {
$field_ids[] = "{$field_storage->entity_type}.$bundle.{$field_storage->name}";
}
}
}
if ($instance_ids) {
$instances = $instance_storage->loadMultiple($instance_ids);
if ($field_ids) {
$fields = $field_config_storage->loadMultiple($field_ids);
// Tag the objects to preserve recursive deletion of the field.
foreach ($instances as $instance) {
$instance->noFieldDelete = TRUE;
foreach ($fields as $field) {
$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
// during field_purge_batch().
$deleted_storages = $state->get('field.storage.deleted') ?: array();
foreach ($fields as $field) {
if (!$field->deleted) {
$config = $field->toArray();
foreach ($field_storages as $field_storage) {
if (!$field_storage->deleted) {
$config = $field_storage->toArray();
$config['deleted'] = TRUE;
$config['bundles'] = $field->getBundles();
$deleted_storages[$field->uuid()] = $config;
$config['bundles'] = $field_storage->getBundles();
$deleted_storages[$field_storage->uuid()] = $config;
}
}
@ -495,11 +495,11 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
public function getSettings() {
// @todo FieldTypePluginManager maintains its own static cache. However, do
// some CPU and memory profiling to see if it's worth statically caching
// $field_type_info, or the default field and instance settings, within
// $this.
// $field_type_info, or the default field storage and field settings,
// within $this.
$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;
}

View File

@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\field\FieldInstanceConfigAccessControlHandler.
* Contains \Drupal\field\FieldConfigAccessControlHandler.
*/
namespace Drupal\field;
@ -13,11 +13,11 @@ use Drupal\Core\Entity\EntityInterface;
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}

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
* Contains \Drupal\field\FieldInstanceConfigStorage.
* Contains \Drupal\field\FieldConfigStorage.
*/
namespace Drupal\field;
@ -19,9 +19,9 @@ use Drupal\Component\Uuid\UuidInterface;
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.
@ -38,7 +38,14 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
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
* The entity type definition.
@ -81,8 +88,8 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
* {@inheritdoc}
*/
public function importDelete($name, Config $new_config, Config $old_config) {
// If the field has been deleted in the same import, the instance will be
// deleted by then, and there is nothing left to do. Just return TRUE so
// If the field storage has been deleted in the same import, the field will
// 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.
if (!$old_config->get()) {
return TRUE;
@ -94,47 +101,47 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
* {@inheritdoc}
*/
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;
unset($conditions['include_deleted']);
$instances = array();
$fields = array();
// Get instances stored in configuration. If we are explicitly looking for
// deleted instances only, this can be skipped, because they will be
// Get fields stored in configuration. If we are explicitly looking for
// deleted fields only, this can be skipped, because they will be
// retrieved from state below.
if (empty($conditions['deleted'])) {
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.
$id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name'];
$instances = $this->loadMultiple(array($id));
$fields = $this->loadMultiple(array($id));
}
else {
// No specific ID, we need to examine all existing instances.
$instances = $this->loadMultiple();
// No specific ID, we need to examine all existing fields.
$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'])) {
$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();
foreach ($deleted_instances as $id => $config) {
// If the field itself is deleted, inject it directly in the instance.
foreach ($deleted_fields as $id => $config) {
// If the field storage itself is deleted, inject it directly in the field.
if (isset($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.
$matching_instances = array();
foreach ($instances as $instance) {
// Collect matching fields.
$matching_fields = array();
foreach ($fields as $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) {
// Extract the actual value against which the condition is checked.
switch ($key) {
@ -148,27 +155,27 @@ class FieldInstanceConfigStorage extends FieldConfigStorageBase {
break;
case 'uuid';
$checked_value = $instance->uuid();
$checked_value = $field->uuid();
break;
default:
$checked_value = $instance->$key;
$checked_value = $field->$key;
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) {
continue 2;
}
}
// When returning deleted instances, key the results by UUID since they
// can include several instances with the same ID.
$key = $include_deleted ? $instance->uuid() : $instance->id();
$matching_instances[$key] = $instance;
// When returning deleted fields, key the results by UUID since they
// can include several fields with the same ID.
$key = $include_deleted ? $field->uuid() : $field->id();
$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