Maps a ValueObject from eZ content repository to a data usable as underlying form data
(e.g. create/update struct).

@param ValueObject|\eZ\Publish\API\Repository\Values\User\RoleDraft $role
@param array $params

@return RoleData
166602
public function mapToFormData(ValueObject $roleDraft, array $params = [])
    {
        $roleData = new RoleData(['roleDraft' => $roleDraft]);
        if (!$roleData->isNew()) {
            $roleData->identifier = $roleDraft->identifier;
        }

        return $roleData;
    }
654458
public function setRole($role)
    {
        $allowed_values = array('fleet_commander', 'wing_commander', 'squad_commander', 'squad_member');
        if ((!in_array($role, $allowed_values))) {
            throw new \InvalidArgumentException("Invalid value for 'role', must be one of 'fleet_commander', 'wing_commander', 'squad_commander', 'squad_member'");
        }
        $this->container['role'] = $role;

        return $this;
    }
637397
final protected function addRole(object $data, AbstractRole $role): BoundedRoleInterface
    {
        return new class ($role, $data) implements BoundedRoleInterface
        {
            use DelegatorTrait;

            public function __construct(AbstractRole $role, object $data)
            {
                if (false === $role->supports($data)) {
                    throw new InvalidArgumentException(
                        sprintf(
                            'Role "%s" does not support for current data',
                            get_class($role)
                        )
                    );
                }

                $this->attach($this->invoke($role, 'attach', $data));
            }

            /**
             * Extract data from bounded roles.
             *
             * @return object
             */
            public function extract(): object
            {
                return $this->invoke($this->getInstance(), 'extract');
            }

            /**
             * Invoke closure method from role.
             *
             * @param AbstractRole $role
             * @param string       $method
             * @param array        ...$args
             *
             * @return mixed
             */
            private function invoke(AbstractRole $role, string $method, ...$args)
            {
                $method = new ReflectionMethod(get_class($role), $method);
                $method->setAccessible(true);

                return $method->invoke($role, ...$args);
            }
        };
    }
751155
public function import(Role $role, ImportRecordsDataTable $importRecordsDataTable)
    {
        return $importRecordsDataTable->with([
            'resource' => $role,
            'tabs' => 'managerarea.roles.tabs',
            'url' => route('managerarea.roles.stash'),
            'id' => "managerarea-roles-{$role->getRouteKey()}-import-table",
        ])->render('cortex/foundation::managerarea.pages.datatable-dropzone');
    }
