public function EntityUsage::delete in Entity Usage 8
Remove a record indicating that the entity is not being referenced anymore.
Parameters
int $t_id: The identifier of the target entity.
string $t_type: The type of the target entity.
int $re_id: (optional) The unique, numerid ID of the object containing the referenced entity. May be omitted if all references to an entity are being deleted. Defaults to NULL.
string $re_type: (optional) The type of the object containing the referenced entity. May be omitted if all entity-type references to a file are being deleted. Defaults to NULL.
int $count: (optional) The number of references to delete from the object. Defaults to 1. Zero may be specified to delete all references to the entity within a specific object.
Overrides EntityUsageInterface::delete
File
- src/
EntityUsage.php, line 81
Class
- EntityUsage
- Defines the entity usage base class.
Namespace
Drupal\entity_usageCode
public function delete($t_id, $t_type, $re_id = NULL, $re_type = NULL, $count = 1) {
// Delete rows that have an exact or less value to prevent empty rows.
$query = $this->connection
->delete($this->tableName)
->condition('t_type', $t_type)
->condition('t_id', $t_id);
if ($re_type && $re_id) {
$query
->condition('re_type', $re_type)
->condition('re_id', $re_id);
}
if ($count) {
$query
->condition('count', $count, '<=');
}
$result = $query
->execute();
// If the row has more than the specified count decrement it by that number.
if (!$result && $count > 0) {
$query = $this->connection
->update($this->tableName)
->condition('t_type', $t_type)
->condition('t_id', $t_id);
if ($re_type && $re_id) {
$query
->condition('re_type', $re_type)
->condition('re_id', $re_id);
}
$query
->expression('count', 'count - :count', [
':count' => $count,
]);
$query
->execute();
}
$event = new EntityUsageEvent($t_id, $t_type, $re_id, $re_type, NULL, $count);
$this->eventDispatcher
->dispatch(Events::USAGE_DELETE, $event);
}