[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/people/controller/ -> PhabricatorPeopleProfileEditController.php (source)

   1  <?php
   2  
   3  final class PhabricatorPeopleProfileEditController
   4    extends PhabricatorPeopleController {
   5  
   6    private $id;
   7  
   8    public function shouldRequireAdmin() {
   9      return false;
  10    }
  11  
  12    public function willProcessRequest(array $data) {
  13      $this->id = $data['id'];
  14    }
  15  
  16    public function processRequest() {
  17      $request = $this->getRequest();
  18      $viewer = $request->getUser();
  19  
  20      $user = id(new PhabricatorPeopleQuery())
  21        ->setViewer($viewer)
  22        ->withIDs(array($this->id))
  23        ->requireCapabilities(
  24          array(
  25            PhabricatorPolicyCapability::CAN_VIEW,
  26            PhabricatorPolicyCapability::CAN_EDIT,
  27          ))
  28        ->executeOne();
  29      if (!$user) {
  30        return new Aphront404Response();
  31      }
  32  
  33      $profile_uri = '/p/'.$user->getUsername().'/';
  34  
  35      $field_list = PhabricatorCustomField::getObjectFields(
  36        $user,
  37        PhabricatorCustomField::ROLE_EDIT);
  38      $field_list
  39        ->setViewer($viewer)
  40        ->readFieldsFromStorage($user);
  41  
  42      $validation_exception = null;
  43      if ($request->isFormPost()) {
  44        $xactions = $field_list->buildFieldTransactionsFromRequest(
  45          new PhabricatorUserTransaction(),
  46          $request);
  47  
  48        $editor = id(new PhabricatorUserProfileEditor())
  49          ->setActor($viewer)
  50          ->setContentSource(
  51            PhabricatorContentSource::newFromRequest($request))
  52          ->setContinueOnNoEffect(true);
  53  
  54        try {
  55          $editor->applyTransactions($user, $xactions);
  56          return id(new AphrontRedirectResponse())->setURI($profile_uri);
  57        } catch (PhabricatorApplicationTransactionValidationException $ex) {
  58          $validation_exception = $ex;
  59        }
  60      }
  61  
  62      $title = pht('Edit Profile');
  63      $crumbs = $this->buildApplicationCrumbs();
  64      $crumbs->addTextCrumb($user->getUsername(), $profile_uri);
  65      $crumbs->addTextCrumb($title);
  66  
  67      $form = id(new AphrontFormView())
  68        ->setUser($viewer);
  69  
  70      $field_list->appendFieldsToForm($form);
  71  
  72      $form
  73        ->appendChild(
  74          id(new AphrontFormSubmitControl())
  75            ->addCancelButton($profile_uri)
  76            ->setValue(pht('Save Profile')));
  77  
  78      $form_box = id(new PHUIObjectBoxView())
  79        ->setHeaderText(pht('Edit Profile'))
  80        ->setValidationException($validation_exception)
  81        ->setForm($form);
  82  
  83      return $this->buildApplicationPage(
  84        array(
  85          $crumbs,
  86          $form_box,
  87        ),
  88        array(
  89          'title' => $title,
  90        ));
  91    }
  92  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1