You are here

public function WebformAccessGroupStorage::loadByEntities in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_access/src/WebformAccessGroupStorage.php \Drupal\webform_access\WebformAccessGroupStorage::loadByEntities()

Load webform access groups by their related entity references.

Parameters

\Drupal\webform\WebformInterface|null $webform: (optional) The webform that the submission token is associated with.

\Drupal\Core\Entity\EntityInterface|null $source_entity: (optional) A webform submission source entity.

\Drupal\Core\Session\AccountInterface|null $account: (optional) A user account.

string $type: (optional) Webform access type.

Return value

\Drupal\webform\WebformSubmissionInterface[] An array of webform access group objects indexed by their ids.

Overrides WebformAccessGroupStorageInterface::loadByEntities

1 call to WebformAccessGroupStorage::loadByEntities()
WebformAccessGroupStorage::getUserEntities in modules/webform_access/src/WebformAccessGroupStorage.php
Get source entities associated with a user account.

File

modules/webform_access/src/WebformAccessGroupStorage.php, line 211

Class

WebformAccessGroupStorage
Storage controller class for "webform_access_group" configuration entities.

Namespace

Drupal\webform_access

Code

public function loadByEntities(WebformInterface $webform = NULL, EntityInterface $source_entity = NULL, AccountInterface $account = NULL, $type = NULL) {
  $query = $this->database
    ->select('webform_access_group_entity', 'ge');
  $query
    ->fields('ge', [
    'group_id',
  ]);

  // Webform.
  if ($webform) {
    $query
      ->condition('webform_id', $webform
      ->id());
  }

  // Source entity.
  if ($source_entity) {
    $query
      ->condition('entity_type', $source_entity
      ->getEntityTypeId());
    $query
      ->condition('entity_id', $source_entity
      ->id());
  }

  // Account.
  if ($account) {
    $query
      ->innerjoin('webform_access_group_user', 'gu', 'ge.group_id = gu.group_id');
    $query
      ->condition('uid', $account
      ->id());
  }

  // Webform access type.
  if ($type) {
    $type_group_ids = $this
      ->getQuery()
      ->condition('type', $type)
      ->accessCheck(FALSE)
      ->execute();
    if (empty($type_group_ids)) {
      return [];
    }
    $query
      ->condition('group_id', $type_group_ids, 'IN');
  }
  $group_ids = $query
    ->execute()
    ->fetchCol();
  return $group_ids ? $this
    ->loadMultiple($group_ids) : [];
}