Commit bfe4794d authored by alexpott's avatar alexpott

Issue #3027178 by Berdir, alexpott, miroslav-lee, andypost, larowlan,...

Issue #3027178 by Berdir, alexpott, miroslav-lee, andypost, larowlan, mikelutz, JeroenT: Properly deprecate entity_load_multiple_by_properties()
parent fb532b06
...@@ -184,19 +184,13 @@ function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) { ...@@ -184,19 +184,13 @@ function entity_load_multiple($entity_type, array $ids = NULL, $reset = FALSE) {
* An array of entity objects indexed by their IDs. Returns an empty array if * An array of entity objects indexed by their IDs. Returns an empty array if
* no matching entities are found. * no matching entities are found.
* *
* @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use * @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
* the entity storage's loadByProperties() method to load an entity by their * entity type storage's loadByProperties() method.
* property values:
* @code
* \Drupal::entityTypeManager()
* ->getStorage($entity_type)
* ->loadByProperties($values);
* @endcode
* *
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage() * @see https://www.drupal.org/node/3050910
* @see \Drupal\Core\Entity\EntityStorageInterface::loadByProperties()
*/ */
function entity_load_multiple_by_properties($entity_type, array $values) { function entity_load_multiple_by_properties($entity_type, array $values) {
@trigger_error('entity_load_multiple_by_properties() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the entity type storage\'s loadByProperties() method. See https://www.drupal.org/node/3050910', E_USER_DEPRECATED);
return \Drupal::entityManager() return \Drupal::entityManager()
->getStorage($entity_type) ->getStorage($entity_type)
->loadByProperties($values); ->loadByProperties($values);
......
...@@ -208,7 +208,7 @@ public function process(FeedInterface $feed) { ...@@ -208,7 +208,7 @@ public function process(FeedInterface $feed) {
} }
// Try to load an existing entry. // Try to load an existing entry.
if ($entry = entity_load_multiple_by_properties('aggregator_item', $values)) { if ($entry = $this->itemStorage->loadByProperties($values)) {
$entry = reset($entry); $entry = reset($entry);
} }
else { else {
......
...@@ -77,7 +77,7 @@ public function testFeedLanguage() { ...@@ -77,7 +77,7 @@ public function testFeedLanguage() {
// the one from the feed. // the one from the feed.
foreach ($feeds as $feed) { foreach ($feeds as $feed) {
/** @var \Drupal\aggregator\ItemInterface[] $items */ /** @var \Drupal\aggregator\ItemInterface[] $items */
$items = entity_load_multiple_by_properties('aggregator_item', ['fid' => $feed->id()]); $items = \Drupal::entityTypeManager()->getStorage('aggregator_item')->loadByProperties(['fid' => $feed->id()]);
$this->assertTrue(count($items) > 0, 'Feed items were created.'); $this->assertTrue(count($items) > 0, 'Feed items were created.');
foreach ($items as $item) { foreach ($items as $item) {
$this->assertEqual($item->language()->getId(), $feed->language()->getId()); $this->assertEqual($item->language()->getId(), $feed->language()->getId());
......
...@@ -45,7 +45,7 @@ public function testDelete() { ...@@ -45,7 +45,7 @@ public function testDelete() {
$description = $feed->description->value ?: ''; $description = $feed->description->value ?: '';
$this->updateAndDelete($feed, NULL); $this->updateAndDelete($feed, NULL);
// Make sure the feed title is changed. // Make sure the feed title is changed.
$entities = entity_load_multiple_by_properties('aggregator_feed', ['description' => $description]); $entities = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->loadByProperties(['description' => $description]);
$this->assertTrue(empty($entities)); $this->assertTrue(empty($entities));
} }
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
*/ */
function comment_uninstall() { function comment_uninstall() {
// Remove the comment fields. // Remove the comment fields.
$fields = entity_load_multiple_by_properties('field_storage_config', ['type' => 'comment']); $storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
foreach ($fields as $field) { $fields = $storage->loadByProperties(['type' => 'comment']);
$field->delete(); $storage->delete($fields);
}
// Remove state setting. // Remove state setting.
\Drupal::state()->delete('comment.node_comment_statistics_scale'); \Drupal::state()->delete('comment.node_comment_statistics_scale');
......
...@@ -531,7 +531,7 @@ function comment_node_search_result(EntityInterface $node) { ...@@ -531,7 +531,7 @@ function comment_node_search_result(EntityInterface $node) {
function comment_user_cancel($edit, UserInterface $account, $method) { function comment_user_cancel($edit, UserInterface $account, $method) {
switch ($method) { switch ($method) {
case 'user_cancel_block_unpublish': case 'user_cancel_block_unpublish':
$comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]); $comments = \Drupal::entityTypeManager()->getStorage('comment')->loadByProperties(['uid' => $account->id()]);
foreach ($comments as $comment) { foreach ($comments as $comment) {
$comment->setUnpublished(); $comment->setUnpublished();
$comment->save(); $comment->save();
...@@ -540,7 +540,7 @@ function comment_user_cancel($edit, UserInterface $account, $method) { ...@@ -540,7 +540,7 @@ function comment_user_cancel($edit, UserInterface $account, $method) {
case 'user_cancel_reassign': case 'user_cancel_reassign':
/** @var \Drupal\comment\CommentInterface[] $comments */ /** @var \Drupal\comment\CommentInterface[] $comments */
$comments = entity_load_multiple_by_properties('comment', ['uid' => $account->id()]); $comments = \Drupal::entityTypeManager()->getStorage('comment')->loadByProperties(['uid' => $account->id()]);
foreach ($comments as $comment) { foreach ($comments as $comment) {
$comment->setOwnerId(0); $comment->setOwnerId(0);
$comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous')); $comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous'));
......
...@@ -177,7 +177,7 @@ public function testDeleteField() { ...@@ -177,7 +177,7 @@ public function testDeleteField() {
$field->delete(); $field->delete();
// The field still exists, deleted. // The field still exists, deleted.
$fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]);
$this->assertEqual(count($fields), 1, 'There is one deleted field'); $this->assertEqual(count($fields), 1, 'There is one deleted field');
$field = $fields[$field->uuid()]; $field = $fields[$field->uuid()];
$this->assertEqual($field->getTargetBundle(), $bundle, 'The deleted field is for the correct bundle'); $this->assertEqual($field->getTargetBundle(), $bundle, 'The deleted field is for the correct bundle');
...@@ -248,7 +248,7 @@ public function testPurgeWithDeletedAndActiveField() { ...@@ -248,7 +248,7 @@ public function testPurgeWithDeletedAndActiveField() {
$deleted_field_uuid = $deleted_field->uuid(); $deleted_field_uuid = $deleted_field->uuid();
// Reload the field storage. // Reload the field storage.
$field_storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE]); $field_storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $deleted_field_storage->uuid(), 'include_deleted' => TRUE]);
$deleted_field_storage = reset($field_storages); $deleted_field_storage = reset($field_storages);
// Create the field again. // Create the field again.
...@@ -265,7 +265,7 @@ public function testPurgeWithDeletedAndActiveField() { ...@@ -265,7 +265,7 @@ public function testPurgeWithDeletedAndActiveField() {
])->save(); ])->save();
// The field still exists, deleted, with the same field name. // The field still exists, deleted, with the same field name.
$fields = entity_load_multiple_by_properties('field_config', ['uuid' => $deleted_field_uuid, 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $deleted_field_uuid, 'include_deleted' => TRUE]);
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted'); $this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->isDeleted(), 'The field exists and is deleted');
$this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name); $this->assertTrue(isset($fields[$deleted_field_uuid]) && $fields[$deleted_field_uuid]->getName() == $field_name);
...@@ -292,7 +292,7 @@ public function testPurgeWithDeletedAndActiveField() { ...@@ -292,7 +292,7 @@ public function testPurgeWithDeletedAndActiveField() {
$this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name)); $this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name));
// The field has been removed from the system. // The field has been removed from the system.
$fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_storage_uuid' => $deleted_field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]);
$this->assertEqual(count($fields), 0, 'The field is gone'); $this->assertEqual(count($fields), 0, 'The field is gone');
// Verify there are still 10 entries in the main table. // Verify there are still 10 entries in the main table.
...@@ -351,19 +351,19 @@ public function testPurgeField() { ...@@ -351,19 +351,19 @@ public function testPurgeField() {
$this->checkHooksInvocations($hooks, $actual_hooks); $this->checkHooksInvocations($hooks, $actual_hooks);
// The field still exists, deleted. // The field still exists, deleted.
$fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]);
$this->assertEqual(count($fields), 1, 'There is one deleted field'); $this->assertEqual(count($fields), 1, 'There is one deleted field');
// Purge the field. // Purge the field.
field_purge_batch($batch_size); field_purge_batch($batch_size);
// The field is gone. // The field is gone.
$fields = entity_load_multiple_by_properties('field_config', ['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]);
$this->assertEqual(count($fields), 0, 'The field is gone'); $this->assertEqual(count($fields), 0, 'The field is gone');
// The field storage still exists, not deleted, because it has a second // The field storage still exists, not deleted, because it has a second
// field. // field.
$storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($storages[$field_storage->uuid()]), 'The field storage exists and is not deleted'); $this->assertTrue(isset($storages[$field_storage->uuid()]), 'The field storage exists and is not deleted');
} }
...@@ -402,17 +402,17 @@ public function testPurgeFieldStorage() { ...@@ -402,17 +402,17 @@ public function testPurgeFieldStorage() {
$this->checkHooksInvocations($hooks, $actual_hooks); $this->checkHooksInvocations($hooks, $actual_hooks);
// The field still exists, deleted. // The field still exists, deleted.
$fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $field->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted'); $this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted');
// Purge again to purge the field. // Purge again to purge the field.
field_purge_batch(0); field_purge_batch(0);
// The field is gone. // The field is gone.
$fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $field->uuid(), 'include_deleted' => TRUE]);
$this->assertEqual(count($fields), 0, 'The field is purged.'); $this->assertEqual(count($fields), 0, 'The field is purged.');
// The field storage still exists, not deleted. // The field storage still exists, not deleted.
$storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($storages[$field_storage->uuid()]) && !$storages[$field_storage->uuid()]->isDeleted(), '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. // Delete the second field.
...@@ -437,18 +437,18 @@ public function testPurgeFieldStorage() { ...@@ -437,18 +437,18 @@ public function testPurgeFieldStorage() {
$this->checkHooksInvocations($hooks, $actual_hooks); $this->checkHooksInvocations($hooks, $actual_hooks);
// The field and the storage still exist, deleted. // The field and the storage still exist, deleted.
$fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $field->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted'); $this->assertTrue(isset($fields[$field->uuid()]) && $fields[$field->uuid()]->isDeleted(), 'The field exists and is deleted');
$storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]);
$this->assertTrue(isset($storages[$field_storage->uuid()]) && $storages[$field_storage->uuid()]->isDeleted(), '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. // Purge again to purge the field and the storage.
field_purge_batch(0); field_purge_batch(0);
// The field and the storage are gone. // The field and the storage are gone.
$fields = entity_load_multiple_by_properties('field_config', ['uuid' => $field->uuid(), 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['uuid' => $field->uuid(), 'include_deleted' => TRUE]);
$this->assertEqual(count($fields), 0, 'The field is purged.'); $this->assertEqual(count($fields), 0, 'The field is purged.');
$storages = entity_load_multiple_by_properties('field_storage_config', ['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]); $storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['uuid' => $field_storage->uuid(), 'include_deleted' => TRUE]);
$this->assertEqual(count($storages), 0, 'The field storage is purged.'); $this->assertEqual(count($storages), 0, 'The field storage is purged.');
} }
......
...@@ -283,13 +283,13 @@ public function testDeleteFieldNoData() { ...@@ -283,13 +283,13 @@ public function testDeleteFieldNoData() {
FieldConfig::create($another_field_definition)->save(); FieldConfig::create($another_field_definition)->save();
// Test that the first field is not deleted, and then delete it. // Test that the first field is not deleted, and then delete it.
$field = current(entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE])); $field = current(\Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]));
$this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.'); $this->assertTrue(!empty($field) && empty($field->deleted), 'A new field is not marked for deletion.');
$field->delete(); $field->delete();
// Make sure the field was deleted without being marked for purging as there // Make sure the field was deleted without being marked for purging as there
// was no data. // was no data.
$fields = entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $this->fieldDefinition['field_name'], 'bundle' => $this->fieldDefinition['bundle'], 'include_deleted' => TRUE]);
$this->assertEquals(0, count($fields), 'A deleted field is marked for deletion.'); $this->assertEquals(0, count($fields), 'A deleted field is marked for deletion.');
// Try to load the field normally and make sure it does not show up. // Try to load the field normally and make sure it does not show up.
......
...@@ -213,13 +213,14 @@ public function testRead() { ...@@ -213,13 +213,14 @@ public function testRead() {
$id = $field_storage->id(); $id = $field_storage->id();
// Check that 'single column' criteria works. // Check that 'single column' criteria works.
$fields = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name']]); $field_storage_config_storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
$fields = $field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name']]);
$this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.');
// Check that 'multi column' criteria works. // Check that 'multi column' criteria works.
$fields = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'type' => $field_storage_definition['type']]); $fields = $field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'type' => $field_storage_definition['type']]);
$this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.'); $this->assertTrue(count($fields) == 1 && isset($fields[$id]), 'The field was properly read.');
$fields = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'type' => 'foo']); $fields = $field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'type' => 'foo']);
$this->assertTrue(empty($fields), 'No field was found.'); $this->assertTrue(empty($fields), 'No field was found.');
// Create a field from the field storage. // Create a field from the field storage.
...@@ -314,17 +315,18 @@ public function testDeleteNoData() { ...@@ -314,17 +315,18 @@ public function testDeleteNoData() {
FieldConfig::create($another_field_definition)->save(); FieldConfig::create($another_field_definition)->save();
// Test that the first field is not deleted, and then delete it. // Test that the first field is not deleted, and then delete it.
$field_storage = current(entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE])); $field_storage_config_storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
$field_storage = current($field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]));
$this->assertTrue(!empty($field_storage) && !$field_storage->isDeleted(), '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(); FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();
// Make sure that the field storage is deleted as it had no data. // Make sure that the field storage is deleted as it had no data.
$field_storages = entity_load_multiple_by_properties('field_storage_config', ['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]); $field_storages = $field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'include_deleted' => TRUE]);
$this->assertEquals(0, count($field_storages), 'Field storage was deleted'); $this->assertEquals(0, count($field_storages), 'Field storage was deleted');
// Make sure that this field is marked as deleted when it is // Make sure that this field is marked as deleted when it is
// specifically loaded. // specifically loaded.
$fields = entity_load_multiple_by_properties('field_config', ['entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE]); $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['entity_type' => 'entity_test', 'field_name' => $field_definition['field_name'], 'bundle' => $field_definition['bundle'], 'include_deleted' => TRUE]);
$this->assertEquals(0, count($fields), 'Field storage was deleted'); $this->assertEquals(0, count($fields), 'Field storage was deleted');
// Try to load the storage normally and make sure it does not show up. // Try to load the storage normally and make sure it does not show up.
......
...@@ -177,7 +177,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E ...@@ -177,7 +177,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E
// @todo Do not create a new entity in order to update it. See // @todo Do not create a new entity in order to update it. See
// https://www.drupal.org/node/2241865. // https://www.drupal.org/node/2241865.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', ['uri' => $uri]); $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]);
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$file->fid = $existing->id(); $file->fid = $existing->id();
...@@ -256,7 +256,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E ...@@ -256,7 +256,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E
$file->setFileUri($uri); $file->setFileUri($uri);
// If we are replacing an existing file re-use its database record. // If we are replacing an existing file re-use its database record.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', ['uri' => $uri]); $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]);
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$delete_source = TRUE; $delete_source = TRUE;
...@@ -579,7 +579,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM ...@@ -579,7 +579,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
// @todo Do not create a new entity in order to update it. See // @todo Do not create a new entity in order to update it. See
// https://www.drupal.org/node/2241865. // https://www.drupal.org/node/2241865.
if ($replace == FILE_EXISTS_REPLACE) { if ($replace == FILE_EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', ['uri' => $uri]); $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]);
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$file->fid = $existing->id(); $file->fid = $existing->id();
...@@ -659,7 +659,7 @@ function file_theme() { ...@@ -659,7 +659,7 @@ function file_theme() {
function file_file_download($uri) { function file_file_download($uri) {
// Get the file record based on the URI. If not in the database just return. // Get the file record based on the URI. If not in the database just return.
/** @var \Drupal\file\FileInterface[] $files */ /** @var \Drupal\file\FileInterface[] $files */
$files = entity_load_multiple_by_properties('file', ['uri' => $uri]); $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]);
if (count($files)) { if (count($files)) {
foreach ($files as $item) { foreach ($files as $item) {
// Since some database servers sometimes use a case-insensitive comparison // Since some database servers sometimes use a case-insensitive comparison
...@@ -1095,7 +1095,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va ...@@ -1095,7 +1095,7 @@ function _file_save_upload_single(\SplFileInfo $file_info, $form_field_name, $va
// @todo Do not create a new entity in order to update it. See // @todo Do not create a new entity in order to update it. See
// https://www.drupal.org/node/2241865. // https://www.drupal.org/node/2241865.
if ($replace == FileSystemInterface::EXISTS_REPLACE) { if ($replace == FileSystemInterface::EXISTS_REPLACE) {
$existing_files = entity_load_multiple_by_properties('file', ['uri' => $file->getFileUri()]); $existing_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $file->getFileUri()]);
if (count($existing_files)) { if (count($existing_files)) {
$existing = reset($existing_files); $existing = reset($existing_files);
$file->fid = $existing->id(); $file->fid = $existing->id();
......
...@@ -151,7 +151,7 @@ function file_test_file_validate(File $file) { ...@@ -151,7 +151,7 @@ function file_test_file_validate(File $file) {
*/ */
function file_test_file_download($uri) { function file_test_file_download($uri) {
if (\Drupal::state()->get('file_test.allow_all', FALSE)) { if (\Drupal::state()->get('file_test.allow_all', FALSE)) {
$files = entity_load_multiple_by_properties('file', ['uri' => $uri]); $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $uri]);
$file = reset($files); $file = reset($files);
return file_get_content_headers($file); return file_get_content_headers($file);
} }
......
...@@ -24,7 +24,7 @@ public function testLoadMissingFid() { ...@@ -24,7 +24,7 @@ public function testLoadMissingFid() {
* Try to load a non-existent file by URI. * Try to load a non-existent file by URI.
*/ */
public function testLoadMissingFilepath() { public function testLoadMissingFilepath() {
$files = entity_load_multiple_by_properties('file', ['uri' => 'foobar://misc/druplicon.png']); $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => 'foobar://misc/druplicon.png']);
$this->assertFalse(reset($files), "Try to load a file that doesn't exist in the database fails."); $this->assertFalse(reset($files), "Try to load a file that doesn't exist in the database fails.");
$this->assertFileHooksCalled([]); $this->assertFileHooksCalled([]);
} }
...@@ -33,7 +33,7 @@ public function testLoadMissingFilepath() { ...@@ -33,7 +33,7 @@ public function testLoadMissingFilepath() {
* Try to load a non-existent file by status. * Try to load a non-existent file by status.
*/ */
public function testLoadInvalidStatus() { public function testLoadInvalidStatus() {
$files = entity_load_multiple_by_properties('file', ['status' => -99]); $files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['status' => -99]);
$this->assertFalse(reset($files), 'Trying to load a file with an invalid status fails.'); $this->assertFalse(reset($files), 'Trying to load a file with an invalid status fails.');
$this->assertFileHooksCalled([]); $this->assertFileHooksCalled([]);
} }
...@@ -64,9 +64,9 @@ public function testMultiple() { ...@@ -64,9 +64,9 @@ public function testMultiple() {
// Load by path. // Load by path.
file_test_reset(); file_test_reset();
$by_path_files = entity_load_multiple_by_properties('file', ['uri' => $file->getFileUri()]); $by_path_files = \Drupal::entityTypeManager()->getStorage('file')->loadByProperties(['uri' => $file->getFileUri()]);
$this->assertFileHookCalled('load'); $this->assertFileHookCalled('load');
$this->assertEqual(1, count($by_path_files), 'entity_load_multiple_by_properties() returned an array of the correct size.'); $this->assertEqual(1, count($by_path_files), '\Drupal::entityTypeManager()->getStorage(\'file\')->loadByProperties() returned an array of the correct size.');
$by_path_file = reset($by_path_files); $by_path_file = reset($by_path_files);
$this->assertTrue($by_path_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.'); $this->assertTrue($by_path_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
$this->assertEqual($by_path_file->id(), $file->id(), 'Loading by filepath got the correct fid.', 'File'); $this->assertEqual($by_path_file->id(), $file->id(), 'Loading by filepath got the correct fid.', 'File');
......
...@@ -80,10 +80,9 @@ public function testForumUninstallWithField() { ...@@ -80,10 +80,9 @@ public function testForumUninstallWithField() {
// Delete any forum terms. // Delete any forum terms.
$vid = $this->config('forum.settings')->get('vocabulary'); $vid = $this->config('forum.settings')->get('vocabulary');
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]); $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
foreach ($terms as $term) { $terms = $storage->loadByProperties(['vid' => $vid]);
$term->delete(); $storage->delete($terms);
}
// Ensure that the forum node type can not be deleted. // Ensure that the forum node type can not be deleted.
$this->drupalGet('admin/structure/types/manage/forum'); $this->drupalGet('admin/structure/types/manage/forum');
...@@ -137,7 +136,7 @@ public function testForumUninstallWithoutFieldStorage() { ...@@ -137,7 +136,7 @@ public function testForumUninstallWithoutFieldStorage() {
// Delete all terms in the Forums vocabulary. Uninstalling the forum module // Delete all terms in the Forums vocabulary. Uninstalling the forum module
// will fail unless this is done. // will fail unless this is done.
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => 'forums']); $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => 'forums']);
foreach ($terms as $term) { foreach ($terms as $term) {
$term->delete(); $term->delete();
} }
......
...@@ -78,7 +78,7 @@ public function testMenuLanguage() { ...@@ -78,7 +78,7 @@ public function testMenuLanguage() {
]; ];
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save'));
// Check the link was added with the correct menu link default language. // Check the link was added with the correct menu link default language.
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $link_title]);
$menu_link = reset($menu_links); $menu_link = reset($menu_links);
$this->assertMenuLink([ $this->assertMenuLink([
'menu_name' => $menu_name, 'menu_name' => $menu_name,
...@@ -100,7 +100,7 @@ public function testMenuLanguage() { ...@@ -100,7 +100,7 @@ public function testMenuLanguage() {
]; ];
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save'));
// Check the link was added with the correct new menu link default language. // Check the link was added with the correct new menu link default language.
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $link_title]); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $link_title]);
$menu_link = reset($menu_links); $menu_link = reset($menu_links);
$this->assertMenuLink([ $this->assertMenuLink([
'menu_name' => $menu_name, 'menu_name' => $menu_name,
......
...@@ -254,7 +254,7 @@ public function deleteCustomMenu() { ...@@ -254,7 +254,7 @@ public function deleteCustomMenu() {
$this->assertNull(Menu::load($menu_name), 'Custom menu was deleted'); $this->assertNull(Menu::load($menu_name), 'Custom menu was deleted');
// Test if all menu links associated with the menu were removed from // Test if all menu links associated with the menu were removed from
// database. // database.
$result = entity_load_multiple_by_properties('menu_link_content', ['menu_name' => $menu_name]); $result = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['menu_name' => $menu_name]);
$this->assertFalse($result, 'All menu links associated with the custom menu were deleted.'); $this->assertFalse($result, 'All menu links associated with the custom menu were deleted.');
// Make sure there's no delete button on system menus. // Make sure there's no delete button on system menus.
...@@ -612,7 +612,7 @@ public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $ex ...@@ -612,7 +612,7 @@ public function addMenuLink($parent = '', $path = '/', $menu_name = 'tools', $ex
$this->assertResponse(200); $this->assertResponse(200);
$this->assertText('The menu link has been saved.'); $this->assertText('The menu link has been saved.');
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $title]); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $title]);
$menu_link = reset($menu_links); $menu_link = reset($menu_links);
$this->assertTrue($menu_link, 'Menu link was found in database.'); $this->assertTrue($menu_link, 'Menu link was found in database.');
...@@ -660,7 +660,7 @@ public function checkInvalidParentMenuLinks() { ...@@ -660,7 +660,7 @@ public function checkInvalidParentMenuLinks() {
'weight[0][value]' => '0', 'weight[0][value]' => '0',
]; ];
$this->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/manage/{$this->menu->id()}/add", $edit, t('Save'));
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => $title]); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => $title]);
$last_link = reset($menu_links); $last_link = reset($menu_links);
$created_links[] = 'tools:' . $last_link->getPluginId(); $created_links[] = 'tools:' . $last_link->getPluginId();
} }
......
...@@ -206,7 +206,7 @@ public function testBreadCrumbs() { ...@@ -206,7 +206,7 @@ public function testBreadCrumbs() {
'link[0][uri]' => '/node', 'link[0][uri]' => '/node',
]; ];
$this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
$menu_links = entity_load_multiple_by_properties('menu_link_content', ['title' => 'Root']); $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties(['title' => 'Root']);
$link = reset($menu_links); $link = reset($menu_links);
$edit = [ $edit = [
...@@ -240,7 +240,7 @@ public function testBreadCrumbs() { ...@@ -240,7 +240,7 @@ public function testBreadCrumbs() {
// the breadcrumb based on taxonomy term hierarchy. // the breadcrumb based on taxonomy term hierarchy.
$parent_tid = 0; $parent_tid = 0;
foreach ($tags as $name => $null) { foreach ($tags as $name => $null) {
$terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $name]); $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => $name]);
$term = reset($terms); $term = reset($terms);
$tags[$name]['term'] = $term; $tags[$name]['term'] = $term;
if ($parent_tid) { if ($parent_tid) {
...@@ -261,7 +261,7 @@ public function testBreadCrumbs() { ...@@ -261,7 +261,7 @@ public function testBreadCrumbs() {
'enabled[value]' => 1, 'enabled[value]' => 1,
]; ];
$this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save')); $this->drupalPostForm("admin/structure/menu/manage/$menu/add", $edit, t('Save'));
$menu_links = entity_load_multiple_by_properties('menu_link_content', [ $menu_links = \Drupal::entityTypeManager()->getStorage('menu_link_content')->loadByProperties([
'title' => $edit['title[0][value]'], 'title' => $edit['title[0][value]'],
'link.uri' => 'internal:/taxonomy/term/' . $term->id(), 'link.uri' => 'internal:/taxonomy/term/' . $term->id(),
]); ]);
......
...@@ -182,10 +182,10 @@ public function testUninstallDependents() { ...@@ -182,10 +182,10 @@ public function testUninstallDependents() {
// Ensure taxonomy has been loaded into the test-runner after forum was // Ensure taxonomy has been loaded into the test-runner after forum was
// enabled. // enabled.
\Drupal::moduleHandler()->load('taxonomy'); \Drupal::moduleHandler()->load('taxonomy');
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]); $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
foreach ($terms as $term) { $terms = $storage->loadByProperties(['vid' => $vid]);
$term->delete(); $storage->delete($terms);
}
// Uninstall the forum module, and check that taxonomy now can also be // Uninstall the forum module, and check that taxonomy now can also be
// uninstalled. // uninstalled.
$edit = ['uninstall[forum]' => 'forum']; $edit = ['uninstall[forum]' => 'forum'];
......
...@@ -147,7 +147,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti ...@@ -147,7 +147,7 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
} }