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;
    }
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;
    }
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 ; }
Validate that assignments not already exists and filter validations against existing.

@param mixed $contentId
@param SPIRole $spiRole
@param array|null $limitation

@return array[]|null Filtered version of $limitation

@throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If assignment already exists
Validate that assignments not already exists and filter validations against existing .