Creates or updates a preference for a given user.
public setSystemPreference ( string $key, string $value ) : |
||
$key | string | The key to set |
$value | string | The value to set |
return | The user preference |
/** * Retrieves a collection of resources. * * @param Request $request * * @throws \Exception If the format is invalid * @throws RuntimeException|RootNodeNotFoundException * * @return JsonResponse */ public function __invoke(Request $request) { $data = json_decode($request->getContent()); if (property_exists($data, 'preferenceKey') && property_exists($data, 'preferenceValue')) { $preference = $this->systemPreferenceService->setSystemPreference($data->preferenceKey, $data->preferenceValue); } else { throw new \Exception('Invalid format'); } /** * @var ResourceInterface $resourceType */ list($resourceType) = $this->extractAttributes($request); $serializedData = $this->serializer->normalize($preference, 'json', $resourceType->getNormalizationContext()); return new JsonResponse($serializedData); }