Issue #3027178 by Berdir, alexpott, miroslav-lee, andypost, larowlan, mikelutz, JeroenT: Properly deprecate entity_load_multiple_by_properties()
parent
fb532b06f8
commit
bfe4794d88
|
@ -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
|
||||
* no matching entities are found.
|
||||
*
|
||||
* @deprecated as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use
|
||||
* the entity storage's loadByProperties() method to load an entity by their
|
||||
* property values:
|
||||
* @code
|
||||
* \Drupal::entityTypeManager()
|
||||
* ->getStorage($entity_type)
|
||||
* ->loadByProperties($values);
|
||||
* @endcode
|
||||
* @deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use the
|
||||
* entity type storage's loadByProperties() method.
|
||||
*
|
||||
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getStorage()
|
||||
* @see \Drupal\Core\Entity\EntityStorageInterface::loadByProperties()
|
||||
* @see https://www.drupal.org/node/3050910
|
||||
*/
|
||||
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()
|
||||
->getStorage($entity_type)
|
||||
->loadByProperties($values);
|
||||
|
|
|
@ -208,7 +208,7 @@ class DefaultProcessor extends AggregatorPluginSettingsBase implements Processor
|
|||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -77,7 +77,7 @@ class FeedLanguageTest extends AggregatorTestBase {
|
|||
// the one from the feed.
|
||||
foreach ($feeds as $feed) {
|
||||
/** @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.');
|
||||
foreach ($items as $item) {
|
||||
$this->assertEqual($item->language()->getId(), $feed->language()->getId());
|
||||
|
|
|
@ -45,7 +45,7 @@ class FeedProcessorPluginTest extends AggregatorTestBase {
|
|||
$description = $feed->description->value ?: '';
|
||||
$this->updateAndDelete($feed, NULL);
|
||||
// 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));
|
||||
}
|
||||
|
||||
|
|
|
@ -16,10 +16,9 @@ use Drupal\field\Entity\FieldStorageConfig;
|
|||
*/
|
||||
function comment_uninstall() {
|
||||
// Remove the comment fields.
|
||||
$fields = entity_load_multiple_by_properties('field_storage_config', ['type' => 'comment']);
|
||||
foreach ($fields as $field) {
|
||||
$field->delete();
|
||||
}
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('field_storage_config');
|
||||
$fields = $storage->loadByProperties(['type' => 'comment']);
|
||||
$storage->delete($fields);
|
||||
|
||||
// Remove state setting.
|
||||
\Drupal::state()->delete('comment.node_comment_statistics_scale');
|
||||
|
|
|
@ -531,7 +531,7 @@ function comment_node_search_result(EntityInterface $node) {
|
|||
function comment_user_cancel($edit, UserInterface $account, $method) {
|
||||
switch ($method) {
|
||||
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) {
|
||||
$comment->setUnpublished();
|
||||
$comment->save();
|
||||
|
@ -540,7 +540,7 @@ function comment_user_cancel($edit, UserInterface $account, $method) {
|
|||
|
||||
case 'user_cancel_reassign':
|
||||
/** @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) {
|
||||
$comment->setOwnerId(0);
|
||||
$comment->setAuthorName(\Drupal::config('user.settings')->get('anonymous'));
|
||||
|
|
|
@ -177,7 +177,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$field->delete();
|
||||
|
||||
// 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');
|
||||
$field = $fields[$field->uuid()];
|
||||
$this->assertEqual($field->getTargetBundle(), $bundle, 'The deleted field is for the correct bundle');
|
||||
|
@ -248,7 +248,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$deleted_field_uuid = $deleted_field->uuid();
|
||||
|
||||
// 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);
|
||||
|
||||
// Create the field again.
|
||||
|
@ -265,7 +265,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
])->save();
|
||||
|
||||
// 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]->getName() == $field_name);
|
||||
|
||||
|
@ -292,7 +292,7 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$this->assertFalse(\Drupal::database()->schema()->tableExists($deleted_table_name));
|
||||
|
||||
// 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');
|
||||
|
||||
// Verify there are still 10 entries in the main table.
|
||||
|
@ -351,19 +351,19 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$this->checkHooksInvocations($hooks, $actual_hooks);
|
||||
|
||||
// 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');
|
||||
|
||||
// Purge the field.
|
||||
field_purge_batch($batch_size);
|
||||
|
||||
// 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');
|
||||
|
||||
// The field storage still exists, not deleted, because it has a second
|
||||
// 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');
|
||||
}
|
||||
|
||||
|
@ -402,17 +402,17 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$this->checkHooksInvocations($hooks, $actual_hooks);
|
||||
|
||||
// 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');
|
||||
|
||||
// Purge again to purge the field.
|
||||
field_purge_batch(0);
|
||||
|
||||
// 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.');
|
||||
// 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');
|
||||
|
||||
// Delete the second field.
|
||||
|
@ -437,18 +437,18 @@ class BulkDeleteTest extends FieldKernelTestBase {
|
|||
$this->checkHooksInvocations($hooks, $actual_hooks);
|
||||
|
||||
// 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');
|
||||
$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');
|
||||
|
||||
// Purge again to purge the field and the storage.
|
||||
field_purge_batch(0);
|
||||
|
||||
// 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.');
|
||||
$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.');
|
||||
}
|
||||
|
||||
|
|
|
@ -283,13 +283,13 @@ class FieldCrudTest extends FieldKernelTestBase {
|
|||
FieldConfig::create($another_field_definition)->save();
|
||||
|
||||
// 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.');
|
||||
$field->delete();
|
||||
|
||||
// Make sure the field was deleted without being marked for purging as there
|
||||
// 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.');
|
||||
|
||||
// Try to load the field normally and make sure it does not show up.
|
||||
|
|
|
@ -213,13 +213,14 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
|
|||
$id = $field_storage->id();
|
||||
|
||||
// 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.');
|
||||
|
||||
// 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.');
|
||||
$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.');
|
||||
|
||||
// Create a field from the field storage.
|
||||
|
@ -314,17 +315,18 @@ class FieldStorageCrudTest extends FieldKernelTestBase {
|
|||
FieldConfig::create($another_field_definition)->save();
|
||||
|
||||
// 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.');
|
||||
FieldStorageConfig::loadByName('entity_test', $field_storage_definition['field_name'])->delete();
|
||||
|
||||
// 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');
|
||||
|
||||
// Make sure that this field is marked as deleted when it is
|
||||
// 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');
|
||||
|
||||
// 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
|
|||
// @todo Do not create a new entity in order to update it. See
|
||||
// https://www.drupal.org/node/2241865.
|
||||
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)) {
|
||||
$existing = reset($existing_files);
|
||||
$file->fid = $existing->id();
|
||||
|
@ -256,7 +256,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E
|
|||
$file->setFileUri($uri);
|
||||
// If we are replacing an existing file re-use its database record.
|
||||
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)) {
|
||||
$existing = reset($existing_files);
|
||||
$delete_source = TRUE;
|
||||
|
@ -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
|
||||
// https://www.drupal.org/node/2241865.
|
||||
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)) {
|
||||
$existing = reset($existing_files);
|
||||
$file->fid = $existing->id();
|
||||
|
@ -659,7 +659,7 @@ function file_theme() {
|
|||
function file_file_download($uri) {
|
||||
// Get the file record based on the URI. If not in the database just return.
|
||||
/** @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)) {
|
||||
foreach ($files as $item) {
|
||||
// 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
|
|||
// @todo Do not create a new entity in order to update it. See
|
||||
// https://www.drupal.org/node/2241865.
|
||||
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)) {
|
||||
$existing = reset($existing_files);
|
||||
$file->fid = $existing->id();
|
||||
|
|
|
@ -151,7 +151,7 @@ function file_test_file_validate(File $file) {
|
|||
*/
|
||||
function file_test_file_download($uri) {
|
||||
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);
|
||||
return file_get_content_headers($file);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class LoadTest extends FileManagedUnitTestBase {
|
|||
* Try to load a non-existent file by URI.
|
||||
*/
|
||||
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->assertFileHooksCalled([]);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class LoadTest extends FileManagedUnitTestBase {
|
|||
* Try to load a non-existent file by status.
|
||||
*/
|
||||
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->assertFileHooksCalled([]);
|
||||
}
|
||||
|
@ -64,9 +64,9 @@ class LoadTest extends FileManagedUnitTestBase {
|
|||
|
||||
// Load by path.
|
||||
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->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);
|
||||
$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');
|
||||
|
|
|
@ -80,10 +80,9 @@ class ForumUninstallTest extends BrowserTestBase {
|
|||
|
||||
// Delete any forum terms.
|
||||
$vid = $this->config('forum.settings')->get('vocabulary');
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]);
|
||||
foreach ($terms as $term) {
|
||||
$term->delete();
|
||||
}
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
|
||||
$terms = $storage->loadByProperties(['vid' => $vid]);
|
||||
$storage->delete($terms);
|
||||
|
||||
// Ensure that the forum node type can not be deleted.
|
||||
$this->drupalGet('admin/structure/types/manage/forum');
|
||||
|
@ -137,7 +136,7 @@ class ForumUninstallTest extends BrowserTestBase {
|
|||
|
||||
// Delete all terms in the Forums vocabulary. Uninstalling the forum module
|
||||
// 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) {
|
||||
$term->delete();
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class MenuUiLanguageTest extends BrowserTestBase {
|
|||
];
|
||||
$this->drupalPostForm("admin/structure/menu/manage/$menu_name/add", $edit, t('Save'));
|
||||
// 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);
|
||||
$this->assertMenuLink([
|
||||
'menu_name' => $menu_name,
|
||||
|
@ -100,7 +100,7 @@ class MenuUiLanguageTest extends BrowserTestBase {
|
|||
];
|
||||
$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.
|
||||
$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);
|
||||
$this->assertMenuLink([
|
||||
'menu_name' => $menu_name,
|
||||
|
|
|
@ -254,7 +254,7 @@ class MenuUiTest extends BrowserTestBase {
|
|||
$this->assertNull(Menu::load($menu_name), 'Custom menu was deleted');
|
||||
// Test if all menu links associated with the menu were removed from
|
||||
// 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.');
|
||||
|
||||
// Make sure there's no delete button on system menus.
|
||||
|
@ -612,7 +612,7 @@ class MenuUiTest extends BrowserTestBase {
|
|||
$this->assertResponse(200);
|
||||
$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);
|
||||
$this->assertTrue($menu_link, 'Menu link was found in database.');
|
||||
|
@ -660,7 +660,7 @@ class MenuUiTest extends BrowserTestBase {
|
|||
'weight[0][value]' => '0',
|
||||
];
|
||||
$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);
|
||||
$created_links[] = 'tools:' . $last_link->getPluginId();
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ class BreadcrumbTest extends BrowserTestBase {
|
|||
'link[0][uri]' => '/node',
|
||||
];
|
||||
$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);
|
||||
|
||||
$edit = [
|
||||
|
@ -240,7 +240,7 @@ class BreadcrumbTest extends BrowserTestBase {
|
|||
// the breadcrumb based on taxonomy term hierarchy.
|
||||
$parent_tid = 0;
|
||||
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);
|
||||
$tags[$name]['term'] = $term;
|
||||
if ($parent_tid) {
|
||||
|
@ -261,7 +261,7 @@ class BreadcrumbTest extends BrowserTestBase {
|
|||
'enabled[value]' => 1,
|
||||
];
|
||||
$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]'],
|
||||
'link.uri' => 'internal:/taxonomy/term/' . $term->id(),
|
||||
]);
|
||||
|
|
|
@ -182,10 +182,10 @@ class DependencyTest extends ModuleTestBase {
|
|||
// Ensure taxonomy has been loaded into the test-runner after forum was
|
||||
// enabled.
|
||||
\Drupal::moduleHandler()->load('taxonomy');
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vid]);
|
||||
foreach ($terms as $term) {
|
||||
$term->delete();
|
||||
}
|
||||
$storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
|
||||
$terms = $storage->loadByProperties(['vid' => $vid]);
|
||||
$storage->delete($terms);
|
||||
|
||||
// Uninstall the forum module, and check that taxonomy now can also be
|
||||
// uninstalled.
|
||||
$edit = ['uninstall[forum]' => 'forum'];
|
||||
|
|
|
@ -147,7 +147,7 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
|
|||
}
|
||||
// Load all Taxonomy module fields and delete those which use only this
|
||||
// vocabulary.
|
||||
$field_storages = entity_load_multiple_by_properties('field_storage_config', ['module' => 'taxonomy']);
|
||||
$field_storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['module' => 'taxonomy']);
|
||||
foreach ($field_storages as $field_storage) {
|
||||
$modified_storage = FALSE;
|
||||
// Term reference fields may reference terms from more than one
|
||||
|
|
|
@ -349,7 +349,7 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
|
|||
return [];
|
||||
}
|
||||
}
|
||||
return entity_load_multiple_by_properties('taxonomy_term', $values);
|
||||
return \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties($values);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,7 +31,8 @@ class LoadMultipleTest extends TaxonomyTestBase {
|
|||
$this->createTerm($vocabulary);
|
||||
}
|
||||
// Load the terms from the vocabulary.
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
|
||||
$term_storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term');
|
||||
$terms = $term_storage->loadByProperties(['vid' => $vocabulary->id()]);
|
||||
$count = count($terms);
|
||||
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', ['@count' => $count]));
|
||||
|
||||
|
@ -47,13 +48,13 @@ class LoadMultipleTest extends TaxonomyTestBase {
|
|||
$this->assertFalse($deleted_term);
|
||||
|
||||
// Load terms from the vocabulary by vid.
|
||||
$terms3 = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
|
||||
$terms3 = $term_storage->loadByProperties(['vid' => $vocabulary->id()]);
|
||||
$this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.');
|
||||
$this->assertFalse(isset($terms3[$deleted->id()]));
|
||||
|
||||
// Create a single term and load it by name.
|
||||
$term = $this->createTerm($vocabulary);
|
||||
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $term->getName()]);
|
||||
$loaded_terms = $term_storage->loadByProperties(['name' => $term->getName()]);
|
||||
$this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
|
||||
$loaded_term = reset($loaded_terms);
|
||||
$this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.');
|
||||
|
|
|
@ -85,7 +85,7 @@ class TaxonomyImageTest extends TaxonomyTestBase {
|
|||
$edit['files[field_test_0]'] = \Drupal::service('file_system')->realpath($image->uri);
|
||||
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
|
||||
$this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save'));
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $edit['name[0][value]']]);
|
||||
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['name' => $edit['name[0][value]']]);
|
||||
$term = reset($terms);
|
||||
$this->assertText(t('Created new term @name.', ['@name' => $term->getName()]));
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class TermKernelTest extends KernelTestBase {
|
|||
$valid_term = $this->createTerm($vocabulary);
|
||||
// Delete a valid term.
|
||||
$valid_term->delete();
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
|
||||
$terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => $vocabulary->id()]);
|
||||
$this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
|
||||
|
||||
// Delete an invalid term. Should not throw any notices.
|
||||
|
|
|
@ -431,7 +431,7 @@ class UserCancelTest extends BrowserTestBase {
|
|||
$this->drupalPostForm('comment/reply/node/' . $node->id() . '/comment', $edit, t('Preview'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
$this->assertText(t('Your comment has been posted.'));
|
||||
$comments = entity_load_multiple_by_properties('comment', ['subject' => $edit['subject[0][value]']]);
|
||||
$comments = \Drupal::entityTypeManager()->getStorage('comment')->loadByProperties(['subject' => $edit['subject[0][value]']]);
|
||||
$comment = reset($comments);
|
||||
$this->assertTrue($comment->id(), 'Comment found.');
|
||||
|
||||
|
|
|
@ -91,6 +91,22 @@ class EntityLegacyTest extends KernelTestBase {
|
|||
$this->assertEquals('entity_test.entity_test.default', $form_display->id());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation 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
|
||||
*/
|
||||
public function testEntityLoadMultipleByProperties() {
|
||||
$this->assertCount(0, entity_load_multiple_by_properties('entity_test', ['name' => 'published entity']));
|
||||
|
||||
EntityTest::create(['name' => 'published entity'])->save();
|
||||
$this->assertCount(1, entity_load_multiple_by_properties('entity_test', ['name' => 'published entity']));
|
||||
$this->assertCount(0, entity_load_multiple_by_properties('entity_test_mul', ['name' => 'published entity']));
|
||||
|
||||
EntityTest::create(['name' => 'published entity'])->save();
|
||||
EntityTestMul::create(['name' => 'published entity'])->save();
|
||||
$this->assertCount(2, entity_load_multiple_by_properties('entity_test', ['name' => 'published entity']));
|
||||
$this->assertCount(1, entity_load_multiple_by_properties('entity_test_mul', ['name' => 'published entity']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedDeprecation entity_view() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656
|
||||
* @expectedDeprecation entity_view_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->viewMultiple($entities, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656
|
||||
|
|
Loading…
Reference in New Issue