You are here

function cer_sync_corresponding_references in Corresponding Entity References 8.4

Synchronize corresponding references for an entity.

Parameters

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

bool $deleted: Whether the entity is deleted.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

3 calls to cer_sync_corresponding_references()
cer_entity_delete in ./cer.module
Implements hook_entity_delete().
cer_entity_insert in ./cer.module
Implements hook_entity_insert().
cer_entity_update in ./cer.module
Implements hook_entity_update().

File

./cer.module, line 43
CER keeps reference fields in sync.

Code

function cer_sync_corresponding_references(EntityInterface $entity, $deleted = FALSE) {
  if (!$entity instanceof FieldableEntityInterface) {
    return;
  }

  /** @var \Drupal\cer\CorrespondingReferenceStorageInterface $storage */
  $storage = \Drupal::entityTypeManager()
    ->getStorage('corresponding_reference');
  $references = $storage
    ->loadValid($entity);
  foreach ($references as $reference) {
    $reference
      ->synchronizeCorrespondingFields($entity, $deleted);
  }
}