You are here

protected function PbfSynchronize::findPbfFieldsSynchronized in Permissions by field 8

Find pbf fields synchronized attached on an entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity on which search Pbf fields.

Return value

array $pbf_fields An array of Pbf fields found.

1 call to PbfSynchronize::findPbfFieldsSynchronized()
PbfSynchronize::synchronize in src/PbfSynchronize.php
Synchronize a Pbf field form entity.

File

src/PbfSynchronize.php, line 104

Class

PbfSynchronize
Class PbfSynchronize.

Namespace

Drupal\pbf

Code

protected function findPbfFieldsSynchronized(EntityInterface $entity) {
  $pbf_fields = [];

  // Check if a Pbf field is attached to the entity.

  /* @var  \Drupal\Core\Entity\FieldableEntityInterface $entity */
  $fields = $entity
    ->getFieldDefinitions();

  /** @var \Drupal\Core\Field\FieldConfigInterface $field */
  foreach ($fields as $field_name => $field) {
    if ($field instanceof FieldConfigInterface && $field
      ->getType() == 'pbf' && $this
      ->hasUnlimitedCardinality($field)) {
      if ($this
        ->isSynchronizedWith($field) || $this
        ->isSynchronizedBy($field)) {
        $pbf_fields[$field_name] = $field;
      }
    }
  }
  return $pbf_fields;
}