Differential D14945 Diff 36121 src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionRepositorySymbolsController.php
<?php | <?php | ||||
final class DiffusionRepositorySymbolsController | final class DiffusionRepositorySymbolsController | ||||
extends DiffusionRepositoryEditController { | extends DiffusionRepositoryEditController { | ||||
protected function processDiffusionRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$user = $request->getUser(); | $response = $this->loadDiffusionContextForEdit(); | ||||
$drequest = $this->diffusionRequest; | if ($response) { | ||||
$repository = $drequest->getRepository(); | return $response; | ||||
$repository = id(new PhabricatorRepositoryQuery()) | |||||
->setViewer($user) | |||||
->requireCapabilities( | |||||
array( | |||||
PhabricatorPolicyCapability::CAN_VIEW, | |||||
PhabricatorPolicyCapability::CAN_EDIT, | |||||
)) | |||||
->withIDs(array($repository->getID())) | |||||
->executeOne(); | |||||
if (!$repository) { | |||||
return new Aphront404Response(); | |||||
} | } | ||||
$viewer = $this->getViewer(); | |||||
$drequest = $this->getDiffusionRequest(); | |||||
$repository = $drequest->getRepository(); | |||||
$edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | $edit_uri = $this->getRepositoryControllerURI($repository, 'edit/'); | ||||
$v_sources = $repository->getSymbolSources(); | $v_sources = $repository->getSymbolSources(); | ||||
$v_languages = $repository->getSymbolLanguages(); | $v_languages = $repository->getSymbolLanguages(); | ||||
if ($v_languages) { | if ($v_languages) { | ||||
$v_languages = implode(', ', $v_languages); | $v_languages = implode(', ', $v_languages); | ||||
} | } | ||||
$errors = array(); | $errors = array(); | ||||
Show All 17 Lines | if ($request->isFormPost()) { | ||||
$xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
->setTransactionType($type_lang) | ->setTransactionType($type_lang) | ||||
->setNewValue($v_languages); | ->setNewValue($v_languages); | ||||
try { | try { | ||||
id(new PhabricatorRepositoryEditor()) | id(new PhabricatorRepositoryEditor()) | ||||
->setContinueOnNoEffect(true) | ->setContinueOnNoEffect(true) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setActor($user) | ->setActor($viewer) | ||||
->applyTransactions($repository, $xactions); | ->applyTransactions($repository, $xactions); | ||||
return id(new AphrontRedirectResponse())->setURI($edit_uri); | return id(new AphrontRedirectResponse())->setURI($edit_uri); | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { | ||||
$errors[] = $ex->getMessage(); | $errors[] = $ex->getMessage(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb(pht('Edit Symbols')); | $crumbs->addTextCrumb(pht('Edit Symbols')); | ||||
$title = pht('Edit %s', $repository->getName()); | $title = pht('Edit %s', $repository->getName()); | ||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setUser($viewer) | ||||
->appendRemarkupInstructions($this->getInstructions()) | ->appendRemarkupInstructions($this->getInstructions()) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('languages') | ->setName('languages') | ||||
->setLabel(pht('Indexed Languages')) | ->setLabel(pht('Indexed Languages')) | ||||
->setCaption(pht( | ->setCaption(pht( | ||||
'File extensions, separate with commas, for example: php, py. '. | 'File extensions, separate with commas, for example: php, py. '. | ||||
'Leave blank for "any".')) | 'Leave blank for "any".')) | ||||
Show All 11 Lines | $form = id(new AphrontFormView()) | ||||
->setValue(pht('Save')) | ->setValue(pht('Save')) | ||||
->addCancelButton($edit_uri)); | ->addCancelButton($edit_uri)); | ||||
$object_box = id(new PHUIObjectBoxView()) | $object_box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText($title) | ->setHeaderText($title) | ||||
->setForm($form) | ->setForm($form) | ||||
->setFormErrors($errors); | ->setFormErrors($errors); | ||||
return $this->buildApplicationPage( | return $this->newPage() | ||||
array( | ->setTitle($title) | ||||
$crumbs, | ->setCrumbs($crumbs) | ||||
$object_box, | ->appendChild($object_box); | ||||
), | |||||
array( | |||||
'title' => $title, | |||||
)); | |||||
} | } | ||||
private function getInstructions() { | private function getInstructions() { | ||||
return pht(<<<EOT | return pht(<<<EOT | ||||
Configure Symbols for this repository. | Configure Symbols for this repository. | ||||
See [[%s | Symbol Indexes]] for more information on using symbols. | See [[%s | Symbol Indexes]] for more information on using symbols. | ||||
EOT | EOT | ||||
, | , | ||||
PhabricatorEnv::getDoclink( | PhabricatorEnv::getDoclink( | ||||
'Diffusion User Guide: Symbol Indexes')); | 'Diffusion User Guide: Symbol Indexes')); | ||||
} | } | ||||
} | } |