[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorStandardCustomFieldCredential 4 extends PhabricatorStandardCustomField { 5 6 public function getFieldType() { 7 return 'credential'; 8 } 9 10 public function buildFieldIndexes() { 11 $indexes = array(); 12 13 $value = $this->getFieldValue(); 14 if (strlen($value)) { 15 $indexes[] = $this->newStringIndex($value); 16 } 17 18 return $indexes; 19 } 20 21 public function renderEditControl(array $handles) { 22 $provides_type = $this->getFieldConfigValue('credential.provides'); 23 $credential_type = $this->getFieldConfigValue('credential.type'); 24 25 $all_types = PassphraseCredentialType::getAllProvidesTypes(); 26 if (!in_array($provides_type, $all_types)) { 27 $provides_type = PassphraseCredentialTypePassword::PROVIDES_TYPE; 28 } 29 30 $credentials = id(new PassphraseCredentialQuery()) 31 ->setViewer($this->getViewer()) 32 ->withIsDestroyed(false) 33 ->withProvidesTypes(array($provides_type)) 34 ->execute(); 35 36 return id(new PassphraseCredentialControl()) 37 ->setLabel($this->getFieldName()) 38 ->setName($this->getFieldKey()) 39 ->setCaption($this->getCaption()) 40 ->setAllowNull(!$this->getRequired()) 41 ->setCredentialType($credential_type) 42 ->setValue($this->getFieldValue()) 43 ->setError($this->getFieldError()) 44 ->setOptions($credentials); 45 } 46 47 public function getRequiredHandlePHIDsForPropertyView() { 48 $value = $this->getFieldValue(); 49 if ($value) { 50 return array($value); 51 } 52 return array(); 53 } 54 55 public function renderPropertyViewValue(array $handles) { 56 $value = $this->getFieldValue(); 57 if ($value) { 58 return $handles[$value]->renderLink(); 59 } 60 return null; 61 } 62 63 public function validateApplicationTransactions( 64 PhabricatorApplicationTransactionEditor $editor, 65 $type, 66 array $xactions) { 67 68 $errors = parent::validateApplicationTransactions( 69 $editor, 70 $type, 71 $xactions); 72 73 $ok = PassphraseCredentialControl::validateTransactions( 74 $this->getViewer(), 75 $xactions); 76 77 if (!$ok) { 78 foreach ($xactions as $xaction) { 79 $errors[] = new PhabricatorApplicationTransactionValidationError( 80 $type, 81 pht('Invalid'), 82 pht( 83 'The selected credential does not exist, or you do not have '. 84 'permission to use it.'), 85 $xaction); 86 $this->setFieldError(pht('Invalid')); 87 } 88 } 89 90 return $errors; 91 } 92 93 public function getApplicationTransactionRequiredHandlePHIDs( 94 PhabricatorApplicationTransaction $xaction) { 95 $phids = array(); 96 $old = $xaction->getOldValue(); 97 $new = $xaction->getNewValue(); 98 if ($old) { 99 $phids[] = $old; 100 } 101 if ($new) { 102 $phids[] = $new; 103 } 104 return $phids; 105 } 106 107 108 public function getApplicationTransactionTitle( 109 PhabricatorApplicationTransaction $xaction) { 110 $author_phid = $xaction->getAuthorPHID(); 111 112 $old = $xaction->getOldValue(); 113 $new = $xaction->getNewValue(); 114 115 if ($old && !$new) { 116 return pht( 117 '%s removed %s as %s.', 118 $xaction->renderHandleLink($author_phid), 119 $xaction->renderHandleLink($old), 120 $this->getFieldName()); 121 } else if ($new && !$old) { 122 return pht( 123 '%s set %s to %s.', 124 $xaction->renderHandleLink($author_phid), 125 $this->getFieldName(), 126 $xaction->renderHandleLink($new)); 127 } else { 128 return pht( 129 '%s changed %s from %s to %s.', 130 $xaction->renderHandleLink($author_phid), 131 $this->getFieldName(), 132 $xaction->renderHandleLink($old), 133 $xaction->renderHandleLink($new)); 134 } 135 } 136 137 138 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |