Commit d6075b5f authored by catch's avatar catch

Issue #1822150 by sun: Fixed EntityStorageControllerInterface::delete() should...

Issue #1822150 by sun: Fixed EntityStorageControllerInterface::delete() should accept an array of entities, not IDs.
parent 84e4e29a
......@@ -225,13 +225,15 @@ function entity_load_unchanged($entity_type, $id) {
/**
* Deletes multiple entities permanently.
*
* @param $entity_type
* @param string $entity_type
* The type of the entity.
* @param $ids
* @param array $ids
* An array of entity IDs of the entities to delete.
*/
function entity_delete_multiple($entity_type, $ids) {
entity_get_controller($entity_type)->delete($ids);
function entity_delete_multiple($entity_type, array $ids) {
$controller = entity_get_controller($entity_type);
$entities = $controller->load($ids);
$controller->delete($entities);
}
/**
......
......@@ -239,8 +239,7 @@ public function create(array $values) {
/**
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::delete().
*/
public function delete($ids) {
$entities = $ids ? $this->load($ids) : FALSE;
public function delete(array $entities) {
if (!$entities) {
// If no IDs or invalid IDs were passed, do nothing.
return;
......
......@@ -443,8 +443,7 @@ public function create(array $values) {
/**
* Implements Drupal\Core\Entity\EntityStorageControllerInterface::delete().
*/
public function delete($ids) {
$entities = $ids ? $this->load($ids) : FALSE;
public function delete(array $entities) {
if (!$entities) {
// If no IDs or invalid IDs were passed, do nothing.
return;
......
......@@ -320,7 +320,7 @@ public function save() {
*/
public function delete() {
if (!$this->isNew()) {
entity_get_controller($this->entityType)->delete(array($this->id()));
entity_get_controller($this->entityType)->delete(array($this->id() => $this));
}
}
......
......@@ -88,13 +88,13 @@ public function create(array $values);
/**
* Deletes permanently saved entities.
*
* @param $ids
* An array of entity IDs.
* @param array $entities
* An array of entity objects to delete.
*
* @throws Drupal\Core\Entity\EntityStorageException
* In case of failures, an exception is thrown.
*/
public function delete($ids);
public function delete(array $entities);
/**
* Saves the entity permanently.
......
......@@ -28,7 +28,7 @@ function testUnused() {
// Check that deletion removes the file and database record.
$this->assertTrue(is_file($file->uri), t('File exists.'));
$file->delete();
$this->assertFileHooksCalled(array('delete', 'load'));
$this->assertFileHooksCalled(array('delete'));
$this->assertFalse(file_exists($file->uri), t('Test file has actually been deleted.'));
$this->assertFalse(file_load($file->fid), t('File was removed from the database.'));
}
......
......@@ -111,7 +111,7 @@ function entity_test_load_multiple(array $ids = NULL, $reset = FALSE) {
* An array of test entity IDs.
*/
function entity_test_delete_multiple(array $ids) {
entity_get_controller('entity_test')->delete($ids);
entity_delete_multiple('entity_test', $ids);
}
/**
......
......@@ -1973,7 +1973,7 @@ function user_delete($uid) {
* @see hook_user_delete()
*/
function user_delete_multiple(array $uids) {
entity_get_controller('user')->delete($uids);
entity_delete_multiple('user', $uids);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment