function RefinableCalculatedPermissions::mergeItems

Same name in other branches
  1. 10 core/lib/Drupal/Core/Session/RefinableCalculatedPermissions.php \Drupal\Core\Session\RefinableCalculatedPermissions::mergeItems()

Merges two items of identical scope and identifier.

Parameters

\Drupal\Core\Session\CalculatedPermissionsItemInterface $a: The first item to merge.

\Drupal\Core\Session\CalculatedPermissionsItemInterface $b: The second item to merge.

Return value

\Drupal\Core\Session\CalculatedPermissionsItemInterface A new item representing the merger of both items.

1 call to RefinableCalculatedPermissions::mergeItems()
RefinableCalculatedPermissions::addItem in core/lib/Drupal/Core/Session/RefinableCalculatedPermissions.php
Adds a calculated permission item.

File

core/lib/Drupal/Core/Session/RefinableCalculatedPermissions.php, line 74

Class

RefinableCalculatedPermissions
Represents a calculated set of permissions with cacheable metadata.

Namespace

Drupal\Core\Session

Code

protected static function mergeItems(CalculatedPermissionsItemInterface $a, CalculatedPermissionsItemInterface $b) : CalculatedPermissionsItemInterface {
    // If either of the items is admin, the new one is too.
    $is_admin = $a->isAdmin() || $b->isAdmin();
    // Admin items don't need to have any permissions.
    $permissions = [];
    if (!$is_admin) {
        $permissions = array_unique(array_merge($a->getPermissions(), $b->getPermissions()));
    }
    return new CalculatedPermissionsItem($permissions, $is_admin, $a->getScope(), $a->getIdentifier());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.