public function EntityUsage::add in Entity Usage 8
Records that an entity is referencing another entity.
Examples:
- A node that references another node using an entityreference field.
Parameters
int $t_id: The identifier of the target entity.
string $t_type: The type of the target entity.
int $re_id: The identifier of the referencing entity.
string $re_type: The type of the entity that is referencing.
string $method: (optional) The method or way the two entities are being referenced. Defaults to 'entity_reference'.
int $count: (optional) The number of references to add to the object. Defaults to 1.
Overrides EntityUsageInterface::add
File
- src/
EntityUsage.php, line 59
Class
- EntityUsage
- Defines the entity usage base class.
Namespace
Drupal\entity_usageCode
public function add($t_id, $t_type, $re_id, $re_type, $method = 'entity_reference', $count = 1) {
$this->connection
->merge($this->tableName)
->keys([
't_id' => $t_id,
't_type' => $t_type,
're_id' => $re_id,
're_type' => $re_type,
'method' => $method,
])
->fields([
'count' => $count,
])
->expression('count', 'count + :count', [
':count' => $count,
])
->execute();
$event = new EntityUsageEvent($t_id, $t_type, $re_id, $re_type, $method, $count);
$this->eventDispatcher
->dispatch(Events::USAGE_ADD, $event);
}