summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2015-02-10 13:39:31 (GMT)
committerAlex Pott2015-02-10 13:39:31 (GMT)
commiteebf624a3b4f4cb99ef95f93d3bb4a6ce7c44a34 (patch)
tree278c06bc24355c46bc2494df99c98d19b07c7f02
parent6eb18e4ff5e139e7e75b62fd6655dccbb2875313 (diff)
Issue #2030633 by hussainweb, Mile23, carsonevans, czigor, Berdir, fernando_calsa, Geijutsuka, amitgoyal, Jānis Bebrītis, undertext: Expand FieldStorageConfig with methods
-rw-r--r--core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php2
-rw-r--r--core/modules/comment/src/Form/CommentTypeDeleteForm.php2
-rw-r--r--core/modules/comment/src/Tests/CommentLanguageTest.php2
-rw-r--r--core/modules/config/src/Tests/ConfigExportImportUITest.php2
-rw-r--r--core/modules/datetime/src/Tests/DateTimeFieldTest.php8
-rw-r--r--core/modules/editor/src/Tests/QuickEditIntegrationTest.php2
-rw-r--r--core/modules/entity_reference/entity_reference.module2
-rw-r--r--core/modules/field/field.api.php2
-rw-r--r--core/modules/field/field.module2
-rw-r--r--core/modules/field/field.purge.inc6
-rw-r--r--core/modules/field/src/ConfigImporterFieldPurger.php5
-rw-r--r--core/modules/field/src/Entity/FieldConfig.php2
-rw-r--r--core/modules/field/src/Entity/FieldStorageConfig.php117
-rw-r--r--core/modules/field/src/FieldStorageConfigInterface.php100
-rw-r--r--core/modules/field/src/FieldStorageConfigStorage.php12
-rw-r--r--core/modules/field/src/Tests/BulkDeleteTest.php4
-rw-r--r--core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php2
-rw-r--r--core/modules/field/src/Tests/FieldCrudTest.php12
-rw-r--r--core/modules/field/src/Tests/FieldStorageCrudTest.php18
-rw-r--r--core/modules/field/src/Tests/FieldValidationTest.php2
-rw-r--r--core/modules/field/src/Tests/reEnableModuleFieldTest.php2
-rw-r--r--core/modules/field_ui/src/FieldConfigListBuilder.php2
-rw-r--r--core/modules/field_ui/src/FieldStorageConfigListBuilder.php15
-rw-r--r--core/modules/field_ui/src/Form/FieldConfigDeleteForm.php2
-rw-r--r--core/modules/field_ui/src/Form/FieldStorageEditForm.php4
-rw-r--r--core/modules/field_ui/src/Tests/EntityDisplayTest.php2
-rw-r--r--core/modules/field_ui/src/Tests/EntityFormDisplayTest.php2
-rw-r--r--core/modules/field_ui/src/Tests/ManageFieldsTest.php2
-rw-r--r--core/modules/file/file.views.inc2
-rw-r--r--core/modules/image/image.module63
-rw-r--r--core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php4
-rw-r--r--core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php50
-rw-r--r--core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php22
-rw-r--r--core/modules/node/src/Tests/NodeFieldMultilingualTest.php2
-rw-r--r--core/modules/node/src/Tests/Views/NodeLanguageTest.php2
-rw-r--r--core/modules/options/options.module4
-rw-r--r--core/modules/options/options.views.inc6
-rw-r--r--core/modules/options/src/Tests/OptionsFieldTest.php6
-rw-r--r--core/modules/options/src/Tests/OptionsWidgetsTest.php12
-rw-r--r--core/modules/quickedit/src/Tests/EditorSelectionTest.php6
-rw-r--r--core/modules/search/src/Tests/SearchLanguageTest.php2
-rw-r--r--core/modules/search/src/Tests/SearchMultilingualEntityTest.php2
-rw-r--r--core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php2
-rw-r--r--core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php10
-rw-r--r--core/modules/taxonomy/src/Entity/Vocabulary.php13
-rw-r--r--core/modules/taxonomy/src/Tests/TermFieldTest.php4
-rw-r--r--core/modules/user/src/Tests/UserRegistrationTest.php2
-rw-r--r--core/modules/views/views.api.php2
-rw-r--r--core/modules/views/views.views.inc6
49 files changed, 362 insertions, 195 deletions
diff --git a/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php
index 5ca1a5b..c1cef64 100644
--- a/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php
+++ b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php
@@ -50,7 +50,7 @@ class BlockContentFieldFilterTest extends BlockContentTestBase {
// Make the body field translatable. The info is already translatable by
// definition.
$field_storage = FieldStorageConfig::loadByName('block_content', 'body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
// Set up block_content infos.
diff --git a/core/modules/comment/src/Form/CommentTypeDeleteForm.php b/core/modules/comment/src/Form/CommentTypeDeleteForm.php
index 9a859e8..deac0ac 100644
--- a/core/modules/comment/src/Form/CommentTypeDeleteForm.php
+++ b/core/modules/comment/src/Form/CommentTypeDeleteForm.php
@@ -97,7 +97,7 @@ class CommentTypeDeleteForm extends EntityDeleteForm {
$caption = '';
foreach (array_keys($this->commentManager->getFields($entity_type)) as $field_name) {
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
- if (($field_storage = FieldStorageConfig::loadByName($entity_type, $field_name)) && $field_storage->getSetting('comment_type') == $this->entity->id() && !$field_storage->deleted) {
+ if (($field_storage = FieldStorageConfig::loadByName($entity_type, $field_name)) && $field_storage->getSetting('comment_type') == $this->entity->id() && !$field_storage->isDeleted()) {
$caption .= '<p>' . $this->t('%label is used by the %field field on your site. You can not remove this comment type until you have removed the field.', array(
'%label' => $this->entity->label(),
'%field' => $field_storage->label(),
diff --git a/core/modules/comment/src/Tests/CommentLanguageTest.php b/core/modules/comment/src/Tests/CommentLanguageTest.php
index 92f610e..883eb17 100644
--- a/core/modules/comment/src/Tests/CommentLanguageTest.php
+++ b/core/modules/comment/src/Tests/CommentLanguageTest.php
@@ -73,7 +73,7 @@ class CommentLanguageTest extends WebTestBase {
// Make comment body translatable.
$field_storage = FieldStorageConfig::loadByName('comment', 'comment_body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
$this->assertTrue($field_storage->isTranslatable(), 'Comment body is translatable.');
}
diff --git a/core/modules/config/src/Tests/ConfigExportImportUITest.php b/core/modules/config/src/Tests/ConfigExportImportUITest.php
index a172649..f3aa1ff 100644
--- a/core/modules/config/src/Tests/ConfigExportImportUITest.php
+++ b/core/modules/config/src/Tests/ConfigExportImportUITest.php
@@ -143,7 +143,7 @@ class ConfigExportImportUITest extends WebTestBase {
}
$field_storages = FieldStorageConfig::loadMultiple();
foreach ($field_storages as $field_storage) {
- if ($field_storage->field_name == $this->fieldName) {
+ if ($field_storage->getName() == $this->fieldName) {
$field_storage->delete();
}
}
diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
index 07707b9..1f3a409 100644
--- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php
+++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
@@ -95,7 +95,7 @@ class DateTimeFieldTest extends WebTestBase {
* Tests date field functionality.
*/
function testDateField() {
- $field_name = $this->fieldStorage->field_name;
+ $field_name = $this->fieldStorage->getName();
// Display creation form.
$this->drupalGet('entity_test/add');
@@ -163,7 +163,7 @@ class DateTimeFieldTest extends WebTestBase {
function testDatetimeField() {
$field_name = $this->fieldStorage->getName();
// Change the field to a datetime field.
- $this->fieldStorage->settings['datetime_type'] = 'datetime';
+ $this->fieldStorage->setSetting('datetime_type', 'datetime');
$this->fieldStorage->save();
// Display creation form.
@@ -229,7 +229,7 @@ class DateTimeFieldTest extends WebTestBase {
function testDatelistWidget() {
$field_name = $this->fieldStorage->getName();
// Change the field to a datetime field.
- $this->fieldStorage->settings['datetime_type'] = 'datetime';
+ $this->fieldStorage->setSetting('datetime_type', 'datetime');
$this->fieldStorage->save();
// Change the widget to a datelist widget.
@@ -393,7 +393,7 @@ class DateTimeFieldTest extends WebTestBase {
function testInvalidField() {
// Change the field to a datetime field.
- $this->fieldStorage->settings['datetime_type'] = 'datetime';
+ $this->fieldStorage->setSetting('datetime_type', 'datetime');
$this->fieldStorage->save();
$field_name = $this->fieldStorage->getName();
diff --git a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php
index 33077c3..ab48237 100644
--- a/core/modules/editor/src/Tests/QuickEditIntegrationTest.php
+++ b/core/modules/editor/src/Tests/QuickEditIntegrationTest.php
@@ -145,7 +145,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
$this->assertEqual('editor', $this->getSelectedEditor($entity->id(), $this->fieldName), "With cardinality 1, and the full_html text format, the 'editor' editor is selected.");
// Editor selection with text processing, cardinality >1
- $this->fields->field_textarea_field_storage->cardinality = 2;
+ $this->fields->field_textarea_field_storage->setCardinality(2);
$this->fields->field_textarea_field_storage->save();
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $this->fieldName), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module
index b1b0619..526c60c 100644
--- a/core/modules/entity_reference/entity_reference.module
+++ b/core/modules/entity_reference/entity_reference.module
@@ -69,7 +69,7 @@ function entity_reference_field_widget_info_alter(&$info) {
* Reset the instance handler settings, when the target type is changed.
*/
function entity_reference_field_storage_config_update(FieldStorageConfigInterface $field_storage) {
- if ($field_storage->type != 'entity_reference') {
+ if ($field_storage->getType() != 'entity_reference') {
// Only act on entity reference fields.
return;
}
diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php
index bb39027..55c239d 100644
--- a/core/modules/field/field.api.php
+++ b/core/modules/field/field.api.php
@@ -81,7 +81,7 @@ function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfi
$allowed_values = $field_storage->getSetting('allowed_values');
$prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
$lost_keys = array_keys(array_diff_key($prior_allowed_values,$allowed_values));
- if (_options_values_in_use($field_storage->entity_type, $field_storage->getName(), $lost_keys)) {
+ if (_options_values_in_use($field_storage->getTargetEntityTypeId(), $field_storage->getName(), $lost_keys)) {
throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field_storage->getName())));
}
}
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index 5f95d50..3e9c9e0 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -153,7 +153,7 @@ function field_system_info_alter(&$info, Extension $file, $type) {
// remains no actual, non-deleted fields)
$non_deleted = FALSE;
foreach ($field_storages as $field_storage) {
- if (empty($field_storage->deleted)) {
+ if (!$field_storage->isDeleted()) {
$non_deleted = TRUE;
break;
}
diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc
index 73de63f..4af0f4e 100644
--- a/core/modules/field/field.purge.inc
+++ b/core/modules/field/field.purge.inc
@@ -84,7 +84,7 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
$info = \Drupal::entityManager()->getDefinitions();
foreach ($fields as $field) {
- $entity_type = $field->entity_type;
+ $entity_type = $field->getTargetEntityTypeId();
// We cannot purge anything if the entity type is unknown (e.g. the
// providing module was uninstalled).
@@ -117,7 +117,7 @@ function field_purge_batch($batch_size, $field_storage_uuid = NULL) {
// We cannot purge anything if the entity type is unknown (e.g. the
// providing module was uninstalled).
// @todo Revisit after https://drupal.org/node/2080823.
- if (!isset($info[$field_storage->entity_type])) {
+ if (!isset($info[$field_storage->getTargetEntityTypeId()])) {
continue;
}
@@ -170,7 +170,7 @@ function field_purge_field_storage(FieldStorageConfigInterface $field_storage) {
$state->set('field.storage.deleted', $deleted_storages);
// Notify the storage layer.
- \Drupal::entityManager()->getStorage($field_storage->entity_type)->finalizePurge($field_storage);
+ \Drupal::entityManager()->getStorage($field_storage->getTargetEntityTypeId())->finalizePurge($field_storage);
// Invoke external hooks after the cache is cleared for API consistency.
\Drupal::moduleHandler()->invokeAll('field_purge_field_storage', array($field_storage));
diff --git a/core/modules/field/src/ConfigImporterFieldPurger.php b/core/modules/field/src/ConfigImporterFieldPurger.php
index 55294b2..efc39a2 100644
--- a/core/modules/field/src/ConfigImporterFieldPurger.php
+++ b/core/modules/field/src/ConfigImporterFieldPurger.php
@@ -40,7 +40,7 @@ class ConfigImporterFieldPurger {
$context['sandbox']['field']['current_storage_id'] = $field_storage->id();
// If the storage has not been deleted yet we need to do that. This is the
// case when the storage deletion is staged.
- if (!$field_storage->deleted) {
+ if (!$field_storage->isDeleted()) {
$field_storage->delete();
}
}
@@ -138,9 +138,10 @@ class ConfigImporterFieldPurger {
}
// Gather deleted fields from modules that are being uninstalled.
+ /** @var \Drupal\field\FieldStorageConfigInterface[] $field_storages */
$field_storages = entity_load_multiple_by_properties('field_storage_config', array('deleted' => TRUE, 'include_deleted' => TRUE));
foreach ($field_storages as $field_storage) {
- if (!in_array($field_storage->module, $providers)) {
+ if (!in_array($field_storage->getTypeProvider(), $providers)) {
$storages_to_delete[$field_storage->id()] = $field_storage;
}
}
diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php
index dc5607a..c5b9ad5 100644
--- a/core/modules/field/src/Entity/FieldConfig.php
+++ b/core/modules/field/src/Entity/FieldConfig.php
@@ -141,7 +141,7 @@ class FieldConfig extends FieldConfigBase implements FieldConfigInterface {
// Filter out unknown settings and make sure all settings are present, so
// that a complete field definition is passed to the various hooks and
// written to config.
- $default_settings = $field_type_manager->getDefaultFieldSettings($storage_definition->type);
+ $default_settings = $field_type_manager->getDefaultFieldSettings($storage_definition->getType());
$this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings;
if ($this->isNew()) {
diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php
index a64f713..ab869db 100644
--- a/core/modules/field/src/Entity/FieldStorageConfig.php
+++ b/core/modules/field/src/Entity/FieldStorageConfig.php
@@ -51,7 +51,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var string
*/
- public $id;
+ protected $id;
/**
* The field name.
@@ -64,14 +64,14 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var string
*/
- public $field_name;
+ protected $field_name;
/**
* The name of the entity type the field can be attached to.
*
* @var string
*/
- public $entity_type;
+ protected $entity_type;
/**
* The field type.
@@ -80,14 +80,14 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var string
*/
- public $type;
+ protected $type;
/**
* The name of the module that provides the field type.
*
* @var string
*/
- public $module;
+ protected $module;
/**
* Field-type specific settings.
@@ -97,7 +97,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var array
*/
- public $settings = array();
+ protected $settings = [];
/**
* The field cardinality.
@@ -108,7 +108,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var int
*/
- public $cardinality = 1;
+ protected $cardinality = 1;
/**
* Flag indicating whether the field is translatable.
@@ -117,7 +117,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var bool
*/
- public $translatable = TRUE;
+ protected $translatable = TRUE;
/**
* Flag indicating whether the field is available for editing.
@@ -131,7 +131,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var bool
*/
- public $locked = FALSE;
+ protected $locked = FALSE;
/**
* Flag indicating whether the field storage should be deleted when orphaned.
@@ -164,7 +164,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var array
*/
- public $indexes = array();
+ protected $indexes = [];
/**
* Flag indicating whether the field is deleted.
@@ -179,7 +179,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
*
* @var bool
*/
- public $deleted = FALSE;
+ protected $deleted = FALSE;
/**
* The field schema.
@@ -238,7 +238,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* {@inheritdoc}
*/
public function id() {
- return $this->entity_type . '.' . $this->field_name;
+ return $this->getTargetEntityTypeId() . '.' . $this->getName();
}
/**
@@ -288,25 +288,25 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
// Field name cannot be longer than FieldStorageConfig::NAME_MAX_LENGTH characters.
// We use Unicode::strlen() because the DB layer assumes that column widths
// are given in characters rather than bytes.
- if (Unicode::strlen($this->field_name) > static::NAME_MAX_LENGTH) {
+ if (Unicode::strlen($this->getName()) > static::NAME_MAX_LENGTH) {
throw new FieldException(String::format(
'Attempt to create a field storage with an name longer than @max characters: %name', array(
'@max' => static::NAME_MAX_LENGTH,
- '%name' => $this->field_name,
+ '%name' => $this->getName(),
)
));
}
// Disallow reserved field names.
- $disallowed_field_names = array_keys($entity_manager->getBaseFieldDefinitions($this->entity_type));
- if (in_array($this->field_name, $disallowed_field_names)) {
- throw new FieldException(String::format('Attempt to create field storage %name which is reserved by entity type %type.', array('%name' => $this->field_name, '%type' => $this->entity_type)));
+ $disallowed_field_names = array_keys($entity_manager->getBaseFieldDefinitions($this->getTargetEntityTypeId()));
+ if (in_array($this->getName(), $disallowed_field_names)) {
+ throw new FieldException(String::format('Attempt to create field storage %name which is reserved by entity type %type.', array('%name' => $this->getName(), '%type' => $this->getTargetEntityTypeId())));
}
// Check that the field type is known.
- $field_type = $field_type_manager->getDefinition($this->type, FALSE);
+ $field_type = $field_type_manager->getDefinition($this->getType(), FALSE);
if (!$field_type) {
- throw new FieldException(String::format('Attempt to create a field storage of unknown type %type.', array('%type' => $this->type)));
+ throw new FieldException(String::format('Attempt to create a field storage of unknown type %type.', array('%type' => $this->getType())));
}
$this->module = $field_type['provider'];
@@ -320,7 +320,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
public function calculateDependencies() {
parent::calculateDependencies();
// Ensure the field is dependent on the providing module.
- $this->addDependency('module', $this->module);
+ $this->addDependency('module', $this->getTypeProvider());
// Ensure the field is dependent on the provider of the entity type.
$entity_type = \Drupal::entityManager()->getDefinition($this->entity_type);
$this->addDependency('module', $entity_type->getProvider());
@@ -338,10 +338,10 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
$entity_manager = \Drupal::entityManager();
// Some updates are always disallowed.
- if ($this->type != $this->original->type) {
+ if ($this->getType() != $this->original->getType()) {
throw new FieldException("Cannot change the field type for an existing field storage.");
}
- if ($this->entity_type != $this->original->entity_type) {
+ if ($this->getTargetEntityTypeId() != $this->original->getTargetEntityTypeId()) {
throw new FieldException("Cannot change the entity type for an existing field storage.");
}
@@ -383,7 +383,9 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
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->field_name}";
+ $entity_type = $field_storage->getTargetEntityTypeId();
+ $field_name = $field_storage->getName();
+ $field_ids[] = "{$entity_type}.$bundle.{$field_name}";
}
}
}
@@ -481,10 +483,10 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
* {@inheritdoc}
*/
public function getBundles() {
- if (empty($this->deleted)) {
+ if (!$this->isDeleted()) {
$map = \Drupal::entityManager()->getFieldMap();
- if (isset($map[$this->entity_type][$this->field_name]['bundles'])) {
- return $map[$this->entity_type][$this->field_name]['bundles'];
+ if (isset($map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'])) {
+ return $map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'];
}
}
return array();
@@ -500,6 +502,20 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
/**
* {@inheritdoc}
*/
+ public function isDeleted() {
+ return $this->deleted;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getTypeProvider() {
+ return $this->module;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getType() {
return $this->type;
}
@@ -514,7 +530,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
// within $this.
$field_type_manager = \Drupal::service('plugin.manager.field.field_type');
- $settings = $field_type_manager->getDefaultStorageSettings($this->type);
+ $settings = $field_type_manager->getDefaultStorageSettings($this->getType());
return $this->settings + $settings;
}
@@ -540,6 +556,22 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
/**
* {@inheritdoc}
*/
+ public function setSetting($setting_name, $value) {
+ $this->settings[$setting_name] = $value;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setSettings(array $settings) {
+ $this->settings = $settings;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function isTranslatable() {
return $this->translatable;
}
@@ -591,6 +623,14 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
/**
* {@inheritdoc}
*/
+ public function setCardinality($cardinality) {
+ $this->cardinality = $cardinality;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getOptionsProvider($property_name, FieldableEntityInterface $entity) {
// If the field item class implements the interface, create an orphaned
// runtime item object, so that it can be used as the options provider
@@ -621,6 +661,14 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
/**
* {@inheritdoc}
*/
+ public function setLocked($locked) {
+ $this->locked = $locked;
+ return $this;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getTargetEntityTypeId() {
return $this->entity_type;
}
@@ -750,4 +798,19 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI
return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getIndexes() {
+ return $this->indexes;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setIndexes(array $indexes) {
+ $this->indexes = $indexes;
+ return $this;
+ }
+
}
diff --git a/core/modules/field/src/FieldStorageConfigInterface.php b/core/modules/field/src/FieldStorageConfigInterface.php
index de0406b..116517a 100644
--- a/core/modules/field/src/FieldStorageConfigInterface.php
+++ b/core/modules/field/src/FieldStorageConfigInterface.php
@@ -16,6 +16,22 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
interface FieldStorageConfigInterface extends ConfigEntityInterface, FieldStorageDefinitionInterface {
/**
+ * Returns the field type.
+ *
+ * @return string
+ * The field type, i.e. the id of a field type plugin. For example 'text'.
+ */
+ public function getType();
+
+ /**
+ * Returns the name of the module providing the field type.
+ *
+ * @return string
+ * The name of the module that provides the field type.
+ */
+ public function getTypeProvider();
+
+ /**
* Returns the list of bundles where the field storage has fields.
*
* @return array
@@ -24,12 +40,12 @@ interface FieldStorageConfigInterface extends ConfigEntityInterface, FieldStorag
public function getBundles();
/**
- * Returns whether the field storage is locked or not.
+ * Returns whether the field is deleted or not.
*
* @return bool
- * TRUE if the field storage is locked.
+ * TRUE if the field is deleted.
*/
- public function isLocked();
+ public function isDeleted();
/**
* Checks if the field storage can be deleted.
@@ -39,4 +55,82 @@ interface FieldStorageConfigInterface extends ConfigEntityInterface, FieldStorag
*/
public function isDeletable();
+ /**
+ * Returns whether the field storage is locked or not.
+ *
+ * @return bool
+ * TRUE if the field storage is locked.
+ */
+ public function isLocked();
+
+ /**
+ * Sets the locked flag.
+ *
+ * @param bool $locked
+ * Sets value of locked flag.
+ *
+ * @return $this
+ */
+ public function setLocked($locked);
+
+ /**
+ * Sets the maximum number of items allowed for the field.
+ *
+ * @param int $cardinality
+ * The cardinality value.
+ *
+ * @return $this
+ */
+ public function setCardinality($cardinality);
+
+ /**
+ * Sets the value for a field setting by name.
+ *
+ * @param string $setting_name
+ * The name of the setting.
+ * @param mixed $value
+ * The value of the setting.
+ *
+ * @return $this
+ */
+ public function setSetting($setting_name, $value);
+
+ /**
+ * Sets field settings (overwrites existing settings).
+ *
+ * @param array $settings
+ * The array of field settings.
+ *
+ * @return $this
+ */
+ public function setSettings(array $settings);
+
+ /**
+ * Sets whether the field is translatable.
+ *
+ * @param bool $translatable
+ * Whether the field is translatable.
+ *
+ * @return $this
+ */
+ public function setTranslatable($translatable);
+
+ /**
+ * Returns the custom storage indexes for the field data storage.
+ *
+ * @return array
+ * An array of custom indexes.
+ */
+ public function getIndexes();
+
+ /**
+ * Sets the custom storage indexes for the field data storage..
+ *
+ * @param array $indexes
+ * The array of custom indexes.
+ *
+ * @return $this
+ */
+ public function setIndexes(array $indexes);
+
}
diff --git a/core/modules/field/src/FieldStorageConfigStorage.php b/core/modules/field/src/FieldStorageConfigStorage.php
index d865d85..55800b3 100644
--- a/core/modules/field/src/FieldStorageConfigStorage.php
+++ b/core/modules/field/src/FieldStorageConfigStorage.php
@@ -104,6 +104,7 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
$include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE;
unset($conditions['include_deleted']);
+ /** @var \Drupal\field\FieldStorageConfigInterface[] $storages */
$storages = array();
// Get field storages living in configuration. If we are explicitly looking
@@ -134,16 +135,7 @@ class FieldStorageConfigStorage extends ConfigEntityStorage {
foreach ($storages as $field) {
foreach ($conditions as $key => $value) {
// Extract the actual value against which the condition is checked.
- switch ($key) {
- case 'uuid';
- $checked_value = $field->uuid();
- break;
-
- default:
- $checked_value = $field->$key;
- break;
- }
-
+ $checked_value = $field->get($key);
// Skip to the next field as soon as one condition does not match.
if ($checked_value != $value) {
continue 2;
diff --git a/core/modules/field/src/Tests/BulkDeleteTest.php b/core/modules/field/src/Tests/BulkDeleteTest.php
index 4ae227b..be306e5 100644
--- a/core/modules/field/src/Tests/BulkDeleteTest.php
+++ b/core/modules/field/src/Tests/BulkDeleteTest.php
@@ -314,7 +314,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
$this->assertEqual(count($fields), 0, 'The field is purged.');
// The field storage still exists, not deleted.
$storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
- $this->assertTrue(isset($storages[$field_storage->uuid()]) && !$storages[$field_storage->uuid()]->deleted, 'The field storage exists and is not deleted');
+ $this->assertTrue(isset($storages[$field_storage->uuid()]) && !$storages[$field_storage->uuid()]->isDeleted(), 'The field storage exists and is not deleted');
// Delete the second field.
$bundle = next($this->bundles);
@@ -341,7 +341,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
$fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid(), 'include_deleted' => TRUE));
$this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->deleted, 'The field exists and is deleted');
$storages = entity_load_multiple_by_properties('field_storage_config', array('uuid' => $field_storage->uuid(), 'include_deleted' => TRUE));
- $this->assertTrue(isset($storages[$field_storage->uuid()]) && $storages[$field_storage->uuid()]->deleted, 'The field storage exists and is deleted');
+ $this->assertTrue(isset($storages[$field_storage->uuid()]) && $storages[$field_storage->uuid()]->isDeleted(), 'The field storage exists and is deleted');
// Purge again to purge the field and the storage.
field_purge_batch(0);
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
index 6cc7718..d940188 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -244,7 +244,7 @@ class EntityReferenceFormatterTest extends EntityUnitTestBase {
// \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
// and the label formatter will output only the label instead of a link.
$field_storage_config = FieldStorageConfig::loadByName($this->entityType, $this->fieldName);
- $field_storage_config->settings['target_type'] = 'entity_test_label';
+ $field_storage_config->setSetting('target_type', 'entity_test_label');
$field_storage_config->save();
$referenced_entity_with_no_link_template = entity_create('entity_test_label', array(
diff --git a/core/modules/field/src/Tests/FieldCrudTest.php b/core/modules/field/src/Tests/FieldCrudTest.php
index 94639e1..33ace63 100644
--- a/core/modules/field/src/Tests/FieldCrudTest.php
+++ b/core/modules/field/src/Tests/FieldCrudTest.php
@@ -207,10 +207,10 @@ class FieldCrudTest extends FieldUnitTestBase {
entity_create('field_config', $this->fieldDefinition)->save();
entity_create('field_config', $field_definition_2)->save();
$field_storage->delete();
- $this->assertFalse(FieldConfig::loadByName('entity_test', $this->fieldDefinition['bundle'], $field_storage->field_name));
- $this->assertFalse(FieldConfig::loadByName('entity_test', $field_definition_2['bundle'], $field_storage->field_name));
+ $this->assertFalse(FieldConfig::loadByName('entity_test', $this->fieldDefinition['bundle'], $field_storage->getName()));
+ $this->assertFalse(FieldConfig::loadByName('entity_test', $field_definition_2['bundle'], $field_storage->getName()));
- // Chack that deletion of the last field deletes the storage.
+ // Check that deletion of the last field deletes the storage.
$field_storage = entity_create('field_storage_config', $this->fieldStorageDefinition);
$field_storage->save();
$field = entity_create('field_config', $this->fieldDefinition);
@@ -218,9 +218,9 @@ class FieldCrudTest extends FieldUnitTestBase {
$field_2 = entity_create('field_config', $field_definition_2);
$field_2->save();
$field->delete();
- $this->assertTrue(FieldStorageConfig::loadByName('entity_test', $field_storage->field_name));
+ $this->assertTrue(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
$field_2->delete();
- $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->field_name));
+ $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
// Check that deletion of all fields using a storage simultaneously deletes
// the storage.
@@ -231,7 +231,7 @@ class FieldCrudTest extends FieldUnitTestBase {
$field_2 = entity_create('field_config', $field_definition_2);
$field_2->save();
$this->container->get('entity.manager')->getStorage('field_config')->delete(array($field, $field_2));
- $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->field_name));
+ $this->assertFalse(FieldStorageConfig::loadByName('entity_test', $field_storage->getName()));
}
/**
diff --git a/core/modules/field/src/Tests/FieldStorageCrudTest.php b/core/modules/field/src/Tests/FieldStorageCrudTest.php
index 365f136..37e4afb 100644
--- a/core/modules/field/src/Tests/FieldStorageCrudTest.php
+++ b/core/modules/field/src/Tests/FieldStorageCrudTest.php
@@ -305,13 +305,13 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
// Test that the first field is not deleted, and then delete it.
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE)));
- $this->assertTrue(!empty($field_storage) && empty($field_storage->deleted), 'A new storage is not marked for deletion.');
+ $this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage is not marked for deletion.');
FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();
// Make sure that the field is marked as deleted when it is specifically
// loaded.
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', array('field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE)));
- $this->assertTrue(!empty($field_storage->deleted), 'A deleted storage is marked for deletion.');
+ $this->assertTrue($field_storage->isDeleted(), 'A deleted storage is marked for deletion.');
// Make sure that this field is marked as deleted when it is
// specifically loaded.
@@ -328,7 +328,7 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
// Make sure the other field and its storage are not deleted.
$another_field_storage = FieldStorageConfig::load('entity_test.' . $another_field_storage_definition['field_name']);
- $this->assertTrue(!empty($another_field_storage) && empty($another_field_storage->deleted), 'A non-deleted storage is not marked for deletion.');
+ $this->assertTrue(!empty($another_field_storage) && !$another_field_storage->isDeleted(), 'A non-deleted storage is not marked for deletion.');
$another_field = FieldConfig::load('entity_test.' . $another_field_definition['bundle'] . '.' . $another_field_definition['field_name']);
$this->assertTrue(!empty($another_field) && empty($another_field->deleted), 'A field whose storage was not deleted is not marked for deletion.');
@@ -337,7 +337,7 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
entity_create('field_storage_config', $field_storage_definition)->save();
entity_create('field_config', $field_definition)->save();
$field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
- $this->assertTrue(!empty($field_storage) && empty($field_storage->deleted), 'A new storage with a previously used name is created.');
+ $this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), 'A new storage with a previously used name is created.');
$field = FieldConfig::load('entity_test.' . $field_definition['bundle'] . '.' . $field_definition['field_name'] );
$this->assertTrue(!empty($field) && empty($field->deleted), 'A new field for a previously used field name is created.');
@@ -363,7 +363,7 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
$field_storage->save();
try {
- $field_storage->type = 'integer';
+ $field_storage->set('type', 'integer');
$field_storage->save();
$this->fail(t('Cannot update a field to a different type.'));
}
@@ -403,13 +403,13 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
}
// Load back and assert there are $cardinality number of values.
$entity = $this->entitySaveReload($entity);
- $this->assertEqual(count($entity->field_update), $field_storage->cardinality);
+ $this->assertEqual(count($entity->field_update), $field_storage->getCardinality());
// Now check the values themselves.
for ($delta = 0; $delta < $cardinality; $delta++) {
$this->assertEqual($entity->field_update[$delta]->value, $delta + 1);
}
// Increase $cardinality and set the field cardinality to the new value.
- $field_storage->cardinality = ++$cardinality;
+ $field_storage->setCardinality(++$cardinality);
$field_storage->save();
} while ($cardinality < 6);
}
@@ -427,7 +427,7 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
'unchangeable' => 0
)));
$field_storage->save();
- $field_storage->settings['changeable']++;
+ $field_storage->setSetting('changeable', $field_storage->getSetting('changeable') + 1);
try {
$field_storage->save();
$this->pass(t("A changeable setting can be updated."));
@@ -435,7 +435,7 @@ class FieldStorageCrudTest extends FieldUnitTestBase {
catch (FieldStorageDefinitionUpdateForbiddenException $e) {
$this->fail(t("An unchangeable setting cannot be updated."));
}
- $field_storage->settings['unchangeable']++;
+ $field_storage->setSetting('unchangeable', $field_storage->getSetting('unchangeable') + 1);
try {
$field_storage->save();
$this->fail(t("An unchangeable setting can be updated."));
diff --git a/core/modules/field/src/Tests/FieldValidationTest.php b/core/modules/field/src/Tests/FieldValidationTest.php
index 71bb8ad..8f51b7a 100644
--- a/core/modules/field/src/Tests/FieldValidationTest.php
+++ b/core/modules/field/src/Tests/FieldValidationTest.php
@@ -48,7 +48,7 @@ class FieldValidationTest extends FieldUnitTestBase {
* Tests that the number of values is validated against the field cardinality.
*/
function testCardinalityConstraint() {
- $cardinality = $this->fieldTestData->field_storage->cardinality;
+ $cardinality = $this->fieldTestData->field_storage->getCardinality();
$entity = $this->entity;
for ($delta = 0; $delta < $cardinality + 1; $delta++) {
diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php
index 2b8f4c1..52ce2a3 100644
--- a/core/modules/field/src/Tests/reEnableModuleFieldTest.php
+++ b/core/modules/field/src/Tests/reEnableModuleFieldTest.php
@@ -39,6 +39,8 @@ class reEnableModuleFieldTest extends WebTestBase {
/**
* Test the behavior of a field module after being disabled and re-enabled.
+ *
+ * @see field_system_info_alter()
*/
function testReEnabledField() {
diff --git a/core/modules/field_ui/src/FieldConfigListBuilder.php b/core/modules/field_ui/src/FieldConfigListBuilder.php
index 167d9f7..e44bc69 100644
--- a/core/modules/field_ui/src/FieldConfigListBuilder.php
+++ b/core/modules/field_ui/src/FieldConfigListBuilder.php
@@ -149,7 +149,7 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder {
// Add the operations.
$row['data'] = $row['data'] + parent::buildRow($field_config);
- if (!empty($field_storage->locked)) {
+ if ($field_storage->isLocked()) {
$row['data']['operations'] = array('data' => array('#markup' => $this->t('Locked')));
$row['class'][] = 'menu-disabled';
}
diff --git a/core/modules/field_ui/src/FieldStorageConfigListBuilder.php b/core/modules/field_ui/src/FieldStorageConfigListBuilder.php
index a512046..d0fe42f 100644
--- a/core/modules/field_ui/src/FieldStorageConfigListBuilder.php
+++ b/core/modules/field_ui/src/FieldStorageConfigListBuilder.php
@@ -98,24 +98,25 @@ class FieldStorageConfigListBuilder extends ConfigEntityListBuilder {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $field_storage) {
- if ($field_storage->locked) {
+ if ($field_storage->isLocked()) {
$row['class'] = array('menu-disabled');
- $row['data']['id'] = t('@field_name (Locked)', array('@field_name' => $field_storage->field_name));
+ $row['data']['id'] = t('@field_name (Locked)', array('@field_name' => $field_storage->getName()));
}
else {
- $row['data']['id'] = $field_storage->field_name;
+ $row['data']['id'] = $field_storage->getName();
}
- $field_type = $this->fieldTypes[$field_storage->type];
+ $field_type = $this->fieldTypes[$field_storage->getType()];
$row['data']['type'] = t('@type (module: @module)', array('@type' => $field_type['label'], '@module' => $field_type['provider']));
$usage = array();
foreach ($field_storage->getBundles() as $bundle) {
- if ($route_info = FieldUI::getOverviewRouteInfo($field_storage->entity_type, $bundle)) {
- $usage[] = \Drupal::l($this->bundles[$field_storage->entity_type][$bundle]['label'], $route_info);
+ $entity_type_id = $field_storage->getTargetEntityTypeId();
+ if ($route_info = FieldUI::getOverviewRouteInfo($entity_type_id, $bundle)) {
+ $usage[] = \Drupal::l($this->bundles[$entity_type_id][$bundle]['label'], $route_info);
}
else {
- $usage[] = $this->bundles[$field_storage->entity_type][$bundle]['label'];
+ $usage[] = $this->bundles[$entity_type_id][$bundle]['label'];
}
}
$usage_escaped = '';
diff --git a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
index 4afe0e3..5baa57d 100644
--- a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
+++ b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
@@ -59,7 +59,7 @@ class FieldConfigDeleteForm extends EntityDeleteForm {
$bundles = $this->entityManager->getBundleInfo($this->entity->entity_type);
$bundle_label = $bundles[$this->entity->bundle]['label'];
- if ($field_storage && !$field_storage->locked) {
+ if ($field_storage && !$field_storage->isLocked()) {
$this->entity->delete();
drupal_set_message($this->t('The field %field has been deleted from the %type content type.', array('%field' => $this->entity->label(), '%type' => $bundle_label)));
}
diff --git a/core/modules/field_ui/src/Form/FieldStorageEditForm.php b/core/modules/field_ui/src/Form/FieldStorageEditForm.php
index a89f0a7..92ddca1 100644
--- a/core/modules/field_ui/src/Form/FieldStorageEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldStorageEditForm.php
@@ -155,7 +155,7 @@ class FieldStorageEditForm extends FormBase {
// Build the non-configurable field values.
$form['field_storage']['field_name'] = array('#type' => 'value', '#value' => $field_storage->getName());
$form['field_storage']['type'] = array('#type' => 'value', '#value' => $field_storage->getType());
- $form['field_storage']['module'] = array('#type' => 'value', '#value' => $field_storage->module);
+ $form['field_storage']['module'] = array('#type' => 'value', '#value' => $field_storage->getTypeProvider());
$form['field_storage']['translatable'] = array('#type' => 'value', '#value' => $field_storage->isTranslatable());
$form['actions'] = array('#type' => 'actions');
@@ -199,7 +199,7 @@ class FieldStorageEditForm extends FormBase {
// Merge incoming form values into the existing field.
$field_storage = $this->field->getFieldStorageDefinition();
foreach ($field_values as $key => $value) {
- $field_storage->{$key} = $value;
+ $field_storage->set($key, $value);
}
// Update the field.
diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php
index 3bec41b..c26b962 100644
--- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php
+++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php
@@ -173,7 +173,7 @@ class EntityDisplayTest extends KernelTestBase {
// Check that providing no options results in default values being used.
$display->setComponent($field_name);
- $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->type);
+ $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->getType());
$default_formatter = $field_type_info['default_formatter'];
$formatter_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($default_formatter);
$expected = array(
diff --git a/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php b/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php
index 0bd3e2b..6e84b95 100644
--- a/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php
+++ b/core/modules/field_ui/src/Tests/EntityFormDisplayTest.php
@@ -74,7 +74,7 @@ class EntityFormDisplayTest extends KernelTestBase {
// Check that providing no options results in default values being used.
$form_display->setComponent($field_name);
- $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->type);
+ $field_type_info = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field_storage->getType());
$default_widget = $field_type_info['default_widget'];
$widget_settings = \Drupal::service('plugin.manager.field.widget')->getDefaultSettings($default_widget);
$expected = array(
diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php
index 80dbfb9..1a42ce5 100644
--- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php
+++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php
@@ -396,7 +396,7 @@ class ManageFieldsTest extends WebTestBase {
// Check that the default value can be empty when the field is marked as
// required and can store unlimited values.
$field_storage = FieldStorageConfig::loadByName('node', $field_name);
- $field_storage->cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
+ $field_storage->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_storage->save();
$this->drupalGet($admin_path);
diff --git a/core/modules/file/file.views.inc b/core/modules/file/file.views.inc
index a8fc0fe..870a76a 100644
--- a/core/modules/file/file.views.inc
+++ b/core/modules/file/file.views.inc
@@ -37,7 +37,7 @@ function file_field_views_data(FieldStorageConfigInterface $field_storage) {
* Views integration to provide reverse relationships on file fields.
*/
function file_field_views_data_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) {
- $entity_type_id = $field_storage->entity_type;
+ $entity_type_id = $field_storage->getTargetEntityTypeId();
$entity_manager = \Drupal::entityManager();
$entity_type = $entity_manager->getDefinition($entity_type_id);
$field_name = $field_storage->getName();
diff --git a/core/modules/image/image.module b/core/modules/image/image.module
index 7671030..cc326b3 100644
--- a/core/modules/image/image.module
+++ b/core/modules/image/image.module
@@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\field\Entity\FieldConfig;
use Drupal\file\Entity\File;
use Drupal\field\FieldStorageConfigInterface;
use Drupal\field\FieldConfigInterface;
@@ -321,49 +322,51 @@ function image_filter_keyword($value, $current_pixels, $new_pixels) {
* Transforms default image of image field from array into single value at save.
*/
function image_entity_presave(EntityInterface $entity) {
- $field_storage = FALSE;
- $entity_type_id = $entity->getEntityTypeId();
- if ($entity_type_id == 'field_config') {
- $field_storage = $entity->getFieldStorageDefinition();
- $default_settings = \Drupal::service('plugin.manager.field.field_type')->getDefaultFieldSettings('image');
+ // Get the default image settings, return if not saving an image field storage
+ // or image field entity.
+ if (($entity instanceof FieldStorageConfigInterface || $entity instanceof FieldConfigInterface) && $entity->getType() == 'image') {
+ $default_image = $entity->getSetting('default_image');
}
- elseif ($entity_type_id == 'field_storage_config') {
- $field_storage = $entity;
- $default_settings = \Drupal::service('plugin.manager.field.field_type')->getDefaultStorageSettings('image');
- }
- // Exit, if not saving an image field storage or image field entity.
- if (!$field_storage || $field_storage->type != 'image') {
+ else {
return;
}
- if ($field_storage->isSyncing()) {
+ if ($entity->isSyncing()) {
return;
}
- $uuid = $entity->settings['default_image']['uuid'];
+ $uuid = $default_image['uuid'];
if ($uuid) {
- $original_uuid = isset($entity->original) ? $entity->original->settings['default_image']['uuid'] : NULL;
+ $original_uuid = isset($entity->original) ? $entity->original->getSetting('default_image')['uuid'] : NULL;
if ($uuid != $original_uuid) {
$file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid);
if ($file) {
$image = \Drupal::service('image.factory')->get($file->getFileUri());
- $entity->settings['default_image']['width'] = $image->getWidth();
- $entity->settings['default_image']['height'] = $image->getHeight();
+ $default_image['width'] = $image->getWidth();
+ $default_image['height'] = $image->getHeight();
}
else {
- $entity->settings['default_image']['uuid'] = NULL;
+ $default_image['uuid'] = NULL;
}
}
}
- $entity->settings['default_image'] += $default_settings['default_image'];
+ // @todo Simplify this in https://www.drupal.org/node/2030637, when both
+ // interfaces have a setSetting() method.
+ if ($entity instanceof FieldStorageConfigInterface) {
+ $entity->setSetting('default_image', $default_image);
+ }
+ elseif ($entity instanceof FieldConfig) {
+ $entity->settings['default_image'] = $default_image;
+ }
+
}
/**
* Implements hook_ENTITY_TYPE_update() for 'field_storage_config'.
*/
function image_field_storage_config_update(FieldStorageConfigInterface $field_storage) {
- if ($field_storage->type != 'image') {
+ if ($field_storage->getType() != 'image') {
// Only act on image fields.
return;
}
@@ -371,8 +374,8 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st
$prior_field_storage = $field_storage->original;
// The value of a managed_file element can be an array if #extended == TRUE.
- $uuid_new = $field_storage->settings['default_image']['uuid'];
- $uuid_old = $prior_field_storage->settings['default_image']['uuid'];
+ $uuid_new = $field_storage->getSetting('default_image')['uuid'];
+ $uuid_old = $prior_field_storage->getSetting('default_image')['uuid'];
$file_new = $uuid_new ? \Drupal::entityManager()->loadEntityByUuid('file', $uuid_new) : FALSE;
@@ -392,8 +395,8 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st
}
// If the upload destination changed, then move the file.
- if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_storage->settings['uri_scheme'])) {
- $directory = $field_storage->settings['uri_scheme'] . '://default_images/';
+ if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_storage->getSetting('uri_scheme'))) {
+ $directory = $field_storage->getSetting('uri_scheme') . '://default_images/';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
file_move($file_new, $directory . $file_new->filename);
}
@@ -404,14 +407,14 @@ function image_field_storage_config_update(FieldStorageConfigInterface $field_st
*/
function image_field_config_update(FieldConfigInterface $field) {
$field_storage = $field->getFieldStorageDefinition();
- if ($field_storage->type != 'image') {
+ if ($field_storage->getType() != 'image') {
// Only act on image fields.
return;
}
$prior_instance = $field->original;
- $uuid_new = $field->settings['default_image']['uuid'];
+ $uuid_new = $field->getSetting('default_image')['uuid'];
$uuid_old = $prior_instance->settings['default_image']['uuid'];
// If the old and new files do not match, update the default accordingly.
@@ -430,8 +433,8 @@ function image_field_config_update(FieldConfigInterface $field) {
}
// If the upload destination changed, then move the file.
- if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_storage->settings['uri_scheme'])) {
- $directory = $field_storage->settings['uri_scheme'] . '://default_images/';
+ if ($file_new && (file_uri_scheme($file_new->getFileUri()) != $field_storage->getSetting('uri_scheme'))) {
+ $directory = $field_storage->getSetting('uri_scheme') . '://default_images/';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
file_move($file_new, $directory . $file_new->filename);
}
@@ -441,13 +444,13 @@ function image_field_config_update(FieldConfigInterface $field) {
* Implements hook_ENTITY_TYPE_delete() for 'field_storage_config'.
*/
function image_field_storage_config_delete(FieldStorageConfigInterface $field) {
- if ($field->type != 'image') {
+ if ($field->getType() != 'image') {
// Only act on image fields.
return;
}
// The value of a managed_file element can be an array if #extended == TRUE.
- $uuid = $field->settings['default_image']['uuid'];
+ $uuid = $field->getSetting('default_image')['uuid'];
if ($uuid && ($file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid))) {
\Drupal::service('file.usage')->delete($file, 'image', 'default_image', $field->uuid());
}
@@ -458,7 +461,7 @@ function image_field_storage_config_delete(FieldStorageConfigInterface $field) {
*/
function image_field_config_delete(FieldConfigInterface $field) {
$field_storage = $field->getFieldStorageDefinition();
- if ($field_storage->type != 'image') {
+ if ($field_storage->getType() != 'image') {
// Only act on image fields.
return;
}
diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
index a546590..ce1e15f 100644
--- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
+++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php
@@ -175,7 +175,9 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase {
);
// Upload a new default for the field storage.
- $field_storage->settings['default_image']['uuid'] = $default_images['field_new']->uuid();
+ $default_image_settings = $field_storage->getSetting('default_image');
+ $default_image_settings['uuid'] = $default_images['field_new']->uuid();
+ $field_storage->setSetting('default_image', $default_image_settings);
$field_storage->save();
// Confirm that the new default is used on the article field settings form.
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php
index 296ae36..bb91962 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateFieldTest.php
@@ -52,27 +52,27 @@ class MigrateFieldTest extends MigrateDrupalTestBase {
/** @var \Drupal\field\Entity\FieldStorageConfig $field_storage */
$field_storage = FieldStorageConfig::load('node.field_test');
$expected = array('max_length' => 255);
- $this->assertIdentical($field_storage->type, "text", t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->type)));
- $this->assertIdentical($field_storage->settings, $expected, "Field type text settings are correct");
+ $this->assertIdentical($field_storage->getType(), "text", t('Field type is @fieldtype. It should be text.', array('@fieldtype' => $field_storage->getType())));
+ $this->assertIdentical($field_storage->getSettings(), $expected, "Field type text settings are correct");
// Integer field.
$field_storage = FieldStorageConfig::load('node.field_test_two');
- $this->assertIdentical($field_storage->type, "integer", t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "integer", t('Field type is @fieldtype. It should be integer.', array('@fieldtype' => $field_storage->getType())));
// Float field.
$field_storage = FieldStorageConfig::load('node.field_test_three');
- $this->assertIdentical($field_storage->type, "decimal", t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "decimal", t('Field type is @fieldtype. It should be decimal.', array('@fieldtype' => $field_storage->getType())));
// Link field.
$field_storage = FieldStorageConfig::load('node.field_test_link');
- $this->assertIdentical($field_storage->type, "link", t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "link", t('Field type is @fieldtype. It should be link.', array('@fieldtype' => $field_storage->getType())));
// File field.
$field_storage = FieldStorageConfig::load('node.field_test_filefield');
- $this->assertIdentical($field_storage->type, "file", t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "file", t('Field type is @fieldtype. It should be file.', array('@fieldtype' => $field_storage->getType())));
$field_storage = FieldStorageConfig::load('node.field_test_imagefield');
- $this->assertIdentical($field_storage->type, "image", t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "image", t('Field type is @fieldtype. It should be image.', array('@fieldtype' => $field_storage->getType())));
$settings = $field_storage->getSettings();
$this->assertIdentical($settings['target_type'], 'file');
$this->assertIdentical($settings['uri_scheme'], 'public');
@@ -80,39 +80,39 @@ class MigrateFieldTest extends MigrateDrupalTestBase {
// Phone field.
$field_storage = FieldStorageConfig::load('node.field_test_phone');
- $this->assertIdentical($field_storage->type, "telephone", t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "telephone", t('Field type is @fieldtype. It should be telephone.', array('@fieldtype' => $field_storage->getType())));
// Date field.
$field_storage = FieldStorageConfig::load('node.field_test_datetime');
- $this->assertIdentical($field_storage->type, "datetime", t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "datetime", t('Field type is @fieldtype. It should be datetime.', array('@fieldtype' => $field_storage->getType())));
// Decimal field with radio buttons.
$field_storage = FieldStorageConfig::load('node.field_test_decimal_radio_buttons');
- $this->assertIdentical($field_storage->type, "list_float", t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->type)));
- $this->assertNotNull($field_storage->settings['allowed_values']['1.2'], t('First allowed value key is set to 1.2'));
- $this->assertNotNull($field_storage->settings['allowed_values']['2.1'], t('Second allowed value key is set to 2.1'));
- $this->assertIdentical($field_storage->settings['allowed_values']['1.2'], '1.2', t('First allowed value is set to 1.2'));
- $this->assertIdentical($field_storage->settings['allowed_values']['2.1'], '2.1', t('Second allowed value is set to 1.2'));
+ $this->assertIdentical($field_storage->getType(), "list_float", t('Field type is @fieldtype. It should be list_float.', array('@fieldtype' => $field_storage->getType())));
+ $this->assertNotNull($field_storage->getSetting('allowed_values')['1.2'], t('First allowed value key is set to 1.2'));
+ $this->assertNotNull($field_storage->getSetting('allowed_values')['2.1'], t('Second allowed value key is set to 2.1'));
+ $this->assertIdentical($field_storage->getSetting('allowed_values')['1.2'], '1.2', t('First allowed value is set to 1.2'));
+ $this->assertIdentical($field_storage->getSetting('allowed_values')['2.1'], '2.1', t('Second allowed value is set to 1.2'));
// Float field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_float_single_checkbox');
- $this->assertIdentical($field_storage->type, "boolean", t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "boolean", t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
// Integer field with a select list.
$field_storage = FieldStorageConfig::load('node.field_test_integer_selectlist');
- $this->assertIdentical($field_storage->type, "list_integer", t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->type)));
- $this->assertNotNull($field_storage->settings['allowed_values']['1234'], t('First allowed value key is set to 1234'));
- $this->assertNotNull($field_storage->settings['allowed_values']['2341'], t('Second allowed value key is set to 2341'));
- $this->assertNotNull($field_storage->settings['allowed_values']['3412'], t('Third allowed value key is set to 3412'));
- $this->assertNotNull($field_storage->settings['allowed_values']['4123'], t('Fourth allowed value key is set to 4123'));
- $this->assertIdentical($field_storage->settings['allowed_values']['1234'], '1234', t('First allowed value is set to 1234'));
- $this->assertIdentical($field_storage->settings['allowed_values']['2341'], '2341', t('Second allowed value is set to 2341'));
- $this->assertIdentical($field_storage->settings['allowed_values']['3412'], '3412', t('Third allowed value is set to 3412'));
- $this->assertIdentical($field_storage->settings['allowed_values']['4123'], '4123', t('Fourth allowed value is set to 4123'));
+ $this->assertIdentical($field_storage->getType(), "list_integer", t('Field type is @fieldtype. It should be list_integer.', array('@fieldtype' => $field_storage->getType())));
+ $this->assertNotNull($field_storage->getSetting('allowed_values')['1234'], t('First allowed value key is set to 1234'));
+ $this->assertNotNull($field_storage->getSetting('allowed_values')['2341'], t('Second allowed value key is set to 2341'));
+ $this->assertNotNull($field_storage->getSetting('allowed_values')['3412'], t('Third allowed value key is set to 3412'));
+ $this->assertNotNull($field_storage->getSetting('allowed_values')['4123'], t('Fourth allowed value key is set to 4123'));
+ $this->assertIdentical($field_storage->getSetting('allowed_values')['1234'], '1234', t('First allowed value is set to 1234'));
+ $this->assertIdentical($field_storage->getSetting('allowed_values')['2341'], '2341', t('Second allowed value is set to 2341'));
+ $this->assertIdentical($field_storage->getSetting('allowed_values')['3412'], '3412', t('Third allowed value is set to 3412'));
+ $this->assertIdentical($field_storage->getSetting('allowed_values')['4123'], '4123', t('Fourth allowed value is set to 4123'));
// Text field with a single checkbox.
$field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox');
- $this->assertIdentical($field_storage->type, "boolean", t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->type)));
+ $this->assertIdentical($field_storage->getType(), "boolean", t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType())));
}
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php
index 35644ce..79a9362 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateUserProfileFieldTest.php
@@ -44,20 +44,20 @@ class MigrateUserProfileFieldTest extends MigrateDrupalTestBase {
public function testUserProfileFields() {
// Migrated a text field.
$field_storage = FieldStorageConfig::load('user.profile_color');
- $this->assertIdentical($field_storage->type, 'text', 'Field type is text.');
- $this->assertIdentical($field_storage->cardinality, 1, 'Text field has correct cardinality');
+ $this->assertIdentical($field_storage->getType(), 'text', 'Field type is text.');
+ $this->assertIdentical($field_storage->getCardinality(), 1, 'Text field has correct cardinality');
// Migrated a textarea.
$field_storage = FieldStorageConfig::load('user.profile_biography');
- $this->assertIdentical($field_storage->type, 'text_long', 'Field type is text_long.');
+ $this->assertIdentical($field_storage->getType(), 'text_long', 'Field type is text_long.');
// Migrated checkbox field.
$field_storage = FieldStorageConfig::load('user.profile_sell_address');
- $this->assertIdentical($field_storage->type, 'boolean', 'Field type is boolean.');
+ $this->assertIdentical($field_storage->getType(), 'boolean', 'Field type is boolean.');
// Migrated selection field.
$field_storage = FieldStorageConfig::load('user.profile_sold_to');
- $this->assertIdentical($field_storage->type, 'list_string', 'Field type is list_string.');
+ $this->assertIdentical($field_storage->getType(), 'list_string', 'Field type is list_string.');
$settings = $field_storage->getSettings();
$this->assertIdentical($settings['allowed_values'], array(
'Pill spammers' => 'Pill spammers',
@@ -68,23 +68,23 @@ class MigrateUserProfileFieldTest extends MigrateDrupalTestBase {
'Faithful servant' => 'Faithful servant',
'Anonymous donor' => 'Anonymous donor',
));
- $this->assertIdentical($field_storage->type, 'list_string', 'Field type is list_string.');
+ $this->assertIdentical($field_storage->getType(), 'list_string', 'Field type is list_string.');
// Migrated list field.
$field_storage = FieldStorageConfig::load('user.profile_bands');
- $this->assertIdentical($field_storage->type, 'text', 'Field type is text.');
- $this->assertIdentical($field_storage->cardinality, -1, 'List field has correct cardinality');
+ $this->assertIdentical($field_storage->getType(), 'text', 'Field type is text.');
+ $this->assertIdentical($field_storage->getCardinality(), -1, 'List field has correct cardinality');
/*
// Migrated URL field.
$field_storage = FieldStorageConfig::load('user.profile_blog');
- $this->assertIdentical($field_storage->type, 'link', 'Field type is link.');
+ $this->assertIdentical($field_storage->getType(), 'link', 'Field type is link.');
*/
// Migrated date field.
$field_storage = FieldStorageConfig::load('user.profile_birthdate');
- $this->assertIdentical($field_storage->type, 'datetime', 'Field type is datetime.');
- $this->assertIdentical($field_storage->settings['datetime_type'], 'date');
+ $this->assertIdentical($field_storage->getType(), 'datetime', 'Field type is datetime.');
+ $this->assertIdentical($field_storage->getSettings()['datetime_type'], 'date');
}
}
diff --git a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php b/core/modules/node/src/Tests/NodeFieldMultilingualTest.php
index dc8897b..dd8aec2 100644
--- a/core/modules/node/src/Tests/NodeFieldMultilingualTest.php
+++ b/core/modules/node/src/Tests/NodeFieldMultilingualTest.php
@@ -53,7 +53,7 @@ class NodeFieldMultilingualTest extends WebTestBase {
// Make node body translatable.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
}
diff --git a/core/modules/node/src/Tests/Views/NodeLanguageTest.php b/core/modules/node/src/Tests/Views/NodeLanguageTest.php
index 0195b44..4ced144 100644
--- a/core/modules/node/src/Tests/Views/NodeLanguageTest.php
+++ b/core/modules/node/src/Tests/Views/NodeLanguageTest.php
@@ -57,7 +57,7 @@ class NodeLanguageTest extends NodeTestBase {
// Make the body field translatable. The title is already translatable by
// definition.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
// Set up node titles. They should not include the words "French",
diff --git a/core/modules/options/options.module b/core/modules/options/options.module
index a2e8f06..d221adb 100644
--- a/core/modules/options/options.module
+++ b/core/modules/options/options.module
@@ -106,12 +106,12 @@ function options_allowed_values(FieldStorageDefinitionInterface $definition, Fie
* Implements hook_field_storage_config_update_forbid().
*/
function options_field_storage_config_update_forbid(FieldStorageConfigInterface $field_storage, FieldStorageConfigInterface $prior_field_storage) {
- if ($field_storage->module == 'options' && $field_storage->hasData()) {
+ if ($field_storage->getTypeProvider() == 'options' && $field_storage->hasData()) {
// Forbid any update that removes allowed values with actual data.
$allowed_values = $field_storage->getSetting('allowed_values');
$prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
$lost_keys = array_keys(array_diff_key($prior_allowed_values, $allowed_values));
- if (_options_values_in_use($field_storage->entity_type, $field_storage->getName(), $lost_keys)) {
+ if (_options_values_in_use($field_storage->getTargetEntityTypeId(), $field_storage->getName(), $lost_keys)) {
throw new FieldStorageDefinitionUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field_storage->getName())));
}
}
diff --git a/core/modules/options/options.views.inc b/core/modules/options/options.views.inc
index 95b8474..8eb35c2 100644
--- a/core/modules/options/options.views.inc
+++ b/core/modules/options/options.views.inc
@@ -7,6 +7,8 @@
* @ingroup views_module_handlers
*/
+use Drupal\field\FieldStorageConfigInterface;
+
/**
* Implements hook_field_views_data().
*
@@ -14,7 +16,7 @@
* argument handlers for list fields. This should allow to select values of
* the list.
*/
-function options_field_views_data($field) {
+function options_field_views_data(FieldStorageConfigInterface $field) {
$data = views_field_default_views_data($field);
$function = $field->getSetting('allowed_values_function');
@@ -29,7 +31,7 @@ function options_field_views_data($field) {
$data[$table_name][$field_name]['filter']['id'] = 'list_field';
}
if (isset($field_data['argument']) && $field_name != 'delta') {
- if ($field->type == 'list_string') {
+ if ($field->getType() == 'list_string') {
$data[$table_name][$field_name]['argument']['id'] = 'string_list_field';
}
else {
diff --git a/core/modules/options/src/Tests/OptionsFieldTest.php b/core/modules/options/src/Tests/OptionsFieldTest.php
index a6f0b97..5ad5953 100644
--- a/core/modules/options/src/Tests/OptionsFieldTest.php
+++ b/core/modules/options/src/Tests/OptionsFieldTest.php
@@ -39,7 +39,7 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
$entity = entity_create('entity_test');
$entity->{$this->fieldName}->value = 1;
$entity->save();
- $this->fieldStorage->settings['allowed_values'] = array(2 => 'Two');
+ $this->fieldStorage->setSetting('allowed_values', [2 => 'Two']);
try {
$this->fieldStorage->save();
$this->fail(t('Cannot update a list field storage to not include keys with existing data.'));
@@ -52,7 +52,7 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
$entity->save();
// Removed options do not appear.
- $this->fieldStorage->settings['allowed_values'] = array(2 => 'Two');
+ $this->fieldStorage->setSetting('allowed_values', [2 => 'Two']);
$this->fieldStorage->save();
$entity = entity_create('entity_test');
$form = \Drupal::service('entity.form_builder')->getForm($entity);
@@ -61,7 +61,7 @@ class OptionsFieldTest extends OptionsFieldUnitTestBase {
$this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist');
// Completely new options appear.
- $this->fieldStorage->settings['allowed_values'] = array(10 => 'Update', 20 => 'Twenty');
+ $this->fieldStorage->setSetting('allowed_values', [10 => 'Update', 20 => 'Twenty']);
$this->fieldStorage->save();
// The entity holds an outdated field object with the old allowed values
// setting, so we need to reintialize the entity object.
diff --git a/core/modules/options/src/Tests/OptionsWidgetsTest.php b/core/modules/options/src/Tests/OptionsWidgetsTest.php
index 3c2b68b..0de54a5 100644
--- a/core/modules/options/src/Tests/OptionsWidgetsTest.php
+++ b/core/modules/options/src/Tests/OptionsWidgetsTest.php
@@ -132,7 +132,7 @@ class OptionsWidgetsTest extends FieldTestBase {
$this->assertFieldValues($entity_init, 'card_1', array());
// Check that required radios with one option is auto-selected.
- $this->card1->settings['allowed_values'] = [99 => 'Only allowed value'];
+ $this->card1->setSetting('allowed_values', [99 => 'Only allowed value']);
$this->card1->save();
$field->required = TRUE;
$field->save();
@@ -221,7 +221,7 @@ class OptionsWidgetsTest extends FieldTestBase {
$this->assertFieldValues($entity_init, 'card_2', array());
// Required checkbox with one option is auto-selected.
- $this->card2->settings['allowed_values'] = array(99 => 'Only allowed value');
+ $this->card2->setSetting('allowed_values', [99 => 'Only allowed value']);
$this->card2->save();
$field->required = TRUE;
$field->save();
@@ -299,8 +299,8 @@ class OptionsWidgetsTest extends FieldTestBase {
// Test optgroups.
- $this->card1->settings['allowed_values'] = array();
- $this->card1->settings['allowed_values_function'] = 'options_test_allowed_values_callback';
+ $this->card1->setSetting('allowed_values', []);
+ $this->card1->setSetting('allowed_values_function', 'options_test_allowed_values_callback');
$this->card1->save();
// Display form: with no field data, nothing is selected
@@ -418,8 +418,8 @@ class OptionsWidgetsTest extends FieldTestBase {
// Test optgroups.
// Use a callback function defining optgroups.
- $this->card2->settings['allowed_values'] = array();
- $this->card2->settings['allowed_values_function'] = 'options_test_allowed_values_callback';
+ $this->card2->setSetting('allowed_values', []);
+ $this->card2->setSetting('allowed_values_function', 'options_test_allowed_values_callback');
$this->card2->save();
$field->required = FALSE;
$field->save();
diff --git a/core/modules/quickedit/src/Tests/EditorSelectionTest.php b/core/modules/quickedit/src/Tests/EditorSelectionTest.php
index 336fbec..d148408 100644
--- a/core/modules/quickedit/src/Tests/EditorSelectionTest.php
+++ b/core/modules/quickedit/src/Tests/EditorSelectionTest.php
@@ -74,7 +74,7 @@ class EditorSelectionTest extends QuickEditTestBase {
$this->assertEqual('plain_text', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality 1, the 'plain_text' editor is selected.");
// With cardinality >1
- $this->fields->field_text_field_storage->cardinality = 2;
+ $this->fields->field_text_field_storage->setCardinality(2);
$this->fields->field_text_field_storage->save();
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality >1, the 'form' editor is selected.");
@@ -119,7 +119,7 @@ class EditorSelectionTest extends QuickEditTestBase {
$this->assertEqual('wysiwyg', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected.");
// Editor selection with text field, cardinality >1.
- $this->fields->field_textarea_field_storage->cardinality = 2;
+ $this->fields->field_textarea_field_storage->setCardinality(2);
$this->fields->field_textarea_field_storage->save();
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}
@@ -150,7 +150,7 @@ class EditorSelectionTest extends QuickEditTestBase {
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality 1, the 'form' editor is selected.");
// Editor selection with cardinality >1.
- $this->fields->field_nr_field_storage->cardinality = 2;
+ $this->fields->field_nr_field_storage->setCardinality(2);
$this->fields->field_nr_field_storage->save();
$this->assertEqual('form', $this->getSelectedEditor($entity->id(), $field_name), "With cardinality >1, the 'form' editor is selected.");
}
diff --git a/core/modules/search/src/Tests/SearchLanguageTest.php b/core/modules/search/src/Tests/SearchLanguageTest.php
index b6f8d2b..f4acf9c 100644
--- a/core/modules/search/src/Tests/SearchLanguageTest.php
+++ b/core/modules/search/src/Tests/SearchLanguageTest.php
@@ -45,7 +45,7 @@ class SearchLanguageTest extends SearchTestBase {
// definition. The parent class has already created the article and page
// content types.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
// Create a few page nodes with multilingual body values.
diff --git a/core/modules/search/src/Tests/SearchMultilingualEntityTest.php b/core/modules/search/src/Tests/SearchMultilingualEntityTest.php
index 0370ee2..ad2445f 100644
--- a/core/modules/search/src/Tests/SearchMultilingualEntityTest.php
+++ b/core/modules/search/src/Tests/SearchMultilingualEntityTest.php
@@ -59,7 +59,7 @@ class SearchMultilingualEntityTest extends SearchTestBase {
// definition. The parent class has already created the article and page
// content types.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
// Create a few page nodes with multilingual body values.
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php
index cee9a0b..933f8dd 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php
@@ -99,7 +99,7 @@ class EntityTranslationFormTest extends WebTestBase {
// Make body translatable.
$field_storage = FieldStorageConfig::loadByName('node', 'body');
- $field_storage->translatable = TRUE;
+ $field_storage->setTranslatable(TRUE);
$field_storage->save();
$field_storage = FieldStorageConfig::loadByName('node', 'body');
$this->assertTrue($field_storage->isTranslatable(), 'Field body is translatable.');
diff --git a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
index 8fdb484..688daf2 100644
--- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
+++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php
@@ -332,7 +332,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
$entity->save();
// Attempt to update the field in a way that would work without data.
- $field_storage->settings['scale'] = 3;
+ $field_storage->setSetting('scale', 3);
try {
$field_storage->save();
$this->fail(t('Cannot update field schema with data.'));
@@ -357,7 +357,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
// Attempt to update the field in a way that would break the storage.
$prior_field_storage = $field_storage;
- $field_storage->settings['max_length'] = -1;
+ $field_storage->setSetting('max_length', -1);
try {
$field_storage->save();
$this->fail(t('Update succeeded.'));
@@ -412,14 +412,14 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
$entity->save();
// Add an index.
- $field_storage->indexes = array('value' => array(array('value', 255)));
+ $field_storage->setIndexes(['value' => [['value', 255]]]);
$field_storage->save();
foreach ($tables as $table) {
$this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value"), t("Index on value created in @table", array('@table' => $table)));
}
// Add a different index, removing the existing custom one.
- $field_storage->indexes = array('value_format' => array(array('value', 127), array('format', 127)));
+ $field_storage->setIndexes(['value_format' => [['value', 127], ['format', 127]]]);
$field_storage->save();
foreach ($tables as $table) {
$this->assertTrue(Database::getConnection()->schema()->indexExists($table, "{$field_name}_value_format"), t("Index on value_format created in @table", array('@table' => $table)));
@@ -455,7 +455,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
// Update the field settings, it should update the foreign key definition too.
$foreign_key_name = 'color';
- $field_storage->settings['foreign_key_name'] = $foreign_key_name;
+ $field_storage->setSetting('foreign_key_name', $foreign_key_name);
$field_storage->save();
// Reload the field schema after the update.
$schema = $field_storage->getSchema();
diff --git a/core/modules/taxonomy/src/Entity/Vocabulary.php b/core/modules/taxonomy/src/Entity/Vocabulary.php
index ae7b10f..b8edfde 100644
--- a/core/modules/taxonomy/src/Entity/Vocabulary.php
+++ b/core/modules/taxonomy/src/Entity/Vocabulary.php
@@ -137,12 +137,14 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
foreach ($field_storages as $field_storage) {
$update_storage = FALSE;
- foreach ($field_storage->settings['allowed_values'] as &$value) {
+ $allowed_values = $field_storage->getSetting('allowed_values');
+ foreach ($allowed_values as &$value) {
if ($value['vocabulary'] == $this->getOriginalId()) {
$value['vocabulary'] = $this->id();
$update_storage = TRUE;
}
}
+ $field_storage->setSetting('allowed_values', $allowed_values);
if ($update_storage) {
$field_storage->save();
@@ -186,14 +188,17 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
$modified_storage = FALSE;
// Term reference fields may reference terms from more than one
// vocabulary.
- foreach ($field_storage->settings['allowed_values'] as $key => $allowed_value) {
+ foreach ($field_storage->getSetting('allowed_values') as $key => $allowed_value) {
if (isset($vocabularies[$allowed_value['vocabulary']])) {
- unset($field_storage->settings['allowed_values'][$key]);
+ $allowed_values = $field_storage->getSetting('allowed_values');
+ unset($allowed_values[$key]);
+ $field_storage->setSetting('allowed_values', $allowed_values);
$modified_storage = TRUE;
}
}
if ($modified_storage) {
- if (empty($field_storage->settings['allowed_values'])) {
+ $allowed_values = $field_storage->getSetting('allowed_values');
+ if (empty($allowed_values)) {
$field_storage->delete();
}
else {
diff --git a/core/modules/taxonomy/src/Tests/TermFieldTest.php b/core/modules/taxonomy/src/Tests/TermFieldTest.php
index e3f0abd..d41a083 100644
--- a/core/modules/taxonomy/src/Tests/TermFieldTest.php
+++ b/core/modules/taxonomy/src/Tests/TermFieldTest.php
@@ -161,7 +161,7 @@ class TermFieldTest extends TaxonomyTestBase {
function testTaxonomyTermFieldChangeMachineName() {
// Add several entries in the 'allowed_values' setting, to make sure that
// they all get updated.
- $this->fieldStorage->settings['allowed_values'] = array(
+ $this->fieldStorage->setSetting('allowed_values', [
array(
'vocabulary' => $this->vocabulary->id(),
'parent' => '0',
@@ -174,7 +174,7 @@ class TermFieldTest extends TaxonomyTestBase {
'vocabulary' => 'foo',
'parent' => '0',
),
- );
+ ]);
$this->fieldStorage->save();
// Change the machine name.
$new_name = Unicode::strtolower($this->randomMachineName());
diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/src/Tests/UserRegistrationTest.php
index 221667f..f1eb637 100644
--- a/core/modules/user/src/Tests/UserRegistrationTest.php
+++ b/core/modules/user/src/Tests/UserRegistrationTest.php
@@ -247,7 +247,7 @@ class UserRegistrationTest extends WebTestBase {
$this->assertEqual($new_user->test_user_field->value, $value, 'The field value was correclty saved.');
// Check that the 'add more' button works.
- $field_storage->cardinality = FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED;
+ $field_storage->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_storage->save();
foreach (array('js', 'nojs') as $js) {
$this->drupalGet('user/register');
diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php
index 9f2813b..2001c83 100644
--- a/core/modules/views/views.api.php
+++ b/core/modules/views/views.api.php
@@ -500,7 +500,7 @@ function hook_field_views_data(\Drupal\field\FieldStorageConfigInterface $field_
* @see hook_field_views_data_views_data_alter()
*/
function hook_field_views_data_alter(array &$data, \Drupal\field\FieldStorageConfigInterface $field_storage) {
- $entity_type_id = $field_storage->entity_type;
+ $entity_type_id = $field_storage->getTargetEntityTypeId();
$field_name = $field_storage->getName();
$entity_type = \Drupal::entityManager()->getDefinition($entity_type_id);
$pseudo_field_name = 'reverse_' . $field_name . '_' . $entity_type_id;
diff --git a/core/modules/views/views.views.inc b/core/modules/views/views.views.inc
index 1e91727..2037645 100644
--- a/core/modules/views/views.views.inc
+++ b/core/modules/views/views.views.inc
@@ -176,9 +176,10 @@ function views_views_data() {
$entity_manager = \Drupal::entityManager();
if ($entity_manager->hasDefinition('field_storage_config')) {
+ /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
foreach ($entity_manager->getStorage('field_storage_config')->loadMultiple() as $field_storage) {
if (_views_field_get_entity_type_storage($field_storage)) {
- $result = (array) $module_handler->invoke($field_storage->module, 'field_views_data', array($field_storage));
+ $result = (array) $module_handler->invoke($field_storage->getTypeProvider(), 'field_views_data', array($field_storage));
if (empty($result)) {
$result = views_field_default_views_data($field_storage);
}
@@ -207,9 +208,10 @@ function views_views_data_alter(&$data) {
if (!$entity_manager->hasDefinition('field_storage_config')) {
return;
}
+ /** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
foreach ($entity_manager->getStorage('field_storage_config')->loadMultiple() as $field_storage) {
if (_views_field_get_entity_type_storage($field_storage)) {
- $function = $field_storage->module . '_field_views_data_views_data_alter';
+ $function = $field_storage->getTypeProvider() . '_field_views_data_views_data_alter';
if (function_exists($function)) {
$function($data, $field_storage);
}