You are here

public function ContentEntity::getPropertyDefinitions in Search API 8

Retrieves the properties exposed by the underlying complex data type.

Property names have to start with a letter or an underscore, followed by any number of letters, numbers and underscores.

Return value

\Drupal\Core\TypedData\DataDefinitionInterface[] An associative array of property data types, keyed by the property name.

Overrides DatasourcePluginBase::getPropertyDefinitions

1 call to ContentEntity::getPropertyDefinitions()
ContentEntity::getFieldDependencies in src/Plugin/search_api/datasource/ContentEntity.php
Retrieves any dependencies of the given fields.

File

src/Plugin/search_api/datasource/ContentEntity.php, line 465

Class

ContentEntity
Represents a datasource which exposes the content entities.

Namespace

Drupal\search_api\Plugin\search_api\datasource

Code

public function getPropertyDefinitions() {
  $type = $this
    ->getEntityTypeId();
  $properties = $this
    ->getEntityFieldManager()
    ->getBaseFieldDefinitions($type);
  if ($bundles = array_keys($this
    ->getBundles())) {
    foreach ($bundles as $bundle_id) {
      $properties += $this
        ->getEntityFieldManager()
        ->getFieldDefinitions($type, $bundle_id);
    }
  }

  // Exclude properties with custom storage, since we can't extract them
  // currently, due to a shortcoming of Core's Typed Data API. See #2695527.
  // Computed properties should mostly be OK, though, even though they still
  // count as having "custom storage". The "Path" field from the Core module
  // does not work, though, so we explicitly exclude it here to avoid
  // confusion.
  foreach ($properties as $key => $property) {
    if (!$property
      ->isComputed() || $key === 'path') {
      if ($property
        ->getFieldStorageDefinition()
        ->hasCustomStorage()) {
        unset($properties[$key]);
      }
    }
  }
  return $properties;
}