1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Implement standard field "bool" type

Summary: Depends on D7005. Implements the existing "bool" type.

Test Plan: See screenshots.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7006
This commit is contained in:
epriestley 2013-09-16 16:03:51 -07:00
parent 2b538bfb25
commit 2846463481
3 changed files with 110 additions and 0 deletions

View file

@ -1636,6 +1636,7 @@ phutil_register_library_map(array(
'PhabricatorSortTableExample' => 'applications/uiexample/examples/PhabricatorSortTableExample.php',
'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php',
'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php',
'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php',
'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php',
'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php',
'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php',
@ -3785,6 +3786,7 @@ phutil_register_library_map(array(
'PhabricatorSortTableExample' => 'PhabricatorUIExample',
'PhabricatorSourceCodeView' => 'AphrontView',
'PhabricatorStandardCustomField' => 'PhabricatorCustomField',
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField',
'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField',
'PhabricatorStandardPageView' => 'PhabricatorBarePageView',

View file

@ -9,6 +9,7 @@ abstract class PhabricatorStandardCustomField
private $fieldDescription;
private $fieldConfig;
private $applicationField;
private $strings;
abstract public function getFieldType();
@ -84,6 +85,9 @@ abstract class PhabricatorStandardCustomField
case 'description':
$this->setFieldDescription($value);
break;
case 'strings':
$this->setStrings($value);
break;
case 'type':
// We set this earlier on.
break;
@ -119,6 +123,15 @@ abstract class PhabricatorStandardCustomField
return coalesce($this->fieldDescription, parent::getFieldDescription());
}
public function setStrings(array $strings) {
$this->strings = $strings;
return;
}
public function getString($key, $default = null) {
return idx($this->strings, $key, $default);
}
public function shouldUseStorage() {
return true;
}

View file

@ -0,0 +1,95 @@
<?php
final class PhabricatorStandardCustomFieldBool
extends PhabricatorStandardCustomField {
public function getFieldType() {
return 'bool';
}
public function buildFieldIndexes() {
$indexes = array();
$value = $this->getFieldValue();
if (strlen($value)) {
$indexes[] = $this->newNumericIndex((int)$value);
}
return $indexes;
}
public function getValueForStorage() {
$value = $this->getFieldValue();
if (strlen($value)) {
return (int)$value;
} else {
return null;
}
}
public function setValueFromStorage($value) {
if (strlen($value)) {
$value = (bool)$value;
} else {
$value = null;
}
return $this->setFieldValue($value);
}
public function readApplicationSearchValueFromRequest(
PhabricatorApplicationSearchEngine $engine,
AphrontRequest $request) {
return $request->getStr($this->getFieldKey());
}
public function applyApplicationSearchConstraintToQuery(
PhabricatorApplicationSearchEngine $engine,
PhabricatorCursorPagedPolicyAwareQuery $query,
$value) {
if ($value == 'require') {
$query->withApplicationSearchContainsConstraint(
$this->newNumericIndex(null),
1);
}
}
public function appendToApplicationSearchForm(
PhabricatorApplicationSearchEngine $engine,
AphrontFormView $form,
$value,
array $handles) {
$form->appendChild(
id(new AphrontFormSelectControl())
->setLabel($this->getFieldName())
->setName($this->getFieldKey())
->setValue($value)
->setOptions(
array(
'' => $this->getString('search.default', pht('(Any)')),
'require' => $this->getString('search.require', pht('Require')),
)));
}
public function renderEditControl() {
return id(new AphrontFormCheckboxControl())
->setLabel($this->getFieldName())
->addCheckbox(
$this->getFieldKey(),
1,
$this->getString('edit.checkbox'),
(bool)$this->getFieldValue());
}
public function renderPropertyViewValue() {
$value = $this->getFieldValue();
if ($value) {
return $this->getString('view.yes', pht('Yes'));
} else {
return null;
}
}
}