public function EntityUsage::deleteByTargetEntity in Entity Usage 8.2
Same name and namespace in other branches
- 8.4 src/EntityUsage.php \Drupal\entity_usage\EntityUsage::deleteByTargetEntity()
- 8.3 src/EntityUsage.php \Drupal\entity_usage\EntityUsage::deleteByTargetEntity()
Delete all records for a given target entity.
Parameters
int|string $target_id: The target entity ID.
string $target_type: The target entity type.
Overrides EntityUsageInterface::deleteByTargetEntity
File
- src/
EntityUsage.php, line 207
Class
- EntityUsage
- Defines the entity usage base class.
Namespace
Drupal\entity_usageCode
public function deleteByTargetEntity($target_id, $target_type) {
// Entities can have string IDs. We support that by using different columns
// on each case.
$target_id_column = $this
->isInt($target_id) ? 'target_id' : 'target_id_string';
$query = $this->connection
->delete($this->tableName)
->condition($target_id_column, $target_id)
->condition('target_type', $target_type);
$query
->execute();
$event = new EntityUsageEvent($target_id, $target_type, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
$this->eventDispatcher
->dispatch(Events::DELETE_BY_TARGET_ENTITY, $event);
}