You are here

protected function RefinableCalculatedGroupPermissions::mergeItems in Group 2.0.x

Same name and namespace in other branches
  1. 8 src/Access/RefinableCalculatedGroupPermissions.php \Drupal\group\Access\RefinableCalculatedGroupPermissions::mergeItems()

Merges two items of identical scope and identifier.

Parameters

\Drupal\group\Access\CalculatedGroupPermissionsItemInterface $a: The first item to merge.

\Drupal\group\Access\CalculatedGroupPermissionsItemInterface $b: The second item to merge.

Return value

\Drupal\group\Access\CalculatedGroupPermissionsItemInterface A new item representing the merger of both items.

Throws

\LogicException Exception thrown when someone somehow manages to call this method with mismatching items.

1 call to RefinableCalculatedGroupPermissions::mergeItems()
RefinableCalculatedGroupPermissions::addItem in src/Access/RefinableCalculatedGroupPermissions.php
Adds a calculated permission item.

File

src/Access/RefinableCalculatedGroupPermissions.php, line 78

Class

RefinableCalculatedGroupPermissions
Represents a calculated set of group permissions with cacheable metadata.

Namespace

Drupal\group\Access

Code

protected function mergeItems(CalculatedGroupPermissionsItemInterface $a, CalculatedGroupPermissionsItemInterface $b) {
  if ($a
    ->getScope() != $b
    ->getScope()) {
    throw new \LogicException('Trying to merge two items of different scopes.');
  }
  if ($a
    ->getIdentifier() != $b
    ->getIdentifier()) {
    throw new \LogicException('Trying to merge two items with different identifiers.');
  }
  $permissions = array_merge($a
    ->getPermissions(), $b
    ->getPermissions());

  // @todo In Group 8.2.x merge isAdmin flags and pass to constructor.
  return new CalculatedGroupPermissionsItem($a
    ->getScope(), $a
    ->getIdentifier(), array_unique($permissions));
}