Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / customfield / standard / PhabricatorStandardCustomFieldBool.php
blobf1d1371a7dc0b1f094d9ee041967e37731d7fcb3
1 <?php
3 final class PhabricatorStandardCustomFieldBool
4 extends PhabricatorStandardCustomField {
6 public function getFieldType() {
7 return 'bool';
10 public function buildFieldIndexes() {
11 $indexes = array();
13 $value = $this->getFieldValue();
14 if (strlen($value)) {
15 $indexes[] = $this->newNumericIndex((int)$value);
18 return $indexes;
21 public function buildOrderIndex() {
22 return $this->newNumericIndex(0);
25 public function readValueFromRequest(AphrontRequest $request) {
26 $this->setFieldValue((bool)$request->getBool($this->getFieldKey()));
29 public function getValueForStorage() {
30 $value = $this->getFieldValue();
31 if ($value !== null) {
32 return (int)$value;
33 } else {
34 return null;
38 public function setValueFromStorage($value) {
39 if (strlen($value)) {
40 $value = (bool)$value;
41 } else {
42 $value = null;
44 return $this->setFieldValue($value);
47 public function readApplicationSearchValueFromRequest(
48 PhabricatorApplicationSearchEngine $engine,
49 AphrontRequest $request) {
51 return $request->getStr($this->getFieldKey());
54 public function applyApplicationSearchConstraintToQuery(
55 PhabricatorApplicationSearchEngine $engine,
56 PhabricatorCursorPagedPolicyAwareQuery $query,
57 $value) {
58 if ($value == 'require') {
59 $query->withApplicationSearchContainsConstraint(
60 $this->newNumericIndex(null),
61 1);
65 public function appendToApplicationSearchForm(
66 PhabricatorApplicationSearchEngine $engine,
67 AphrontFormView $form,
68 $value) {
70 $form->appendChild(
71 id(new AphrontFormSelectControl())
72 ->setLabel($this->getFieldName())
73 ->setName($this->getFieldKey())
74 ->setValue($value)
75 ->setOptions(
76 array(
77 '' => $this->getString('search.default', pht('(Any)')),
78 'require' => $this->getString('search.require', pht('Require')),
79 )));
82 public function renderEditControl(array $handles) {
83 return id(new AphrontFormCheckboxControl())
84 ->setLabel($this->getFieldName())
85 ->setCaption($this->getCaption())
86 ->addCheckbox(
87 $this->getFieldKey(),
89 $this->getString('edit.checkbox'),
90 (bool)$this->getFieldValue());
93 public function renderPropertyViewValue(array $handles) {
94 $value = $this->getFieldValue();
95 if ($value) {
96 return $this->getString('view.yes', pht('Yes'));
97 } else {
98 return null;
102 public function getApplicationTransactionTitle(
103 PhabricatorApplicationTransaction $xaction) {
104 $author_phid = $xaction->getAuthorPHID();
105 $old = $xaction->getOldValue();
106 $new = $xaction->getNewValue();
108 if ($new) {
109 return pht(
110 '%s checked %s.',
111 $xaction->renderHandleLink($author_phid),
112 $this->getFieldName());
113 } else {
114 return pht(
115 '%s unchecked %s.',
116 $xaction->renderHandleLink($author_phid),
117 $this->getFieldName());
121 public function shouldAppearInHerald() {
122 return true;
125 public function getHeraldFieldConditions() {
126 return array(
127 HeraldAdapter::CONDITION_IS_TRUE,
128 HeraldAdapter::CONDITION_IS_FALSE,
132 public function getHeraldFieldStandardType() {
133 return HeraldField::STANDARD_BOOL;
136 protected function getHTTPParameterType() {
137 return new AphrontBoolHTTPParameterType();
140 protected function newConduitSearchParameterType() {
141 return new ConduitBoolParameterType();
144 protected function newConduitEditParameterType() {
145 return new ConduitBoolParameterType();