You are here

public function GroupContentStorage::loadByGroup in Group 8

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

Retrieves all GroupContent entities for a group.

Parameters

\Drupal\group\Entity\GroupInterface $group: The group entity to load the group content entities for.

string $plugin_id: (optional) A content enabler plugin ID to filter on.

array $filters: (optional) An associative array of extra filters where the keys are property or field names and the values are the value to filter on.

Return value

\Drupal\group\Entity\GroupContentInterface[] A list of GroupContent entities matching the criteria.

Overrides GroupContentStorageInterface::loadByGroup

File

src/Entity/Storage/GroupContentStorage.php, line 67

Class

GroupContentStorage
Defines the storage handler class for group content entities.

Namespace

Drupal\group\Entity\Storage

Code

public function loadByGroup(GroupInterface $group, $plugin_id = NULL, $filters = []) {

  // An unsaved group cannot have any content.
  if ($group
    ->id() === NULL) {
    throw new EntityStorageException("Cannot load GroupContent entities for an unsaved group.");
  }
  $properties = [
    'gid' => $group
      ->id(),
  ] + $filters;

  // If a plugin ID was provided, set the group content type ID for it.
  if (isset($plugin_id)) {

    /** @var \Drupal\group\Plugin\GroupContentEnablerInterface $plugin */
    $plugin = $group
      ->getGroupType()
      ->getContentPlugin($plugin_id);
    $properties['type'] = $plugin
      ->getContentTypeConfigId();
  }
  return $this
    ->loadByProperties($properties);
}