eZ\Publish\Core\Repository\RoleService::checkAssignmentAndFilterLimitationValues PHP Method

checkAssignmentAndFilterLimitationValues() protected method

Validate that assignments not already exists and filter validations against existing.
protected checkAssignmentAndFilterLimitationValues ( mixed $contentId, eZ\Publish\SPI\Persistence\User\Role $spiRole, array $limitation = null ) : array[] | null
$contentId mixed
$spiRole eZ\Publish\SPI\Persistence\User\Role
$limitation array
return array[] | null Filtered version of $limitation
    protected function checkAssignmentAndFilterLimitationValues($contentId, SPIRole $spiRole, array $limitation = null)
    {
        $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($contentId);
        foreach ($spiRoleAssignments as $spiAssignment) {
            // Ignore assignments to other roles
            if ($spiAssignment->roleId !== $spiRole->id) {
                continue;
            }
            // Throw if Role is already assigned without limitations
            if ($spiAssignment->limitationIdentifier === null) {
                throw new InvalidArgumentException('$role', "Role '{$spiRole->id}' already assigned without limitations");
            }
            // Ignore if we are going to assign without limitations
            if ($limitation === null) {
                continue;
            }
            // Ignore if not assigned with same limitation identifier
            if (!isset($limitation[$spiAssignment->limitationIdentifier])) {
                continue;
            }
            // Throw if Role is already assigned with all the same limitations
            $newValues = array_diff($limitation[$spiAssignment->limitationIdentifier], $spiAssignment->values);
            if (empty($newValues)) {
                throw new InvalidArgumentException('$role', "Role '{$spiRole->id}' already assigned with same '{$spiAssignment->limitationIdentifier}' value");
            }
            // Continue using the filtered list of limitations
            $limitation[$spiAssignment->limitationIdentifier] = $newValues;
        }
        return $limitation;
    }