On this page
public function EntityStorageBase::delete
public EntityStorageBase::delete(array $entities)
Deletes permanently saved entities.
Parameters
array $entities: An array of entity objects to delete.
Throws
\Drupal\Core\Entity\EntityStorageException In case of failures, an exception is thrown.
Overrides EntityStorageInterface::delete
File
- core/lib/Drupal/Core/Entity/EntityStorageBase.php, line 343
Class
- EntityStorageBase
- A base entity storage class.
Namespace
Drupal\Core\EntityCode
public function delete(array $entities) {
if (!$entities) {
// If no entities were passed, do nothing.
return;
}
// Ensure that the entities are keyed by ID.
$keyed_entities = [];
foreach ($entities as $entity) {
$keyed_entities[$entity->id()] = $entity;
}
// Allow code to run before deleting.
$entity_class = $this->entityClass;
$entity_class::preDelete($this, $keyed_entities);
foreach ($keyed_entities as $entity) {
$this->invokeHook('predelete', $entity);
}
// Perform the delete and reset the static cache for the deleted entities.
$this->doDelete($keyed_entities);
$this->resetCache(array_keys($keyed_entities));
// Allow code to run after deleting.
$entity_class::postDelete($this, $keyed_entities);
foreach ($keyed_entities as $entity) {
$this->invokeHook('delete', $entity);
}
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityStorageBase.php/function/EntityStorageBase::delete/8.1.x