@param RoleInterface $role

@return $this
760889
public function addBelongTo(RoleInterface $role)
    {
        $name = $role->getType();
        $id = $role->getId();

        if (!isset($this->belongTo[$name][$id])) {
            if (!isset($this->belongTo[$name])) {
                $this->belongTo[$name] = [];
            }

            $this->belongTo[$name][$id] = $role;
        }

        return $this;
    }
1021549
public function remove(Role $role)
    {
        if ($role->isReadOnly()) {
            throw new RoleReadOnlyException('This role cannot be removed');
        }

        $this->om->remove($role);
        $this->om->flush();
    }
862732
public function validateRole($role)
    {
        $roleValidator = new RoleValidator();
        $response = $roleValidator->validate($role);

        if (!$response) {
            $this->addError('role', 'Role must be a valid instance of Role class - ' . $roleValidator->getErrorsAsString());
        }

        return $response;
    }
149639
protected function addRoles(FacadeInterface $facade, GroupInterface $group)
    {
        if ($this->hasGroup(CMSGroupContext::GROUP_ROLES)) {
            foreach ($group->getRoles() as $role) {
                $facade->addRole($role);
            }
        }

        return $facade;
    }
971907
public function addRole($roleName)
    {
        if (true === is_string($roleName) && false === in_array($roleName, $this->roles)) {
            $this->roles[] = $roleName;
        }
        return $this;
    }
967621
public function addSetting(RoleSettingInterface $setting)
    {
        $this->settings->set($setting->getKey(), $setting);

        return $this;
    }
10828
protected function convertRole(RoleInterface $role)
    {
        $roleData['id'] = $role->getId();
        $roleData['name'] = $role->getName();
        $roleData['identifier'] = $role->getIdentifier();
        $roleData['system'] = $role->getSystem();
        $roleData['permissions'] = [];

        $permissions = $role->getPermissions();
        if (!empty($permissions)) {
            foreach ($permissions as $permission) {
                /* @var Permission $permission */
                $roleData['permissions'][] = [
                    'id' => $permission->getId(),
                    'context' => $permission->getContext(),
                    'module' => $permission->getModule(),
                    'permissions' => $this->get('sulu_security.mask_converter')
                        ->convertPermissionsToArray($permission->getPermissions()),
                ];
            }
        }

        $securityType = $role->getSecurityType();
        if ($securityType) {
            $roleData['securityType'] = [
                'id' => $securityType->getId(),
                'name' => $securityType->getName(),
            ];
        }

        return $roleData;
    }
72554
public function intersect(RolesStorageInterface $roles)
    {
        $res = array_intersect($roles->getArrayCopy(), $this->getArrayCopy());
        return (!empty($res));
    }
29133
public function removeRole($role)
    {
        $role = strtoupper($role);

        $roles = $this->roles;

        if (in_array($role, $roles)) {
            $remove[]    = $role;
            $this->roles = array_diff($roles, $remove);
        }

        return $this;
    }
272953
public function initializeRoleLimitAction(Role $role)
    {
        $this->roleManager->initializeLimit($role);

        return new JsonResponse(
            array(
                'name' => $role->getName(),
                'limit' => $role->getMaxUsers(),
                'translationKey' => $role->getTranslationKey()
            )
        );
    }
878913
public static function fromAccount($role)
    {
        return $role instanceof RoleInterface
            ? new self(ClassUtils::getClass($role), $role->getName())
            : new self('role', $role);
    }
1268755
public function assignRole(...$roles)
    {
        $roles = collect($roles)
            ->flatten()
            ->map(function ($role) {
                return $this->getStoredRole($role);
            })
            ->each(function ($role) {
                $this->ensureModelSharesGuard($role);
            })
            ->all();

        $this->roles()->saveMany($roles);

        $this->forgetCachedPermissions();

        return $this;
    }
895177
private function collectPermissions(RoleInterface $role)
    {
        if (method_exists($role, 'getPermissions')) {
            $permissions = $role->getPermissions();
        } else {
            // Gather the permissions for the given role. We have to use reflection as
            // the RoleInterface does not have "getPermissions" method
            $reflectionProperty = new ReflectionProperty($role, 'permissions');
            $reflectionProperty->setAccessible(true);

            $permissions = $reflectionProperty->getValue($role);
        }

        if ($permissions instanceof Traversable) {
            $permissions = iterator_to_array($permissions);
        }

        array_walk($permissions, function (&$permission) {
            $permission = (string) $permission;
        });

        $this->collectedPermissions[$role->getName()] = array_values($permissions);
    }
1033857
public function setRole(Role $v = null)
    {
        if ($v === null) {
            $this->setRoleId(NULL);
        } else {
            $this->setRoleId($v->getId());
        }

        $this->aRole = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the Role object, it will not be re-added.
        if ($v !== null) {
            $v->addUserRole($this);
        }


        return $this;
    }
556282
public function addSingleRole($role)
    {
        if (is_string($role))
            return $this->addRoleByName($role);
        elseif (is_numeric($role))
            return $this->addRoleById($role);
        elseif ($role instanceof BridgeRole)
            return $this->addRoleByObject($role);
        else
            throw new \InvalidArgumentException('Role must be a name, ID, or Role object.');
    }
433286
public static function roleRelationship(RuleInterface $next = null): RuleInterface
    {
        return self::toOneRelationship(RoleSchema::TYPE, static::roleId($next));
    }
371774
public function addRole(Role $role)
    {
        try {
            $this->saveEntity($role);
        } catch (UniqueConstraintViolationException $e) {
            throw new NotUniqueException('Role with name ' . $role->getName() . ' already created');
        }
    }