private function EntityReference::decrementEntityReferenceUsage in Entity Usage 8
Helper method to decrement the usage in entity_reference fields.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The host entity object.
string $field_name: The name of the entity_reference field, present in $entity.
int $target_id: The id of the target entity.
2 calls to EntityReference::decrementEntityReferenceUsage()
- EntityReference::trackOnEntityDeletion in src/
Plugin/ EntityUsage/ Track/ EntityReference.php - Track usage updates on the deletion of entities.
- EntityReference::trackOnEntityUpdate in src/
Plugin/ EntityUsage/ Track/ EntityReference.php - Track usage updates on the edition of entities.
File
- src/
Plugin/ EntityUsage/ Track/ EntityReference.php, line 254
Class
- EntityReference
- Tracks usage of entities related in entity_reference fields.
Namespace
Drupal\entity_usage\Plugin\EntityUsage\TrackCode
private function decrementEntityReferenceUsage(ContentEntityInterface $entity, $field_name, $target_id) {
/** @var \Drupal\field\Entity\FieldConfig $definition */
$definition = $this->entityFieldManager
->getFieldDefinitions($entity
->getEntityTypeId(), $entity
->bundle())[$field_name];
$referenced_entity_type = $definition
->getSetting('target_type');
$this->usageService
->delete($target_id, $referenced_entity_type, $entity
->id(), $entity
->getEntityTypeId());
}