You are here

public function EntityReference::trackOnEntityCreation in Entity Usage 8

Track usage updates on the creation of entities.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity we are dealing with.

Overrides EntityUsageTrackBase::trackOnEntityCreation

File

src/Plugin/EntityUsage/Track/EntityReference.php, line 85

Class

EntityReference
Tracks usage of entities related in entity_reference fields.

Namespace

Drupal\entity_usage\Plugin\EntityUsage\Track

Code

public function trackOnEntityCreation(ContentEntityInterface $entity) {
  foreach ($this
    ->entityReferenceFieldsAvailable($entity) as $field_name) {
    if (!$entity->{$field_name}
      ->isEmpty()) {

      /** @var \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem $field_item */
      foreach ($entity->{$field_name} as $field_item) {

        // This item got added. Track the usage up.
        $this
          ->incrementEntityReferenceUsage($entity, $field_name, $field_item->target_id);
      }
    }
  }
}