You are here

protected function TrackingHelper::isEntityReferenceDataDefinition in Search API 8

Determines whether the given property is a reference to an entity.

Parameters

\Drupal\Core\TypedData\DataDefinitionInterface $property_definition: The property to test.

\Drupal\Core\Cache\RefinableCacheableDependencyInterface $cacheability: A cache metadata object to track any caching information necessary in this method call.

Return value

array This method will return an empty array if $property is not an entity reference. Otherwise it will return an associative array with the following structure:

  • entity_type: (string) The entity type to which $property refers.
  • bundles: (array) A list of bundles to which $property refers. In case specific bundles cannot be determined or the $property points to all the bundles, this key will contain an empty array.
1 call to TrackingHelper::isEntityReferenceDataDefinition()
TrackingHelper::getForeignEntityRelationsMap in src/Utility/TrackingHelper.php
Analyzes the index fields and constructs a map of entity references.

File

src/Utility/TrackingHelper.php, line 275

Class

TrackingHelper
Provides datasource-independent item change tracking functionality.

Namespace

Drupal\search_api\Utility

Code

protected function isEntityReferenceDataDefinition(DataDefinitionInterface $property_definition, RefinableCacheableDependencyInterface $cacheability) : array {
  $return = [];
  if ($property_definition instanceof FieldItemDataDefinitionInterface && $property_definition
    ->getFieldDefinition()
    ->getType() === 'entity_reference') {
    $field = $property_definition
      ->getFieldDefinition();
    $cacheability
      ->addCacheableDependency($field);
    $return['entity_type'] = $field
      ->getSetting('target_type');
    $field_settings = $field
      ->getSetting('handler_settings');
    $return['bundles'] = $field_settings['target_bundles'] ?? [];
  }
  elseif ($property_definition instanceof EntityDataDefinitionInterface) {
    $return['entity_type'] = $property_definition
      ->getEntityTypeId();
    $return['bundles'] = $property_definition
      ->getBundles() ?: [];
  }
  return $return;
}