580170
public function setRoleType($roleType)
    {
        $allowedValues = $this->getRoleTypeAllowableValues();
        if (!in_array($roleType, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'roleType', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['roleType'] = $roleType;

        return $this;
    }
1078139
public function role_mappings($rolemappings, $roles) {
        $roles[0] = get_string('none');
        $output  = html_writer::start_tag('div', array('class' => 'restore-rolemappings'));
        $output .= $this->output->heading(get_string('restorerolemappings', 'backup'), 2);
        foreach ($rolemappings as $id => $mapping) {
            $label = $mapping->name;
            $name = 'mapping'.$id;
            $selected = $mapping->targetroleid;
            $output .= $this->backup_detail_select($label, $name, $roles, $mapping->targetroleid, false, array(), $mapping->description);
        }
        $output .= html_writer::end_tag('div');
        return $output;
    }
1123857
public function addDatabaseReaderRole($role)
	{
		if (strlen($role) < 1) {
			throw new InvalidArgumentException("Role can't be empty");
		}
		$sec = $this->getSecurity();
		if (in_array($role, $sec->readers->roles)) {
			return true;
		}
		array_push($sec->readers->roles, $role);
		$back = $this->setSecurity($sec);
		if (is_object($back) && property_exists($back, "ok") && $back->ok == true) {
			return true;
		}
		return false;
	}
500990
public function createRole(Role $role)
    {
        $url = self::makeUrl($role->tenantId, $role->name);
        $this->service->prepAndSend($url, array(201, 200), 'PUT', json_encode($role), false, 'application/json', 'application/json');
    }
364777
public function createUserWithRoles(array $roles = ['authenticated'], $password = FALSE) {
    $faker = Faker::create();
    /** @var \Drupal\user\Entity\User $user */
    $user = User::create([
      'name' => $faker->userName,
      'mail' => $faker->email,
      'roles' => $roles,
      'pass' => $password ? $password : $faker->password(12, 14),
      'status' => 1,
    ]);

    $user->save();

    $this->users[] = $user->id();

    return $user;
  }
458079
public function updateRole($projectId, $roleId, $user = null, $group = null)
    {
        $parameters = [];
        if ((is_null($user) && is_null($group)) || (!is_null($user) && !is_null($group))) {
            throw new EndpointParameterException('User or group should be given');
        } elseif (!is_null($user)) {
            $parameters['user'] = $user;
        } else {
            $parameters['group'] = $group;
        }

        return $this->apiClient->callEndpoint(
            sprintf('%s/%s/role/%s', self::ENDPOINT, $projectId, $roleId),
            $parameters,
            null,
            HttpMethod::REQUEST_PUT
        );
    }
380966
public function update(Role $role, UpdateRole $request)
    {
        try {
            $role->update($request->except('permissions'));
            $role->syncPermissions($request->permissions());

            flash()->success(__('The :name role has been updated', ['name' => $role->name]));
        } catch (\Exception $e) {
            flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
            return redirect()->back();
        }

        return redirect(route('appshell.role.show', $role));
    }
327095
public function map(ValueObject $value): RoleCreateData
    {
        if (!$value instanceof RoleCreateStruct) {
            throw new InvalidArgumentException('value', 'must be an instance of ' . RoleCreateStruct::class);
        }

        $data = new RoleCreateData();

        $data->setIdentifier($value->identifier);

        return $data;
    }
1161907
public function createCreateStructFromRole(Role $role)
    {
        $createStruct = new RoleCreateStruct();

        $createStruct->identifier = $role->identifier;
        $createStruct->policies = $role->policies;

        return $createStruct;
    }
432851
public function prepareRoleCollection (array $roles)
    {
        $roleCollection = [];
        $roleHelper = new RoleNameHelper();

        foreach ($roles as $role => $configuration)
        {
            try
            {
                // normalize role name
                $roleName = $roleHelper->normalizeRoleName($role);

                // check for duplicate role definitions
                if (array_key_exists($roleName, $roleCollection))
                {
                    $addition = ($roleName !== $role) ? " (normalized from “{$role}”)" : "";
                    throw new DuplicateRoleDefinitionException("The role “{$roleName}”{$addition} has multiple definitions. Keep in mind that all role names are normalized to a common “ROLE_…” format.");
                }

                $roleCollection[$roleName] = $configuration;
            }
            catch (\InvalidArgumentException $e)
            {
                throw new EmptyRoleNameException("Role name could not be normalized: {$e->getMessage()}.", 0, $e);
            }
        }

        return $this->prepareIncludedRoles($roleCollection);
    }
618082
public function addRoleByName($role_name)
    {
        $role = static::$app['db']->connection()
            ->table('roles')->where('name', '=', $role_name)->first();

        if (! $role)
            throw new \RuntimeException('No role with that name found.');

        if (is_array($role))
            return $this->addRoleById($role['id']);
        elseif (is_object($role))
            return $this->addRoleById($role->id);
        else
            throw new \UnexpectedValueException('Value returned not array or instance of BridgeRole.');
    }
309872
public function setRoleToRoleSubject(AbstractRoleSubject $ars, $roleName, $validate = true)
    {
        $role = $this->roleRepo->findOneBy(['name' => $roleName]);

        if ($validate) {
            $validated = $this->validateRoleInsert($ars, $role);
        } else {
            $validated = true;
        }

        if (!$validated) {
            throw new Exception\AddRoleException();
        }

        if ('Claroline\CoreBundle\Entity\Group' === get_class($ars) && 'ROLE_USER' === $role->getName()) {
            throw new Exception\AddRoleException('ROLE_USER cannot be added to groups');
        }

        if (!is_null($role)) {
            $ars->addRole($role);
            $this->om->persist($ars);
            $this->om->flush();
        }
    }
1363000
public function updateRole(
        RoleUpdateData $data,
        ?string $name = null
    ): FormInterface {
        $name = $name ?: sprintf('update-role-%d', $data->getRole()->id);

        return $this->formFactory->createNamed($name, RoleUpdateType::class, $data);
    }