diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 04a59dc..7907ef0 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -164,7 +164,7 @@ class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigI * * @var array */ - protected $indexes = array(); + protected $indexes = []; /** * Flag indicating whether the field is deleted. @@ -316,8 +316,6 @@ protected function preSaveNew(EntityStorageInterface $storage) { // Notify the entity manager. $entity_manager->onFieldStorageDefinitionCreate($this); - // @todo Or this? (taken from patch at https://www.drupal.org/node/2030633#comment-9015925) - // $entity_manager->getStorage($this->getTargetEntityTypeId())->onFieldStorageDefinitionCreate($this); } /** @@ -359,8 +357,6 @@ protected function preSaveUpdated(EntityStorageInterface $storage) { // update as invalid by raising an exception, which stops execution before // the definition is written to config. $entity_manager->onFieldStorageDefinitionUpdate($this, $this->original); - // @todo Or this? (taken from patch at https://www.drupal.org/node/2030633#comment-9015925) - // $entity_manager->getStorage($this->getTargetEntityTypeId())->onFieldStorageDefinitionUpdate($this, $this->original); } /** @@ -491,8 +487,7 @@ public function getColumns() { * {@inheritdoc} */ public function getBundles() { - $deleted = $this->isDeleted(); - if (empty($deleted)) { + if (!$this->isDeleted()) { $map = \Drupal::entityManager()->getFieldMap(); if (isset($map[$this->getTargetEntityTypeId()][$this->getName()]['bundles'])) { return $map[$this->getTargetEntityTypeId()][$this->getName()]['bundles']; @@ -574,7 +569,7 @@ public function setSetting($setting_name, $value) { * {@inheritdoc} */ public function setSettings($settings) { - $this->set('settings', $settings); + $this->settings = $settings; return $this; } @@ -633,7 +628,7 @@ public function getCardinality() { * {@inheritdoc} */ public function setCardinality($cardinality) { - $this->set('cardinality', $cardinality); + $this->cardinality = $cardinality; return $this; } @@ -676,7 +671,7 @@ public function isLocked() { * {@inheritdoc} */ public function setLocked($locked) { - $this->set('locked', $locked); + $this->locked = $locked; return $this; } @@ -812,4 +807,18 @@ public function isDeletable() { return !$this->deleted && !$this->persist_with_no_fields && count($this->getBundles()) == 0; } + /** + * {@inheritdoc} + */ + public function getIndexes() { + return $this->indexes; + } + + /** + * {@inheritdoc} + */ + public function setIndexes($indexes) { + $this->indexes = $indexes; + return $this; + } } diff --git a/core/modules/field/src/FieldStorageConfigInterface.php b/core/modules/field/src/FieldStorageConfigInterface.php index 84a73f3..c7a7da8 100644 --- a/core/modules/field/src/FieldStorageConfigInterface.php +++ b/core/modules/field/src/FieldStorageConfigInterface.php @@ -53,7 +53,7 @@ public function setLocked($locked); * Returns whether the field is deleted or not. * * @return bool - * The deleted property. + * TRUE if the field is deleted. */ public function isDeleted(); @@ -80,9 +80,9 @@ public function setCardinality($cardinality); public function setSetting($setting_name, $value); /** - * Sets field settings by overwriting the settings array. + * Sets field settings (overwrites existing settings). * - * @param string $settings + * @param array $settings * The array of field settings. * * @return $this @@ -107,4 +107,22 @@ public function getModule(); */ 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($indexes); + } diff --git a/core/modules/field/src/FieldStorageConfigStorage.php b/core/modules/field/src/FieldStorageConfigStorage.php index 5503d28..0f4bdba 100644 --- a/core/modules/field/src/FieldStorageConfigStorage.php +++ b/core/modules/field/src/FieldStorageConfigStorage.php @@ -156,7 +156,7 @@ public function loadByProperties(array $conditions = array()) { break; default: - $checked_value = $field->$key; + $checked_value = $field->get($key); } // Skip to the next field as soon as one condition does not match. diff --git a/core/modules/field/src/Tests/FieldStorageCrudTest.php b/core/modules/field/src/Tests/FieldStorageCrudTest.php index 0a3aa94..e334135 100644 --- a/core/modules/field/src/Tests/FieldStorageCrudTest.php +++ b/core/modules/field/src/Tests/FieldStorageCrudTest.php @@ -363,11 +363,7 @@ function testUpdateFieldType() { $field_storage->save(); try { - // Set the field storage type to 'integer.' Since $type is protected, - // we have to use reflection. - $ref_field_storage_type = new \ReflectionProperty($field_storage, 'type'); - $ref_field_storage_type->setAccessible(TRUE); - $ref_field_storage_type->setValue($field_storage, 'integer'); + $field_storage->set('type', 'integer'); $field_storage->save(); $this->fail(t('Cannot update a field to a different type.')); } diff --git a/core/modules/field/src/Tests/reEnableModuleFieldTest.php b/core/modules/field/src/Tests/reEnableModuleFieldTest.php index 2139f6e..52ce2a3 100644 --- a/core/modules/field/src/Tests/reEnableModuleFieldTest.php +++ b/core/modules/field/src/Tests/reEnableModuleFieldTest.php @@ -40,7 +40,7 @@ protected function setUp() { /** * Test the behavior of a field module after being disabled and re-enabled. * - * @see \field_system_info_alter() + * @see field_system_info_alter() */ function testReEnabledField() { diff --git a/core/modules/field_ui/src/Form/FieldStorageEditForm.php b/core/modules/field_ui/src/Form/FieldStorageEditForm.php index dbe5a1f..9c1df19 100644 --- a/core/modules/field_ui/src/Form/FieldStorageEditForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageEditForm.php @@ -194,7 +194,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // Merge incoming form values into the existing field. $field_storage = $this->field->getFieldStorageDefinition(); foreach ($field_values as $key => $value) { - $field_storage->set($key,$value); + $field_storage->set($key, $value); } // Update the field. diff --git a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php index 417d7e0..688daf2 100644 --- a/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php +++ b/core/modules/system/src/Tests/Entity/FieldSqlStorageTest.php @@ -411,23 +411,15 @@ function testFieldUpdateIndexesWithData() { $entity->enforceIsNew(); $entity->save(); - // Add an index. Since $indexes is protected, we have to use reflection. - $ref_field_storage_indexes = new \ReflectionProperty($field_storage, 'indexes'); - $ref_field_storage_indexes->setAccessible(TRUE); - $ref_field_storage_indexes->setValue( - $field_storage, - array('value' => array(array('value', 255))) - ); + // Add an index. + $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. - $ref_field_storage_indexes->setValue( - $field_storage, - 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)));