You are here

public static function EntityReferenceHandlerBase::getReferencedEntityTypesFromFieldDefinition in CMS Content Sync 2.1.x

Same name and namespace in other branches
  1. 8 src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::getReferencedEntityTypesFromFieldDefinition()
  2. 2.0.x src/Plugin/EntityReferenceHandlerBase.php \Drupal\cms_content_sync\Plugin\EntityReferenceHandlerBase::getReferencedEntityTypesFromFieldDefinition()

Parameters

$fieldDefinition:

Return value

array

2 calls to EntityReferenceHandlerBase::getReferencedEntityTypesFromFieldDefinition()
DefaultEntityReferenceHandler::supports in src/Plugin/cms_content_sync/field_handler/DefaultEntityReferenceHandler.php
Check if this handler supports the given field instance.
EntityReferenceHandlerBase::getReferencedEntityTypes in src/Plugin/EntityReferenceHandlerBase.php

File

src/Plugin/EntityReferenceHandlerBase.php, line 160

Class

EntityReferenceHandlerBase
Providing a base implementation for any reference field type.

Namespace

Drupal\cms_content_sync\Plugin

Code

public static function getReferencedEntityTypesFromFieldDefinition(FieldDefinitionInterface $fieldDefinition) {
  if ('dynamic_entity_reference' == $fieldDefinition
    ->getFieldStorageDefinition()
    ->getType()) {
    if ($fieldDefinition
      ->getFieldStorageDefinition()
      ->getSetting('exclude_entity_types')) {
      $entity_types = EntityHandlerPluginManager::getEntityTypes();
      $included = [];
      $excluded = $fieldDefinition
        ->getFieldStorageDefinition()
        ->getSetting('entity_type_ids');
      foreach ($entity_types as $entity_type) {
        if (!in_array($entity_type['entity_type'], $excluded)) {
          $included[] = $entity_type['entity_type'];
        }
      }
      return $included;
    }
    return $fieldDefinition
      ->getFieldStorageDefinition()
      ->getSetting('entity_type_ids');
  }
  $reference_type = $fieldDefinition
    ->getFieldStorageDefinition()
    ->getPropertyDefinition('entity')
    ->getTargetDefinition()
    ->getEntityTypeId();
  return [
    $reference_type,
  ];
}