You are here

public function WorkspacePointerSelection::getReferenceableEntities in Workspace 8

Gets the list of referenceable entities.

Return value

array A nested array of entities, the first level is keyed by the entity bundle, which contains an array of entity labels (escaped), keyed by the entity ID.

Overrides DefaultSelection::getReferenceableEntities

File

src/Plugin/EntityReferenceSelection/WorkspacePointerSelection.php, line 39

Class

WorkspacePointerSelection
Provides specific access control for the node entity type.

Namespace

Drupal\workspace\Plugin\EntityReferenceSelection

Code

public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
  $target_type = $this
    ->getConfiguration()['target_type'];
  $query = $this
    ->buildEntityQuery($match, $match_operator);
  if ($limit > 0) {
    $query
      ->range(0, $limit);
  }
  $result = $query
    ->execute();
  if (empty($result)) {
    return [];
  }
  $options = [];
  $entities = $this->entityManager
    ->getStorage($target_type)
    ->loadMultiple($result);
  foreach ($entities as $entity_id => $entity) {

    /** @var WorkspaceInterface $workspace */
    if ($workspace = $entity
      ->getWorkspace()) {
      if (!$workspace
        ->isPublished() || $workspace
        ->getQueuedForDelete()) {
        continue;
      }
    }
    $bundle = $entity
      ->bundle();
    $options[$bundle][$entity_id] = Html::escape($this->entityManager
      ->getTranslationFromContext($entity)
      ->label());
  }
  return $options;
}