You are here

public function GroupContentTypeStorage::loadByEntityTypeId in Group 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/Storage/GroupContentTypeStorage.php \Drupal\group\Entity\Storage\GroupContentTypeStorage::loadByEntityTypeId()

Retrieves group content types which could serve a given entity type.

Parameters

string $entity_type_id: An entity type ID which may be served by one or more group content types.

Return value

\Drupal\group\Entity\GroupContentTypeInterface[] An array of group content types indexed by their IDs.

Overrides GroupContentTypeStorageInterface::loadByEntityTypeId

File

src/Entity/Storage/GroupContentTypeStorage.php, line 89

Class

GroupContentTypeStorage
Defines the storage handler class for group content type entities.

Namespace

Drupal\group\Entity\Storage

Code

public function loadByEntityTypeId($entity_type_id) {
  $plugin_ids = [];
  if (isset($this->byEntityTypeCache[$entity_type_id])) {
    return $this->byEntityTypeCache[$entity_type_id];
  }

  /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
  foreach ($this->pluginManager
    ->getAll() as $plugin_id => $plugin) {
    if ($plugin
      ->getEntityTypeId() === $entity_type_id) {
      $plugin_ids[] = $plugin_id;
    }
  }

  // If no responsible group content plugins were found, we return nothing.
  if (empty($plugin_ids)) {
    $this->byEntityTypeCache[$entity_type_id] = [];
    return [];
  }

  // Otherwise load all group content types being handled by gathered plugins.
  $this->byEntityTypeCache[$entity_type_id] = $this
    ->loadByContentPluginId($plugin_ids);
  return $this->byEntityTypeCache[$entity_type_id];
}