From e2a148b8f8d25fdd48e01c566e2637af3d3ee394 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 16 Sep 2013 16:04:08 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + .../PhabricatorStandardCustomFieldSelect.php | 78 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 639d408850..6ff129d1bd 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1639,6 +1639,7 @@ phutil_register_library_map(array( 'PhabricatorStandardCustomFieldBool' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php', 'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php', 'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php', + 'PhabricatorStandardCustomFieldSelect' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php', 'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php', 'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php', 'PhabricatorStatusController' => 'applications/system/PhabricatorStatusController.php', @@ -3788,6 +3789,7 @@ phutil_register_library_map(array( 'PhabricatorStandardCustomField' => 'PhabricatorCustomField', 'PhabricatorStandardCustomFieldBool' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField', + 'PhabricatorStandardCustomFieldSelect' => 'PhabricatorStandardCustomField', 'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField', 'PhabricatorStandardPageView' => 'PhabricatorBarePageView', 'PhabricatorStatusController' => 'PhabricatorController', diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php new file mode 100644 index 0000000000..665a05216f --- /dev/null +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php @@ -0,0 +1,78 @@ +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()); + } + +}