mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Implement a "select" standard custom field type
Summary: See D7006, etc. Brings this from Maniphest. Test Plan: See screenshots. Reviewers: btrahan Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D7007
This commit is contained in:
parent
2846463481
commit
e2a148b8f8
2 changed files with 80 additions and 0 deletions
|
@ -1639,6 +1639,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php',
|
'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php',
|
||||||
'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php',
|
'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php',
|
||||||
'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php',
|
'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php',
|
||||||
|
'PhabricatorStandardCustomFieldSelect' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php',
|
||||||
'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php',
|
'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php',
|
||||||
'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php',
|
'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php',
|
||||||
'PhabricatorStatusController' => 'applications/system/PhabricatorStatusController.php',
|
'PhabricatorStatusController' => 'applications/system/PhabricatorStatusController.php',
|
||||||
|
@ -3788,6 +3789,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorStandardCustomField' => 'PhabricatorCustomField',
|
'PhabricatorStandardCustomField' => 'PhabricatorCustomField',
|
||||||
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
|
'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField',
|
||||||
'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField',
|
'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField',
|
||||||
|
'PhabricatorStandardCustomFieldSelect' => 'PhabricatorStandardCustomField',
|
||||||
'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField',
|
'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField',
|
||||||
'PhabricatorStandardPageView' => 'PhabricatorBarePageView',
|
'PhabricatorStandardPageView' => 'PhabricatorBarePageView',
|
||||||
'PhabricatorStatusController' => 'PhabricatorController',
|
'PhabricatorStatusController' => 'PhabricatorController',
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorStandardCustomFieldSelect
|
||||||
|
extends PhabricatorStandardCustomField {
|
||||||
|
|
||||||
|
public function getFieldType() {
|
||||||
|
return 'select';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function buildFieldIndexes() {
|
||||||
|
$indexes = array();
|
||||||
|
|
||||||
|
$value = $this->getFieldValue();
|
||||||
|
if (strlen($value)) {
|
||||||
|
$indexes[] = $this->newStringIndex($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function readApplicationSearchValueFromRequest(
|
||||||
|
PhabricatorApplicationSearchEngine $engine,
|
||||||
|
AphrontRequest $request) {
|
||||||
|
return $request->getArr($this->getFieldKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function applyApplicationSearchConstraintToQuery(
|
||||||
|
PhabricatorApplicationSearchEngine $engine,
|
||||||
|
PhabricatorCursorPagedPolicyAwareQuery $query,
|
||||||
|
$value) {
|
||||||
|
if ($value) {
|
||||||
|
$query->withApplicationSearchContainsConstraint(
|
||||||
|
$this->newStringIndex(null),
|
||||||
|
$value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function appendToApplicationSearchForm(
|
||||||
|
PhabricatorApplicationSearchEngine $engine,
|
||||||
|
AphrontFormView $form,
|
||||||
|
$value,
|
||||||
|
array $handles) {
|
||||||
|
|
||||||
|
if (!is_array($value)) {
|
||||||
|
$value = array();
|
||||||
|
}
|
||||||
|
$value = array_fuse($value);
|
||||||
|
|
||||||
|
$control = id(new AphrontFormCheckboxControl())
|
||||||
|
->setLabel($this->getFieldName());
|
||||||
|
|
||||||
|
foreach ($this->getOptions() as $name => $option) {
|
||||||
|
$control->addCheckbox(
|
||||||
|
$this->getFieldKey().'[]',
|
||||||
|
$name,
|
||||||
|
$option,
|
||||||
|
isset($value[$name]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$form->appendChild($control);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getOptions() {
|
||||||
|
return $this->getFieldConfigValue('options', array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderEditControl() {
|
||||||
|
return id(new AphrontFormSelectControl())
|
||||||
|
->setLabel($this->getFieldName())
|
||||||
|
->setName($this->getFieldKey())
|
||||||
|
->setOptions($this->getOptions());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderPropertyViewValue() {
|
||||||
|
return idx($this->getOptions(), $this->getFieldValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue