You are here

private function ImportEntityManager::isFieldReferencedToSubclassOf in Acquia Content Hub 8

Determine if field have link to ConfigEntityInterface entity.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to check for differences.

string $field_name: The machine name of the field.

string $subclass: The class or interface to check.

Return value

bool TRUE if field have link to ConfigEntityInterface entity, FALSE otherwise.

1 call to ImportEntityManager::isFieldReferencedToSubclassOf()
ImportEntityManager::compareRevisions in src/ImportEntityManager.php
Compare entities by checking if the fields information has changed.

File

src/ImportEntityManager.php, line 253

Class

ImportEntityManager
Provides a service for managing imported entities' actions.

Namespace

Drupal\acquia_contenthub

Code

private function isFieldReferencedToSubclassOf(EntityInterface $entity, $field_name, $subclass = '\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface') {
  if (empty($entity) || empty($field_name)) {
    return FALSE;
  }
  $field_type = $entity
    ->getFieldDefinition($field_name)
    ->getType();
  if ($field_type == 'entity_reference') {
    $field_references = $entity
      ->get($field_name)
      ->referencedEntities();
    foreach ($field_references as $field_reference) {
      if ($field_reference
        ->getEntityType()
        ->entityClassImplements($subclass)) {
        return TRUE;
      }
    }
  }
  return FALSE;
}