Commit ad76a96a authored by catch's avatar catch

Issue #2723607 by valthebald, deepakaryan1988: Remove entity_load* usage for dynamic entity types

parent 03f46efe
......@@ -67,7 +67,9 @@ public function isTargetNew() {
public function getTarget() {
if (!isset($this->target) && isset($this->id)) {
// If we have a valid reference, return the entity's TypedData adapter.
$entity = entity_load($this->getTargetDefinition()->getEntityTypeId(), $this->id);
$entity = \Drupal::entityTypeManager()
->getStorage($this->getTargetDefinition()->getEntityTypeId())
->load($this->id);
$this->target = isset($entity) ? $entity->getTypedData() : NULL;
}
return $this->target;
......
......@@ -179,7 +179,10 @@ public function testDisabledBundle() {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
......
......@@ -146,7 +146,10 @@ protected function doTestPublishedStatus() {
* {@inheritdoc}
*/
protected function doTestAuthoringInfo() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
$values = array();
......@@ -166,7 +169,8 @@ protected function doTestAuthoringInfo() {
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
$metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
$this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
......@@ -195,7 +199,10 @@ function testTranslateLinkCommentAdminPage() {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
......
......@@ -412,7 +412,8 @@ function content_translation_entity_presave(EntityInterface $entity) {
// as original language, since source values are the only ones available to
// compare against.
if (!isset($entity->original)) {
$entity->original = entity_load_unchanged($entity->entityType(), $entity->id());
$entity->original = \Drupal::entityTypeManager()
->getStorage($entity->entityType())->loadUnchanged($entity->id());
}
$langcode = $entity->language()->getId();
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
......
......@@ -64,7 +64,10 @@ protected function setupEntity() {
$this->fieldName => array(array('value' => $this->randomMachineName(16))),
);
$id = $this->createEntity($values, $default_langcode);
$this->entity = entity_load($this->entityTypeId, $id, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$id]);
$this->entity = $storage->load($id);
// Create a translation.
$this->drupalLogin($this->translator);
......
......@@ -82,7 +82,9 @@ public function testSupportedEntityTypesAndWidgets() {
// Try to post the form again with no modification and check if the field
// values remain the same.
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container->get('entity_type.manager')->getStorage($this->entityType);
$entity = current($storage->loadByProperties(['name' => $entity_name]));
$this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
$this->assertFieldByName($this->fieldName . '[0][target_id]', $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')');
$this->assertFieldByName($this->fieldName . '[1][target_id]', $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')');
......@@ -108,7 +110,7 @@ public function testSupportedEntityTypesAndWidgets() {
// Try to post the form again with no modification and check if the field
// values remain the same.
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
$entity = current($storage->loadByProperties(['name' => $entity_name]));
$this->drupalGet($this->entityType . '/manage/' . $entity->id() . '/edit');
$this->assertFieldByName($this->fieldName . '[target_id]', $target_id . ' (' . $referenced_entities[1]->id() . ')');
......@@ -119,7 +121,7 @@ public function testSupportedEntityTypesAndWidgets() {
// Since we don't know the form structure for these widgets, just test
// that editing and saving an already created entity works.
$exclude = array('entity_reference_autocomplete', 'entity_reference_autocomplete_tags');
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
$entity = current($storage->loadByProperties(['name' => $entity_name]));
$supported_widgets = \Drupal::service('plugin.manager.field.widget')->getOptions('entity_reference');
$supported_widget_types = array_diff(array_keys($supported_widgets), $exclude);
......@@ -173,7 +175,8 @@ public function testSupportedEntityTypesAndWidgets() {
* An array of referenced entities.
*/
protected function assertFieldValues($entity_name, $referenced_entities) {
$entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
$entity = current($this->container->get('entity_type.manager')->getStorage(
$this->entityType)->loadByProperties(['name' => $entity_name]));
$this->assertTrue($entity, format_string('%entity_type: Entity found in the database.', array('%entity_type' => $this->entityType)));
......
......@@ -47,8 +47,11 @@ function _generateTestFieldValues($cardinality) {
*/
function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_DEFAULT, $column = 'value') {
// Re-load the entity to make sure we have the latest changes.
\Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
$e = entity_load($entity->getEntityTypeId(), $entity->id());
$storage = $this->container->get('entity_type.manager')
->getStorage($entity->getEntityTypeId());
$storage->resetCache([$entity->id()]);
$e = $storage->load($entity->id());
$field = $values = $e->getTranslation($langcode)->$field_name;
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyItems();
......
......@@ -555,7 +555,9 @@ function testFieldFormAccess() {
$id = $match[1];
// Check that the default value was saved.
$entity = entity_load($entity_type, $id);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity = $storage->load($id);
$this->assertEqual($entity->$field_name_no_access->value, 99, 'Default value was saved for the field with no edit access.');
$this->assertEqual($entity->$field_name->value, 1, 'Entered value vas saved for the field with edit access.');
......@@ -567,8 +569,8 @@ function testFieldFormAccess() {
$this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save'));
// Check that the new revision has the expected values.
$this->container->get('entity.manager')->getStorage($entity_type)->resetCache(array($id));
$entity = entity_load($entity_type, $id);
$storage->resetCache([$id]);
$entity = $storage->load($id);
$this->assertEqual($entity->$field_name_no_access->value, 99, 'New revision has the expected value for the field with no edit access.');
$this->assertEqual($entity->$field_name->value, 2, 'New revision has the expected value for the field with edit access.');
......@@ -606,7 +608,10 @@ function testHiddenField() {
preg_match('|' . $entity_type . '/manage/(\d+)|', $this->url, $match);
$id = $match[1];
$this->assertText(t('entity_test_rev @id has been created.', array('@id' => $id)), 'Entity was created');
$entity = entity_load($entity_type, $id);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity = $storage->load($id);
$this->assertEqual($entity->{$field_name}->value, 99, 'Default value was saved');
// Update the field to remove the default value, and switch to the default
......@@ -628,8 +633,8 @@ function testHiddenField() {
$edit = array("{$field_name}[0][value]" => $value);
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('entity_test_rev @id has been updated.', array('@id' => $id)), 'Entity was updated');
\Drupal::entityManager()->getStorage($entity_type)->resetCache(array($id));
$entity = entity_load($entity_type, $id);
$storage->resetCache([$id]);
$entity = $storage->load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'Field value was updated');
// Set the field back to hidden.
......@@ -642,8 +647,8 @@ function testHiddenField() {
$this->drupalPostForm($entity_type . '/manage/' . $id . '/edit', $edit, t('Save'));
// Check that the expected value has been carried over to the new revision.
\Drupal::entityManager()->getStorage($entity_type)->resetCache(array($id));
$entity = entity_load($entity_type, $id);
$storage->resetCache(array($id));
$entity = $storage->load($id);
$this->assertEqual($entity->{$field_name}->value, $value, 'New revision has the expected value for the field with the Hidden widget');
}
......
......@@ -71,17 +71,16 @@ function testNestedFieldForm() {
// Create two entities.
$entity_type = 'entity_test';
$entity_1 = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 1));
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity_1 = $storage->create(['id' => 1]);
$entity_1->enforceIsNew();
$entity_1->field_single->value = 0;
$entity_1->field_unlimited->value = 1;
$entity_1->save();
$entity_2 = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => 2));
$entity_2 = $storage->create(array('id' => 2));
$entity_2->enforceIsNew();
$entity_2->field_single->value = 10;
$entity_2->field_unlimited->value = 11;
......@@ -104,8 +103,8 @@ function testNestedFieldForm() {
'entity_2[field_unlimited][1][value]' => 13,
);
$this->drupalPostForm(NULL, $edit, t('Save'));
$entity_1 = entity_load($entity_type, 1);
$entity_2 = entity_load($entity_type, 2);
$entity_1 = $storage->load(1);
$entity_2 = $storage->load(2);
$this->assertFieldValues($entity_1, 'field_single', array(1));
$this->assertFieldValues($entity_1, 'field_unlimited', array(2, 3));
$this->assertFieldValues($entity_2, 'field_single', array(11));
......
......@@ -137,7 +137,8 @@ protected function setUp() {
$entity->save();
}
}
$this->entities = entity_load_multiple($this->entityTypeId);
$this->entities = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId)->loadMultiple();
foreach ($this->entities as $entity) {
// This test relies on the entities having stale field definitions
// so that the deleted field can be accessed on them. Access the field
......
......@@ -186,8 +186,11 @@ protected function _generateTestFieldValues($cardinality) {
*/
protected function assertFieldValues(EntityInterface $entity, $field_name, $expected_values, $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED, $column = 'value') {
// Re-load the entity to make sure we have the latest changes.
\Drupal::entityManager()->getStorage($entity->getEntityTypeId())->resetCache(array($entity->id()));
$e = entity_load($entity->getEntityTypeId(), $entity->id());
$storage = $this->container->get('entity_type.manager')
->getStorage($entity->getEntityTypeId());
$storage->resetCache([$entity->id()]);
$e = $storage->load($this->entityId);
$field = $values = $e->getTranslation($langcode)->$field_name;
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyItems();
......
......@@ -1482,7 +1482,8 @@ function file_get_file_references(FileInterface $file, FieldDefinitionInterface
$usage_list = \Drupal::service('file.usage')->listUsage($file);
$file_usage_list = isset($usage_list['file']) ? $usage_list['file'] : array();
foreach ($file_usage_list as $entity_type_id => $entity_ids) {
$entities = entity_load_multiple($entity_type_id, array_keys($entity_ids));
$entities = \Drupal::entityTypeManager()
->getStorage($entity_type_id)->loadMultiple(array_keys($entity_ids));
foreach ($entities as $entity) {
$bundle = $entity->bundle();
// We need to find file fields for this entity type and bundle.
......
......@@ -98,7 +98,10 @@ function testTranslationLinkTheme() {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
......
......@@ -83,7 +83,10 @@ public function testPublishedStatusNoFields() {
$default_langcode = $this->langcodes[0];
$values[$default_langcode] = array('title' => array(array('value' => $this->randomMachineName())));
$entity_id = $this->createEntity($values[$default_langcode], $default_langcode);
$entity = entity_load($this->entityTypeId, $entity_id, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
// Add a content translation.
$langcode = 'fr';
......@@ -98,7 +101,8 @@ public function testPublishedStatusNoFields() {
], array('language' => $language));
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), t('Save and unpublish (this translation)'));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$translation = $entity->getTranslation($langcode);
// Make sure we unpublished the node correctly.
$this->assertFalse($this->manager->getTranslationMetadata($translation)->isPublished(), 'The translation has been correctly unpublished.');
......@@ -148,7 +152,10 @@ protected function getFormSubmitAction(EntityInterface $entity, $langcode) {
* {@inheritdoc}
*/
protected function doTestPublishedStatus() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
$actions = array(
......@@ -164,7 +171,8 @@ protected function doTestPublishedStatus() {
$url = $entity->urlInfo('edit-form', $options);
$this->drupalPostForm($url, array(), $action . $this->getFormSubmitSuffix($entity, $langcode), $options);
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
// The node is created as unpublished thus we switch to the published
// status first.
......@@ -179,7 +187,10 @@ protected function doTestPublishedStatus() {
* {@inheritdoc}
*/
protected function doTestAuthoringInfo() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
$values = array();
......@@ -204,7 +215,8 @@ protected function doTestAuthoringInfo() {
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode), $options);
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
$translation = $entity->getTranslation($langcode);
$metadata = $this->manager->getTranslationMetadata($translation);
......@@ -424,7 +436,10 @@ protected function doUninstallTest() {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
$type_name = node_get_type_label($entity);
......
......@@ -87,7 +87,10 @@ public function testCookieAuth() {
$this->curlExec($curl_options);
$this->assertResponse(403);
// Ensure that the entity was not created.
$this->assertFalse(entity_load_multiple($this->testEntityType, NULL, TRUE), 'No entity has been created in the database.');
$storage = $this->container->get('entity_type.manager')
->getStorage($this->testEntityType);
$storage->resetCache();
$this->assertFalse($storage->loadMultiple(), 'No entity has been created in the database.');
// Create an entity with the CSRF token.
$token = $this->drupalGet('rest/session/token');
......
......@@ -44,7 +44,10 @@ public function testDelete() {
$response = $this->httpRequest($entity->urlInfo(), 'DELETE');
// Clear the static cache with entity_load(), otherwise we won't see the
// update.
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertFalse($entity, $entity_type . ' entity is not in the DB anymore.');
$this->assertResponse('204', 'HTTP response code is correct.');
$this->assertEqual($response, '', 'Response body is empty.');
......@@ -61,7 +64,9 @@ public function testDelete() {
$entity->save();
$this->httpRequest($entity->urlInfo(), 'DELETE');
$this->assertResponse(403);
$this->assertNotIdentical(FALSE, entity_load($entity_type, $entity->id(), TRUE), 'The ' . $entity_type . ' entity is still in the database.');
$storage->resetCache([$entity->id()]);
$this->assertNotIdentical(FALSE, $storage->load($entity->id()),
'The ' . $entity_type . ' entity is still in the database.');
}
// Try to delete a resource which is not REST API enabled.
$this->enableService(FALSE);
......
......@@ -446,7 +446,8 @@ protected function entityPermissions($entity_type_id, $operation) {
protected function loadEntityFromLocationHeader($location_url) {
$url_parts = explode('/', $location_url);
$id = end($url_parts);
return entity_load($this->testEntityType, $id);
return $this->container->get('entity_type.manager')
->getStorage($this->testEntityType)->load($id);
}
/**
......
......@@ -90,7 +90,10 @@ public function testPatchUpdate() {
$this->assertEqual($request, $response);
// Re-load updated entity from the database.
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertEqual($entity->field_test_text->value, $patch_entity->field_test_text->value, 'Field was successfully updated.');
// Make sure that the field does not get deleted if it is not present in the
......@@ -101,7 +104,8 @@ public function testPatchUpdate() {
$this->httpRequest($entity->urlInfo(), 'PATCH', $serialized, $this->defaultMimeType);
$this->assertResponse(200);
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertNotNull($entity->field_test_text->value . 'Test field has not been deleted.');
// Try to empty a field.
......@@ -113,7 +117,8 @@ public function testPatchUpdate() {
$this->assertResponse(200);
// Re-load updated entity from the database.
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id(), TRUE);
$this->assertNull($entity->field_test_text->value, 'Test field has been cleared.');
// Enable access protection for the text field.
......@@ -127,7 +132,8 @@ public function testPatchUpdate() {
$this->assertResponse(403);
// Re-load the entity from the database.
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertEqual($entity->field_test_text->value, 'no edit access value', 'Text field was not deleted.');
// Try to update an access protected field.
......@@ -138,7 +144,8 @@ public function testPatchUpdate() {
$this->assertResponse(403);
// Re-load the entity from the database.
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertEqual($entity->field_test_text->value, 'no edit access value', 'Text field was not updated.');
// Try to update the field with a text format this user has no access to.
......@@ -154,7 +161,8 @@ public function testPatchUpdate() {
$this->assertResponse(422);
// Re-load the entity from the database.
$entity = entity_load($entity_type, $entity->id(), TRUE);
$storage->resetCache([$entity->id()]);
$entity = $storage->load($entity->id());
$this->assertEqual($entity->field_test_text->format, 'plain_text', 'Text format was not updated.');
// Restore the valid test value.
......@@ -168,7 +176,8 @@ public function testPatchUpdate() {
// Try to update a non-existing entity with ID 9999.
$this->httpRequest($entity_type . '/9999', 'PATCH', $serialized, $this->defaultMimeType);
$this->assertResponse(404);
$loaded_entity = entity_load($entity_type, 9999, TRUE);
$storage->resetCache([9999]);
$loaded_entity = $storage->load(9999);
$this->assertFalse($loaded_entity, 'Entity 9999 was not created.');
// Try to send invalid data to trigger the entity validation constraints.
......
......@@ -65,7 +65,10 @@ protected function getNewEntityValues($langcode) {
protected function doTestBasicTranslation() {
parent::doTestBasicTranslation();
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
if ($entity->hasTranslation($langcode)) {
$language = new Language(array('id' => $langcode));
......@@ -84,7 +87,10 @@ protected function doTestBasicTranslation() {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
......@@ -107,7 +113,10 @@ protected function doTestTranslationEdit() {
* Tests the basic translation workflow.
*/
protected function doTestTranslationChanged() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertFalse(
$entity instanceof EntityChangedInterface,
......
......@@ -515,7 +515,9 @@ public function testReferencedEntity() {
// cache miss for both the referencing entity, and the listing of
// referencing entities, but not for any other routes.
$this->pass("Test modification of referenced entity's bundle entity.", 'Debug');
$bundle_entity = entity_load($bundle_entity_type_id, $this->entity->bundle());
$bundle_entity = $this->container->get('entity_type.manager')
->getStorage($bundle_entity_type_id)
->load($this->entity->bundle());
$bundle_entity->save();
$this->verifyPageCache($referencing_entity_url, 'MISS');
$this->verifyPageCache($listing_url, 'MISS');
......
......@@ -83,7 +83,8 @@ protected function runRevisionsTests($entity_type) {
$legacy_name = $entity->name->value;
$legacy_text = $entity->field_test_text->value;
$entity = entity_load($entity_type, $entity->id->value);
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)->load($entity->id->value);
$entity->setNewRevision(TRUE);
$names[] = $entity->name->value = $this->randomMachineName(32);
$texts[] = $entity->field_test_text->value = $this->randomMachineName(32);
......@@ -112,7 +113,9 @@ protected function runRevisionsTests($entity_type) {
}
// Confirm the correct revision text appears in the edit form.
$entity = entity_load($entity_type, $entity->id->value);
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->load($entity->id->value);
$this->drupalGet($entity_type . '/manage/' . $entity->id->value . '/edit');
$this->assertFieldById('edit-name-0-value', $entity->name->value, format_string('%entity_type: Name matches in UI.', array('%entity_type' => $entity_type)));
$this->assertFieldById('edit-field-test-text-0-value', $entity->field_test_text->value, format_string('%entity_type: Text matches in UI.', array('%entity_type' => $entity_type)));
......
......@@ -80,7 +80,9 @@ public function testEntityUri() {
// Verify that after modifying the corresponding bundle entity, there is a
// cache miss.
$this->pass("Test modification of entity's bundle entity.", 'Debug');
$bundle_entity = entity_load($bundle_entity_type_id, $this->entity->bundle());
$bundle_entity = $this->container->get('entity_type.manager')
->getStorage($bundle_entity_type_id)
->load($this->entity->bundle());
$bundle_entity->save();
$this->verifyPageCache($entity_url, 'MISS');
......
......@@ -139,7 +139,10 @@ function testTranslateLinkVocabularyAdminPage() {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
......
......@@ -59,16 +59,16 @@ public function testCrudAndUpdate() {
$this->createField($entity_type);
// Create an entity with a summary and no text format.
$entity = $this->container->get('entity_type.manager')
->getStorage($entity_type)
->create();
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entity = $storage->create();
$entity->summary_field->value = $value = $this->randomMachineName();
$entity->summary_field->summary = $summary = $this->randomMachineName();
$entity->summary_field->format = NULL;
$entity->name->value = $this->randomMachineName();
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$entity = $storage->load($entity->id());
$this->assertTrue($entity->summary_field instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->summary_field[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->summary_field->value, $value);
......
......@@ -53,7 +53,10 @@ protected function getNewEntityValues($langcode) {
* {@inheritdoc}
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
......
......@@ -50,8 +50,10 @@ protected function setUp() {
* Tests that the static cache is working.
*/
public function testCacheHit() {
$entity_1 = entity_load($this->entityTypeId, $this->entityId);
$entity_2 = entity_load($this->entityTypeId, $this->entityId);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$entity_1 = $storage->load($this->entityId);
$entity_2 = $storage->load($this->entityId);
// config_entity_static_cache_test_config_test_load() sets _loadStamp to a
// random string. If they match, it means $entity_2 was retrieved from the
// static cache rather than going through a separate load sequence.
......@@ -62,19 +64,21 @@ public function testCacheHit() {
* Tests that the static cache is reset on entity save and delete.
*/
public function testReset() {
$entity = entity_load($this->entityTypeId, $this->entityId);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$entity = $storage->load($this->entityId);
// Ensure loading after a save retrieves the updated entity rather than an
// obsolete cached one.
$entity->label = 'New label';
$entity->save();
$entity = entity_load($this->entityTypeId, $this->entityId);
$entity = $storage->load($this->entityId);
$this->assertIdentical($entity->label, 'New label');
// Ensure loading after a delete retrieves NULL rather than an obsolete
// cached one.
$entity->delete();
$this->assertNull(entity_load($this->entityTypeId, $this->entityId));
$this->assertNull($storage->load($this->entityId));
}
/**
......
......@@ -27,11 +27,10 @@ public function testUUIDConflict() {
$entity_type = 'config_test';
$id = 'test_1';
// Load the original configuration entity.
$this->container->get('entity_type.manager')
->getStorage($entity_type)
->create(array('id' => $id))
->save();
$entity = entity_load($entity_type, $id);
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$storage->create(['id' => $id])->save();
$entity = $storage->load($id);
$original_properties = $entity->toArray();
......
......@@ -60,32 +60,36 @@ protected function assertCRUD($entity_type, UserInterface $user1) {
->create(array('name' => 'test', 'user_id' => NULL));
$entity->save();
$entities = array_values(entity_load_multiple_by_properties($entity_type, array('name' => 'test')));
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
$storage = $this->container->get('entity_type.manager')
->getStorage($entity_type);
$entities = array_values($storage->loadByProperties(['name' => 'test']));
$this->assertEqual($entities[0]->name->value, 'test', format_string('%entity_type: Created and loaded entity', array('%entity_type' => $entity_type)));