You are here

private function PbfSynchronize::getReferenceIds in Permissions by field 8

Gets all the referenced entity IDs from a specific field on an entity.

Parameters

EntityInterface $entity: The entity to scan for references.

FieldConfigInterface $field: Field config definition.

Return value

array Array of unique ids, empty if there are no references or the field does not exist on $entity.

3 calls to PbfSynchronize::getReferenceIds()
PbfSynchronize::delete in src/PbfSynchronize.php
Update entities ref. by a Pbf field synchronized when entity is deleted.
PbfSynchronize::insert in src/PbfSynchronize.php
Update entities ref. by a Pbf field synchronized when entity is created.
PbfSynchronize::update in src/PbfSynchronize.php
Update entities ref. by a Pbf field synchronized when entity is updated.

File

src/PbfSynchronize.php, line 158

Class

PbfSynchronize
Class PbfSynchronize.

Namespace

Drupal\pbf

Code

private function getReferenceIds(EntityInterface $entity, FieldConfigInterface $field) {
  $ids = array();
  $field_name = $field
    ->getName();

  /** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
  if ($entity
    ->hasField($field_name)) {
    foreach ($entity
      ->get($field_name)
      ->getValue() as $delta => $reference) {
      $ids[$delta] = $reference['target_id'];
    }
  }
  return array_unique(array_filter($ids));
}