diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php index 0a045f2..a10b2d1 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php @@ -241,7 +241,6 @@ public function load($id) { */ protected function mapFromStorageRecords(array $records) { $entities = array(); - $field_definitions = $this->entityManager->getBaseFieldDefinitions($this->entityTypeId); foreach ($records as $id => $record) { $entities[$id] = array(); // Skip the item delta and item value levels (if possible) but let the @@ -252,28 +251,12 @@ protected function mapFromStorageRecords(array $records) { // that store several properties). if ($field_name = strstr($name, '__', TRUE)) { $property_name = substr($name, strpos($name, '__') + 2); - - $field_definition = $field_definitions[$field_name]; - $serialize = !empty($field_definition->getColumns()[$property_name]['serialize']); - $entities[$id][$field_name][Language::LANGCODE_DEFAULT][$property_name] = $serialize ? unserialize($value) : $value; + $entities[$id][$field_name][Language::LANGCODE_DEFAULT][$property_name] = $value; } else { // Handle columns named directly after the field (e.g if the field - // type only stores one property). We allow for storage controllers to - // have schema fields which are not entity fields, which can be useful - // for normalization purposes. The 'default_langcode' field, for - // example, is simply a denormalization of checking the language code - // in the data table against the language code in the base table and - // similarly the 'isDefaultRevision' field (which we add as a query - // expression in FieldableDatabaseStorageController::buildQuery()) is - // a denormalization of checking the revision ID in the revision table - // against the revision ID in the base table. - $serialize = FALSE; - if (isset($field_definitions[$name])) { - $field_definition = $field_definitions[$name]; - $serialize = !empty($field_definition->getColumns()[$field_definition->getMainPropertyName()]['serialize']); - } - $entities[$id][$name][Language::LANGCODE_DEFAULT] = $serialize ? unserialize($value) : $value; + // type only stores one property). + $entities[$id][$name][Language::LANGCODE_DEFAULT] = $value; } } // If we have no multilingual values we can instantiate entity objecs diff --git a/core/modules/entity/entity.module b/core/modules/entity/entity.module index fefc526..ea8776c 100644 --- a/core/modules/entity/entity.module +++ b/core/modules/entity/entity.module @@ -130,26 +130,28 @@ function entity_entity_bundle_delete($entity_type_id, $bundle) { } /** - * Implements hook_module_preinstall(). + * Implements hook_modules_installed(). */ -function entity_module_preinstall($module) { +function entity_modules_installed($modules) { // Install entity type tables. $entity_manager = \Drupal::entityManager(); - $entity_manager->clearCachedDefinitions(); $schema = \Drupal::database()->schema(); - - foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->getProvider() == $module) { - $storage = $entity_manager->getStorage($entity_type_id); - if ($storage instanceof SqlStorageInterface) { - foreach ($storage->getSchema() as $table_name => $table_schema) { - // Some test entity types share the same schema so we need a check to - // avoid attempting to create the schema more than once, which would - // result in an error. - // @todo Remove the drupal_get_schema() call once all entity types - // have been converted to an automatic schema. - if (!drupal_get_schema($table_name) && !$schema->tableExists($table_name)) { - $schema->createTable($table_name, $table_schema); + $definitions = $entity_manager->getDefinitions(); + + foreach ($modules as $module) { + foreach ($definitions as $entity_type_id => $entity_type) { + if ($entity_type->getProvider() == $module) { + $storage = $entity_manager->getStorage($entity_type_id); + if ($storage instanceof SqlStorageInterface) { + foreach ($storage->getSchema() as $table_name => $table_schema) { + // Some test entity types share the same schema so we need a check to + // avoid attempting to create the schema more than once, which would + // result in an error. + // @todo Remove the drupal_get_schema() call once all entity types + // have been converted to an automatic schema. + if (!drupal_get_schema($table_name) && !$schema->tableExists($table_name)) { + $schema->createTable($table_name, $table_schema); + } } } } @@ -158,28 +160,31 @@ function entity_module_preinstall($module) { } /** - * Implements hook_module_preuninstall(). + * Implements hook_modules_uninstalled(). */ -function entity_module_preuninstall($module) { +function entity_modules_uninstalled($modules) { $entity_manager = \Drupal::entityManager(); $schema = \Drupal::database()->schema(); + $definition = $entity_manager->getDefinitions(); + + foreach ($modules as $module) { + foreach ($definition as $entity_type_id => $entity_type) { + if ($entity_type->getProvider() == $module) { + // Clean up all entity bundles (including field instances) of every entity + // type provided by the module that is being uninstalled. + foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) { + entity_invoke_bundle_hook('delete', $entity_type_id, $bundle); + } - foreach ($entity_manager->getDefinitions() as $entity_type_id => $entity_type) { - if ($entity_type->getProvider() == $module) { - // Clean up all entity bundles (including field instances) of every entity - // type provided by the module that is being uninstalled. - foreach (array_keys($entity_manager->getBundleInfo($entity_type_id)) as $bundle) { - entity_invoke_bundle_hook('delete', $entity_type_id, $bundle); - } - - // Remove entity tables. - $storage = $entity_manager->getStorage($entity_type->id()); - if ($storage instanceof SqlStorageInterface) { - foreach ($storage->getSchema() as $table_name => $table_schema) { - // @todo Remove the drupal_get_schema() call once all entity types - // have been converted to an automatic schema. - if (!drupal_get_schema($table_name) && $schema->tableExists($table_name)) { - $schema->dropTable($table_name, $table_schema); + // Remove entity tables. + $storage = $entity_manager->getStorage($entity_type->id()); + if ($storage instanceof SqlStorageInterface) { + foreach ($storage->getSchema() as $table_name => $table_schema) { + // @todo Remove the drupal_get_schema() call once all entity types + // have been converted to an automatic schema. + if (!drupal_get_schema($table_name) && $schema->tableExists($table_name)) { + $schema->dropTable($table_name, $table_schema); + } } } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php index a516ba4..f032080 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php @@ -75,7 +75,7 @@ public static function getInfo() { public function setUp() { parent::setUp(); - $this->installEntitySchema('entity_test'); + $this->installEntitySchema('entity_test_rev'); // Setup a field and instance. entity_reference_create_instance( diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index 28f0567..eed2791 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -36,7 +36,7 @@ public static function getInfo() { public function setUp() { parent::setUp(); - $this->installEntitySchema('entity_test'); + $this->installEntitySchema('entity_test_rev'); } /** diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index d8d9f9c..85ea0dc 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -33,7 +33,7 @@ class TranslationWebTest extends FieldTestBase { * * @var string */ - protected $entity_type = 'entity_test_rev'; + protected $entity_type = 'entity_test_mulrev'; /** * The field to use in this test. @@ -78,7 +78,7 @@ function setUp() { 'bundle' => $this->entity_type, ); entity_create('field_instance_config', $instance)->save(); - $this->instance = entity_load('field_instance_config', 'entity_test.' . $instance['bundle'] . '.' . $this->field_name); + $this->instance = entity_load('field_instance_config', $this->entity_type . '.' . $instance['bundle'] . '.' . $this->field_name); entity_get_form_display($this->entity_type, $this->entity_type, 'default') ->setComponent($this->field_name) diff --git a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php index adff21d..78a8629 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/UpdateTest.php @@ -58,7 +58,6 @@ public function testPatchUpdate() { $patch_entity = entity_create($entity_type, $patch_values); // We don't want to overwrite the UUID. unset($patch_entity->uuid); - $patch_entity->save(); $serialized = $serializer->serialize($patch_entity, $this->defaultFormat); // Update the entity over the REST API. diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php index a1001a4..255200a 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Entity/Shortcut.php @@ -95,7 +95,8 @@ public function setRouteName($route_name) { * {@inheritdoc} */ public function getRouteParams() { - return $this->get('route_parameters')->getValue(); + $value = $this->get('route_parameters')->getValue(); + return reset($value); } /** diff --git a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php index 88f49d3..6cd8d39 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/Tests/DrupalUnitTestBaseTest.php @@ -19,7 +19,7 @@ class DrupalUnitTestBaseTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('entity', 'entity_test', 'entity_install_schema_test'); + public static $modules = array('entity', 'entity_test', 'field', 'simpletest_test'); public static function getInfo() { return array( @@ -33,14 +33,13 @@ public static function getInfo() { * Tests expected behavior of setUp(). */ function testSetUp() { - $modules = array('entity', 'entity_test', 'entity_install_schema_test'); - $tables = array('entity_test', 'entity_install_schema_test'); + $tables = array('entity_test', 'simpletest_test'); // Verify that specified $modules have been loaded. $this->assertTrue(function_exists('entity_test_permission'), 'entity_test.module was loaded.'); // Verify that there is a fixed module list. - $this->assertIdentical(array_keys(\Drupal::moduleHandler()->getModuleList()), $modules); - $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('permission'), $modules); + $this->assertIdentical(array_keys(\Drupal::moduleHandler()->getModuleList()), static::$modules); + $this->assertIdentical(\Drupal::moduleHandler()->getImplementations('permission'), array('entity', 'entity_test')); // Verify that no modules have been installed. foreach($tables as $table){ @@ -126,8 +125,8 @@ function testEnableModulesInstallContainer() { * Tests expected behavior of installSchema(). */ function testInstallSchema() { - $module = 'entity_install_schema_test'; - $table = 'entity_install_schema_test'; + $module = 'simpletest_test'; + $table = 'simpletest_test'; // Verify that we can install a table from the module schema. $this->installSchema($module, $table); $this->assertTrue(db_table_exists($table), "'$table' database table found."); diff --git a/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.info.yml b/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.info.yml deleted file mode 100644 index 7ff72d1..0000000 --- a/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.info.yml +++ /dev/null @@ -1,7 +0,0 @@ -name: Schema Test -type: module -description: 'Provides dummy schema for use by SimpleTest tests.' -package: Testing -version: VERSION -core: 8.x -hidden: TRUE diff --git a/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.module b/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.module deleted file mode 100644 index d67c4bf..0000000 --- a/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.module +++ /dev/null @@ -1,25 +0,0 @@ - array( - 'title' => t('Administer entity_install_schema_test content'), - 'description' => t('Manage entity_install_schema_test content'), - ), - 'view install schema test entity' => array( - 'title' => t('View install schema test entities'), - ), - 'view install schema test entity translations' => array( - 'title' => t('View translations of install schema test entities'), - ), - ); - return $permissions; -} diff --git a/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.info.yml b/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.info.yml new file mode 100644 index 0000000..6c98069 --- /dev/null +++ b/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.info.yml @@ -0,0 +1,7 @@ +name: Simpletest Test +type: module +description: 'Provides dummy hook implementations for use by SimpleTest tests.' +package: Testing +version: VERSION +core: 8.x +hidden: TRUE diff --git a/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.install b/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.install similarity index 81% rename from core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.install rename to core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.install index 3bbe45a..f9b16a0 100644 --- a/core/modules/simpletest/tests/modules/entity_install_schema_test/entity_install_schema_test.install +++ b/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.install @@ -8,9 +8,9 @@ /** * Implements hook_schema(). */ -function entity_install_schema_test_schema(){ - $schema['entity_install_schema_test'] = array( - 'description' => 'Stores entity_install_schema_test data.', +function simpletest_test_schema(){ + $schema['simpletest_test'] = array( + 'description' => 'Stores simpltest_test data.', 'fields' => array( 'sid' => array( 'type' => 'serial', @@ -38,7 +38,7 @@ function entity_install_schema_test_schema(){ ), ), 'indexes' => array( - 'entity_install_schema_test_index' => array('sid', 'dummy_integer'), + 'simpltest_test_index' => array('sid', 'dummy_integer'), ), 'primary key' => array('sid'), 'unique keys' => array( diff --git a/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.module b/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.module new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/core/modules/simpletest/tests/modules/simpletest_test/simpletest_test.module @@ -0,0 +1 @@ +createTestEntity($entity_type); + protected function assertDataStructureInterfaces($entity_type_id) { + $entity = $this->createTestEntity($entity_type_id); // Test using the whole tree of typed data by navigating through the tree of // contained properties and getting all contained strings, limited by a @@ -505,7 +505,12 @@ protected function assertDataStructureInterfaces($entity_type) { // Field format. NULL, ); - $this->assertEqual($strings, $target_strings, format_string('%entity_type: All contained strings found.', array('%entity_type' => $entity_type))); + // Add the "log" NULL value for revisionable entity types. + $entity_type = $this->entityManager->getDefinition($entity_type_id); + if ($entity_type->hasKey('revision')) { + array_splice($target_strings, 4, 0, array(NULL)); + } + $this->assertEqual($strings, $target_strings, format_string('%entity_type: All contained strings found.', array('%entity_type' => $entity_type_id))); } /** diff --git a/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php index cacbf5e..30af0bf 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php @@ -50,7 +50,7 @@ public static function getInfo() { public function setUp() { parent::setUp(); - $this->installEntitySchema('entity_test'); + $this->installEntitySchema('entity_test_rev'); // Create the necessary formats. $this->installConfig(array('filter'));