You are here

public function ContentEntity::getBundles in Search API 8

Retrieves the bundles associated to this datasource.

Return value

string[] An associative array mapping the datasource's bundles' IDs to their labels. If the datasource doesn't contain any bundles, a single pseudo-bundle should be returned, usually equal to the datasource identifier (and label).

Overrides DatasourcePluginBase::getBundles

4 calls to ContentEntity::getBundles()
ContentEntity::getItemId in src/Plugin/search_api/datasource/ContentEntity.php
Retrieves the unique ID of an object from this datasource.
ContentEntity::getPartialItemIds in src/Plugin/search_api/datasource/ContentEntity.php
ContentEntity::getPropertyDefinitions in src/Plugin/search_api/datasource/ContentEntity.php
Retrieves the properties exposed by the underlying complex data type.
ContentEntity::loadMultiple in src/Plugin/search_api/datasource/ContentEntity.php
Loads multiple items.

File

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

Class

ContentEntity
Represents a datasource which exposes the content entities.

Namespace

Drupal\search_api\Plugin\search_api\datasource

Code

public function getBundles() {
  if (!$this
    ->hasBundles()) {

    // For entity types that have no bundle, return a default pseudo-bundle.
    return [
      $this
        ->getEntityTypeId() => $this
        ->label(),
    ];
  }
  $configuration = $this
    ->getConfiguration();

  // If "default" is TRUE (that is, "All except those selected"),remove all
  // the selected bundles from the available ones to compute the indexed
  // bundles. Otherwise, return all the selected bundles.
  $bundles = [];
  $entity_bundles = $this
    ->getEntityBundles();
  $selected_bundles = array_flip($configuration['bundles']['selected']);
  $function = $configuration['bundles']['default'] ? 'array_diff_key' : 'array_intersect_key';
  $entity_bundles = $function($entity_bundles, $selected_bundles);
  foreach ($entity_bundles as $bundle_id => $bundle_info) {
    $bundles[$bundle_id] = $bundle_info['label'] ?? $bundle_id;
  }
  return $bundles ?: [
    $this
      ->getEntityTypeId() => $this
      ->label(),
  ];
}