src/Sulu/Bundle/SecurityBundle/Controller/ProfileController.php
public function patchSettingsAction(Request $request)
    {
        $settings = $request->request->all();

        try {
            $user = $this->tokenStorage->getToken()->getUser();

            foreach ($settings as $settingKey => $settingValue) {
                // get setting
                // TODO: move this logic into own service (UserSettingManager?)
                $setting = $this->userSettingRepository->findOneBy(['user' => $user, 'key' => $settingKey]);

                // or create new one
                if (!$setting) {
                    $setting = new UserSetting();
                    $setting->setKey($settingKey);
                    $setting->setUser($user);
                    $this->objectManager->persist($setting);
                }

                // persist setting
                $setting->setValue(json_encode($settingValue));
            }
            $this->objectManager->flush();

            //create view
            $view = View::create($settings, 200);
        } catch (RestException $exc) {
            $view = View::create($exc->toArray(), 400);
        }

        return $this->viewHandler->handle($view);
    }
public function patchSettingsAction(Request $request)
    {
        $settings = $request->request->all();

        try {
            $user = $this->tokenStorage->getToken()->getUser();

            foreach ($settings as $settingKey => $settingValue) {
                // get setting
                // TODO: move this logic into own service (UserSettingManager?)
                $setting = $this->userSettingRepository->findOneBy(['user' => $user, 'key' => $settingKey]);

                // or create new one
                if (!$setting) {
                    $setting = new UserSetting();
                    $setting->setKey($settingKey);
                    $setting->setUser($user);
                    $this->objectManager->persist($setting);
                }

                // persist setting
                $setting->setValue(json_encode($settingValue));
            }
            $this->objectManager->flush();

            //create view
            $view = View::create($settings, 200);
        } catch (RestException $exc) {
            $view = View::create($exc->toArray(), 400);
        }

        return $this->viewHandler->handle($view);
    }
public function patchSettingsAction ( Request $ request ) { $ settings = $ request -> request -> all ( ) ; try { $ user = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; foreach ( $ settings as $ settingKey => $ settingValue ) { // get setting // TODO: move this logic into own service (UserSettingManager?) $ setting = $ this -> userSettingRepository -> findOneBy ( [ 'user' => $ user , 'key' => $ settingKey ] ) ; // or create new one if ( ! $ setting ) { $ setting = new UserSetting ( ) ; $ setting -> setKey ( $ settingKey ) ; $ setting -> setUser ( $ user ) ; $ this -> objectManager -> persist ( $ setting ) ; } // persist setting $ setting -> setValue ( json_encode ( $ settingValue ) ) ; } $ this -> objectManager -> flush ( ) ; //create view $ view = View :: create ( $ settings , 200 ) ; } catch ( RestException $ exc ) { $ view = View :: create ( $ exc -> toArray ( ) , 400 ) ; } return $ this -> viewHandler -> handle ( $ view ) ; }
Takes a key, value pair and stores it as settings for the user.

@param Request $request

@return Response
Takes a key value pair and stores it as settings for the user .