Path: blob/master/src/applications/almanac/controller/AlmanacPropertyEditController.php
12256 views
<?php12final class AlmanacPropertyEditController3extends AlmanacPropertyController {45public function handleRequest(AphrontRequest $request) {6$viewer = $request->getViewer();78$response = $this->loadPropertyObject();9if ($response) {10return $response;11}1213$object = $this->getPropertyObject();1415$cancel_uri = $object->getURI();16$property_key = $request->getStr('key');1718if (!phutil_nonempty_string($property_key)) {19return $this->buildPropertyKeyResponse($cancel_uri, null);20} else {21$error = null;22try {23AlmanacNames::validateName($property_key);24} catch (Exception $ex) {25$error = $ex->getMessage();26}2728// NOTE: If you enter an existing name, we're just treating it as an29// edit operation. This might be a little confusing.3031if ($error !== null) {32if ($request->isFormPost()) {33// The user is creating a new property and picked a bad name. Give34// them an opportunity to fix it.35return $this->buildPropertyKeyResponse($cancel_uri, $error);36} else {37// The user is editing an invalid property.38return $this->newDialog()39->setTitle(pht('Invalid Property'))40->appendParagraph(41pht(42'The property name "%s" is invalid. This property can not '.43'be edited.',44$property_key))45->appendParagraph($error)46->addCancelButton($cancel_uri);47}48}49}5051return $object->newAlmanacPropertyEditEngine()52->addContextParameter('objectPHID')53->addContextParameter('key')54->setTargetObject($object)55->setPropertyKey($property_key)56->setController($this)57->buildResponse();58}5960private function buildPropertyKeyResponse($cancel_uri, $error) {61$viewer = $this->getViewer();62$request = $this->getRequest();63$v_key = $request->getStr('key');6465if ($error !== null) {66$e_key = pht('Invalid');67} else {68$e_key = true;69}7071$form = id(new AphrontFormView())72->setUser($viewer)73->appendChild(74id(new AphrontFormTextControl())75->setName('key')76->setLabel(pht('Name'))77->setValue($v_key)78->setError($e_key));7980$errors = array();81if ($error !== null) {82$errors[] = $error;83}8485return $this->newDialog()86->setTitle(pht('Add Property'))87->addHiddenInput('objectPHID', $request->getStr('objectPHID'))88->setErrors($errors)89->appendForm($form)90->addSubmitButton(pht('Continue'))91->addCancelButton($cancel_uri);92}9394}959697