Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / standard / PhabricatorStandardCustomFieldSelect.php
blob5957afe56a5762cf65f0a3e53e3be23403b6f282
1 <?php
3 final class PhabricatorStandardCustomFieldSelect
4 extends PhabricatorStandardCustomField {
6 public function getFieldType() {
7 return 'select';
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 readApplicationSearchValueFromRequest(
22 PhabricatorApplicationSearchEngine $engine,
23 AphrontRequest $request) {
24 return $request->getArr($this->getFieldKey());
27 public function applyApplicationSearchConstraintToQuery(
28 PhabricatorApplicationSearchEngine $engine,
29 PhabricatorCursorPagedPolicyAwareQuery $query,
30 $value) {
31 if ($value) {
32 $query->withApplicationSearchContainsConstraint(
33 $this->newStringIndex(null),
34 $value);
38 public function appendToApplicationSearchForm(
39 PhabricatorApplicationSearchEngine $engine,
40 AphrontFormView $form,
41 $value) {
43 if (!is_array($value)) {
44 $value = array();
46 $value = array_fuse($value);
48 $control = id(new AphrontFormCheckboxControl())
49 ->setLabel($this->getFieldName());
51 foreach ($this->getOptions() as $name => $option) {
52 $control->addCheckbox(
53 $this->getFieldKey().'[]',
54 $name,
55 $option,
56 isset($value[$name]));
59 $form->appendChild($control);
62 public function getOptions() {
63 return $this->getFieldConfigValue('options', array());
66 public function renderEditControl(array $handles) {
67 return id(new AphrontFormSelectControl())
68 ->setLabel($this->getFieldName())
69 ->setCaption($this->getCaption())
70 ->setName($this->getFieldKey())
71 ->setValue($this->getFieldValue())
72 ->setOptions($this->getOptions());
75 public function renderPropertyViewValue(array $handles) {
76 if (!strlen($this->getFieldValue())) {
77 return null;
79 return idx($this->getOptions(), $this->getFieldValue());
82 public function getApplicationTransactionTitle(
83 PhabricatorApplicationTransaction $xaction) {
84 $author_phid = $xaction->getAuthorPHID();
85 $old = $xaction->getOldValue();
86 $new = $xaction->getNewValue();
88 $old = idx($this->getOptions(), $old, $old);
89 $new = idx($this->getOptions(), $new, $new);
91 if (!$old) {
92 return pht(
93 '%s set %s to %s.',
94 $xaction->renderHandleLink($author_phid),
95 $this->getFieldName(),
96 $new);
97 } else if (!$new) {
98 return pht(
99 '%s removed %s.',
100 $xaction->renderHandleLink($author_phid),
101 $this->getFieldName());
102 } else {
103 return pht(
104 '%s changed %s from %s to %s.',
105 $xaction->renderHandleLink($author_phid),
106 $this->getFieldName(),
107 $old,
108 $new);
112 public function shouldAppearInHerald() {
113 return true;
116 public function getHeraldFieldConditions() {
117 return array(
118 HeraldAdapter::CONDITION_IS_ANY,
119 HeraldAdapter::CONDITION_IS_NOT_ANY,
123 public function getHeraldFieldValueType($condition) {
124 $parameters = array(
125 'object' => get_class($this->getObject()),
126 'role' => PhabricatorCustomField::ROLE_HERALD,
127 'key' => $this->getFieldKey(),
130 $datasource = id(new PhabricatorStandardSelectCustomFieldDatasource())
131 ->setParameters($parameters);
133 return id(new HeraldTokenizerFieldValue())
134 ->setKey('custom.'.$this->getFieldKey())
135 ->setDatasource($datasource)
136 ->setValueMap($this->getOptions());
139 protected function getHTTPParameterType() {
140 return new AphrontSelectHTTPParameterType();
143 protected function newConduitSearchParameterType() {
144 return new ConduitStringListParameterType();
147 protected function newConduitEditParameterType() {
148 return new ConduitStringParameterType();
151 protected function newBulkParameterType() {
152 return id(new BulkSelectParameterType())
153 ->setOptions($this->getOptions());
156 protected function newExportFieldType() {
157 return id(new PhabricatorOptionExportField())
158 ->setOptions($this->getOptions());