protected function getValidationExceptionShortMessage(PhabricatorApplicationTransactionValidationException $ex, PhabricatorEditField $field)
 {
     // Settings fields all have the same transaction type so we need to make
     // sure the transaction is changing the same setting before matching an
     // error to a given field.
     $xaction_type = $field->getTransactionType();
     if ($xaction_type == PhabricatorUserPreferencesTransaction::TYPE_SETTING) {
         $property = PhabricatorUserPreferencesTransaction::PROPERTY_SETTING;
         $field_setting = idx($field->getMetadata(), $property);
         foreach ($ex->getErrors() as $error) {
             if ($error->getType() !== $xaction_type) {
                 continue;
             }
             $xaction = $error->getTransaction();
             if (!$xaction) {
                 continue;
             }
             $xaction_setting = $xaction->getMetadataValue($property);
             if ($xaction_setting != $field_setting) {
                 continue;
             }
             $short_message = $error->getShortMessage();
             if ($short_message !== null) {
                 return $short_message;
             }
         }
         return null;
     }
     return parent::getValidationExceptionShortMessage($ex, $field);
 }
 /**
  * Code to create a form to edit the @{class:NuanceItem} you are defining.
  *
  * return @{class:AphrontFormView}
  */
 private function renderEditForm(PhabricatorApplicationTransactionValidationException $ex = null)
 {
     $user = $this->requireActor();
     $source = $this->requireSourceObject();
     $policies = $this->loadSourceObjectPolicies($user, $source);
     $e_name = null;
     if ($ex) {
         $e_name = $ex->getShortMessage(NuanceSourceTransaction::TYPE_NAME);
     }
     $form = id(new AphrontFormView())->setUser($user)->appendChild(id(new AphrontFormTextControl())->setLabel(pht('Name'))->setName('name')->setError($e_name)->setValue($source->getName()));
     $form = $this->augmentEditForm($form, $ex);
     $form->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setCapability(PhabricatorPolicyCapability::CAN_VIEW)->setPolicyObject($source)->setPolicies($policies)->setName('viewPolicy'))->appendChild(id(new AphrontFormPolicyControl())->setUser($user)->setCapability(PhabricatorPolicyCapability::CAN_EDIT)->setPolicyObject($source)->setPolicies($policies)->setName('editPolicy'))->appendChild(id(new AphrontFormSubmitControl())->addCancelButton($source->getURI())->setValue(pht('Save')));
     return $form;
 }
 protected function getValidationExceptionShortMessage(PhabricatorApplicationTransactionValidationException $ex, PhabricatorEditField $field)
 {
     $xaction_type = $field->getTransactionType();
     if ($xaction_type === null) {
         return null;
     }
     return $ex->getShortMessage($xaction_type);
 }