Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / standard / PhabricatorStandardCustomFieldCredential.php
blobc2f958f228e7c59f6793a720a823ca328d127ea4
1 <?php
3 final class PhabricatorStandardCustomFieldCredential
4 extends PhabricatorStandardCustomField {
6 public function getFieldType() {
7 return 'credential';
10 public function buildFieldIndexes() {
11 $indexes = array();
13 $value = $this->getFieldValue();
14 if (strlen($value)) {
15 $indexes[] = $this->newStringIndex($value);
18 return $indexes;
21 public function renderEditControl(array $handles) {
22 $provides_type = $this->getFieldConfigValue('credential.provides');
23 $credential_type = $this->getFieldConfigValue('credential.type');
25 $all_types = PassphraseCredentialType::getAllProvidesTypes();
26 if (!in_array($provides_type, $all_types)) {
27 $provides_type = PassphrasePasswordCredentialType::PROVIDES_TYPE;
30 $credentials = id(new PassphraseCredentialQuery())
31 ->setViewer($this->getViewer())
32 ->withIsDestroyed(false)
33 ->withProvidesTypes(array($provides_type))
34 ->execute();
36 return id(new PassphraseCredentialControl())
37 ->setViewer($this->getViewer())
38 ->setLabel($this->getFieldName())
39 ->setName($this->getFieldKey())
40 ->setCaption($this->getCaption())
41 ->setAllowNull(!$this->getRequired())
42 ->setCredentialType($credential_type)
43 ->setValue($this->getFieldValue())
44 ->setError($this->getFieldError())
45 ->setOptions($credentials);
48 public function getRequiredHandlePHIDsForPropertyView() {
49 $value = $this->getFieldValue();
50 if ($value) {
51 return array($value);
53 return array();
56 public function renderPropertyViewValue(array $handles) {
57 $value = $this->getFieldValue();
58 if ($value) {
59 return $handles[$value]->renderLink();
61 return null;
64 public function validateApplicationTransactions(
65 PhabricatorApplicationTransactionEditor $editor,
66 $type,
67 array $xactions) {
69 $errors = parent::validateApplicationTransactions(
70 $editor,
71 $type,
72 $xactions);
74 $ok = PassphraseCredentialControl::validateTransactions(
75 $this->getViewer(),
76 $xactions);
78 if (!$ok) {
79 foreach ($xactions as $xaction) {
80 $errors[] = new PhabricatorApplicationTransactionValidationError(
81 $type,
82 pht('Invalid'),
83 pht(
84 'The selected credential does not exist, or you do not have '.
85 'permission to use it.'),
86 $xaction);
87 $this->setFieldError(pht('Invalid'));
91 return $errors;
94 public function getApplicationTransactionRequiredHandlePHIDs(
95 PhabricatorApplicationTransaction $xaction) {
96 $phids = array();
97 $old = $xaction->getOldValue();
98 $new = $xaction->getNewValue();
99 if ($old) {
100 $phids[] = $old;
102 if ($new) {
103 $phids[] = $new;
105 return $phids;
109 public function getApplicationTransactionTitle(
110 PhabricatorApplicationTransaction $xaction) {
111 $author_phid = $xaction->getAuthorPHID();
113 $old = $xaction->getOldValue();
114 $new = $xaction->getNewValue();
116 if ($old && !$new) {
117 return pht(
118 '%s removed %s as %s.',
119 $xaction->renderHandleLink($author_phid),
120 $xaction->renderHandleLink($old),
121 $this->getFieldName());
122 } else if ($new && !$old) {
123 return pht(
124 '%s set %s to %s.',
125 $xaction->renderHandleLink($author_phid),
126 $this->getFieldName(),
127 $xaction->renderHandleLink($new));
128 } else {
129 return pht(
130 '%s changed %s from %s to %s.',
131 $xaction->renderHandleLink($author_phid),
132 $this->getFieldName(),
133 $xaction->renderHandleLink($old),
134 $xaction->renderHandleLink($new));
139 protected function getHTTPParameterType() {
140 return new AphrontPHIDHTTPParameterType();
143 protected function newConduitSearchParameterType() {
144 return new ConduitPHIDParameterType();
147 protected function newConduitEditParameterType() {
148 return new ConduitPHIDParameterType();