You are here

public function WebformGroupManager::getWebformSubmissionGroupContent in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_group/src/WebformGroupManager.php \Drupal\webform_group\WebformGroupManager::getWebformSubmissionGroupContent()

Get group content for a webform submission.

Parameters

\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.

Return value

\Drupal\group\Entity\GroupContentInterface|bool The group content for the webform submission. FALSE if no group roles is found for the webform submission.

Overrides WebformGroupManagerInterface::getWebformSubmissionGroupContent

1 call to WebformGroupManager::getWebformSubmissionGroupContent()
WebformGroupManager::getWebformSubmissionUserGroupRoles in modules/webform_group/src/WebformGroupManager.php
Get group roles for a webform submission and a specified user account.

File

modules/webform_group/src/WebformGroupManager.php, line 197

Class

WebformGroupManager
Webform group manager manager.

Namespace

Drupal\webform_group

Code

public function getWebformSubmissionGroupContent(WebformSubmissionInterface $webform_submission) {
  $source_entity = $webform_submission
    ->getSourceEntity();
  if (!$source_entity) {
    return NULL;
  }

  /** @var \Drupal\group\Entity\Storage\GroupContentStorageInterface $group_content_storage */
  $group_content_storage = $this->entityTypeManager
    ->getStorage('group_content');

  // Get group content id for the source entity.
  $group_content_ids = $group_content_storage
    ->getQuery()
    ->condition('entity_id', $source_entity
    ->id())
    ->execute();

  /** @var \Drupal\group\Entity\GroupContentInterface[] $group_contents */
  $group_contents = $group_content_storage
    ->loadMultiple($group_content_ids);
  foreach ($group_contents as $group_content) {
    $group_content_entity = $group_content
      ->getEntity();
    if ($group_content_entity
      ->getEntityTypeId() === $source_entity
      ->getEntityTypeId() && $group_content_entity
      ->id() === $source_entity
      ->id()) {
      return $group_content;
    }
  }
  return NULL;
}