You are here

private function EntityReference::incrementEntityReferenceUsage in Entity Usage 8

Helper method to increment 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::incrementEntityReferenceUsage()
EntityReference::trackOnEntityCreation in src/Plugin/EntityUsage/Track/EntityReference.php
Track usage updates on the creation 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 237

Class

EntityReference
Tracks usage of entities related in entity_reference fields.

Namespace

Drupal\entity_usage\Plugin\EntityUsage\Track

Code

private function incrementEntityReferenceUsage(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
    ->add($target_id, $referenced_entity_type, $entity
    ->id(), $entity
    ->getEntityTypeId(), $this->pluginId);
}