Exemplo n.º 1
0
 /**
  * Save a user view/edit form data.
  *
  * @param Storage\Entity\Account $account
  * @param Form                   $form
  *
  * @return FormEntityHandler
  */
 public function saveProfileForm(Storage\Entity\Account $account, Form $form)
 {
     $guid = $account->getId();
     if ($guid === null) {
         throw new \RuntimeException('GUID not set.');
     }
     $account->setDisplayname($form->get('displayname')->getData());
     $account->setEmail($form->get('email')->getData());
     // Dispatch the account profile pre-save event
     $event = new MembersProfileEvent($account);
     $this->eventDispatcher->dispatch(MembersEvents::MEMBER_PROFILE_PRE_SAVE, $event);
     $this->records->saveAccount($account);
     $password = $form->get('password')->getData();
     if ($password !== null) {
         $oauth = $this->getOauth($guid);
         if ($oauth === false) {
             $oauth = $this->createLocalOauthAccount($guid, $password);
             $this->createLocalProviderEntity($guid);
         }
         $oauth->setPassword($password);
         $this->records->saveOauth($oauth);
     }
     // Save any defined meta fields
     foreach ($event->getMetaEntityNames() as $metaField) {
         $metaEntity = $this->records->getAccountMeta($guid, $metaField);
         if ($metaEntity === false) {
             $metaEntity = new Storage\Entity\AccountMeta();
         }
         $metaEntity->setGuid($guid);
         $metaEntity->setMeta($metaField);
         $metaEntity->setValue($form->get($metaField)->getData());
         $this->records->saveAccountMeta($metaEntity);
         $event->addMetaEntity($metaEntity);
     }
     // Dispatch the account profile post-save event
     $this->eventDispatcher->dispatch(MembersEvents::MEMBER_PROFILE_POST_SAVE, $event);
     return $this;
 }