You are here

public function PbfSynchronize::synchronize in Permissions by field 8

Synchronize a Pbf field form entity.

Parameters

string $op: The operation to run.

\Drupal\Core\Entity\EntityInterface $entity: The entity to synchronize.

File

src/PbfSynchronize.php, line 61

Class

PbfSynchronize
Class PbfSynchronize.

Namespace

Drupal\pbf

Code

public function synchronize($op, EntityInterface $entity) {
  $fields = $this
    ->findPbfFieldsSynchronized($entity);
  if (empty($fields)) {
    return;
  }

  /** @var \Drupal\field\FieldConfigInterface $fieldConfig */
  foreach ($fields as $field_name => $fieldConfig) {
    if ($target_field_id = $this
      ->isSynchronizedWith($fieldConfig)) {
      $this
        ->synchronizeTarget($op, $target_field_id, $fieldConfig, $entity);
    }
    elseif ($source_field_id = $this
      ->isSynchronizedBy($fieldConfig)) {
      $this
        ->synchronizeTarget($op, $source_field_id, $fieldConfig, $entity);
    }
    else {
      return;
    }
  }
}