You are here

public function EntityUsage::deleteBySourceEntity in Entity Usage 8.3

Same name and namespace in other branches
  1. 8.4 src/EntityUsage.php \Drupal\entity_usage\EntityUsage::deleteBySourceEntity()
  2. 8.2 src/EntityUsage.php \Drupal\entity_usage\EntityUsage::deleteBySourceEntity()

Delete all records for a given source entity.

Parameters

int|string $source_id: The source entity ID.

string $source_type: The source entity type.

string $source_langcode: (optional) The source entity language code. Defaults to NULL.

string $source_vid: (optional) The source entity revision ID. Defaults to NULL.

Overrides EntityUsageInterface::deleteBySourceEntity

File

src/EntityUsage.php, line 180

Class

EntityUsage
Defines the entity usage base class.

Namespace

Drupal\entity_usage

Code

public function deleteBySourceEntity($source_id, $source_type, $source_langcode = NULL, $source_vid = NULL) {

  // Entities can have string IDs. We support that by using different columns
  // on each case.
  $source_id_column = $this
    ->isInt($source_id) ? 'source_id' : 'source_id_string';
  $query = $this->connection
    ->delete($this->tableName)
    ->condition($source_id_column, $source_id)
    ->condition('source_type', $source_type);
  if ($source_langcode) {
    $query
      ->condition('source_langcode', $source_langcode);
  }
  if ($source_vid) {
    $query
      ->condition('source_vid', $source_vid);
  }
  $query
    ->execute();
  $event = new EntityUsageEvent(NULL, NULL, $source_id, $source_type, $source_langcode, $source_vid);
  $this->eventDispatcher
    ->dispatch(Events::DELETE_BY_SOURCE_ENTITY, $event);
}