diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 18454e3281..b54e8b8625 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1635,8 +1635,10 @@ phutil_register_library_map(array( 'PhabricatorSlugTestCase' => 'infrastructure/util/__tests__/PhabricatorSlugTestCase.php', 'PhabricatorSortTableExample' => 'applications/uiexample/examples/PhabricatorSortTableExample.php', 'PhabricatorSourceCodeView' => 'view/layout/PhabricatorSourceCodeView.php', - 'PhabricatorStandardCustomField' => 'infrastructure/customfield/field/PhabricatorStandardCustomField.php', + 'PhabricatorStandardCustomField' => 'infrastructure/customfield/standard/PhabricatorStandardCustomField.php', + 'PhabricatorStandardCustomFieldInt' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php', 'PhabricatorStandardCustomFieldInterface' => 'infrastructure/customfield/interface/PhabricatorStandardCustomFieldInterface.php', + 'PhabricatorStandardCustomFieldText' => 'infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php', 'PhabricatorStandardPageView' => 'view/page/PhabricatorStandardPageView.php', 'PhabricatorStatusController' => 'applications/system/PhabricatorStatusController.php', 'PhabricatorStorageFixtureScopeGuard' => 'infrastructure/testing/fixture/PhabricatorStorageFixtureScopeGuard.php', @@ -3783,6 +3785,8 @@ phutil_register_library_map(array( 'PhabricatorSortTableExample' => 'PhabricatorUIExample', 'PhabricatorSourceCodeView' => 'AphrontView', 'PhabricatorStandardCustomField' => 'PhabricatorCustomField', + 'PhabricatorStandardCustomFieldInt' => 'PhabricatorStandardCustomField', + 'PhabricatorStandardCustomFieldText' => 'PhabricatorStandardCustomField', 'PhabricatorStandardPageView' => 'PhabricatorBarePageView', 'PhabricatorStatusController' => 'PhabricatorController', 'PhabricatorStorageManagementDatabasesWorkflow' => 'PhabricatorStorageManagementWorkflow', diff --git a/src/infrastructure/customfield/field/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php similarity index 70% rename from src/infrastructure/customfield/field/PhabricatorStandardCustomField.php rename to src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php index 6fedc13e77..d30c7f189b 100644 --- a/src/infrastructure/customfield/field/PhabricatorStandardCustomField.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php @@ -1,27 +1,41 @@ setAncestorClass(__CLASS__) + ->loadObjects(); + $types = mpull($types, null, 'getFieldType'); + $fields = array(); foreach ($config as $key => $value) { + $type = idx($value, 'type', 'text'); + if (empty($types[$type])) { + // TODO: We should have better typechecking somewhere, and then make + // this more serious. + continue; + } + $namespace = $template->getStandardCustomFieldNamespace(); $full_key = "std:{$namespace}:{$key}"; $template = clone $template; - $standard = id(new PhabricatorStandardCustomField($full_key)) + $standard = id(clone $types[$type]) + ->setFieldKey($full_key) ->setFieldConfig($value) ->setApplicationField($template); @@ -32,10 +46,6 @@ final class PhabricatorStandardCustomField return $fields; } - public function __construct($key) { - $this->fieldKey = $key; - } - public function setApplicationField( PhabricatorStandardCustomFieldInterface $application_field) { $this->applicationField = $application_field; @@ -51,15 +61,6 @@ final class PhabricatorStandardCustomField return $this; } - public function setFieldType($type) { - $this->fieldType = $type; - return $this; - } - - public function getFieldType() { - return $this->fieldType; - } - public function getFieldValue() { return $this->fieldValue; } @@ -75,19 +76,17 @@ final class PhabricatorStandardCustomField } public function setFieldConfig(array $config) { - $this->setFieldType('text'); - foreach ($config as $key => $value) { switch ($key) { case 'name': $this->setFieldName($value); break; - case 'type': - $this->setFieldType($value); - break; case 'description': $this->setFieldDescription($value); break; + case 'type': + // We set this earlier on. + break; } } $this->fieldConfig = $config; @@ -103,6 +102,11 @@ final class PhabricatorStandardCustomField /* -( PhabricatorCustomField )--------------------------------------------- */ + public function setFieldKey($field_key) { + $this->fieldKey = $field_key; + return $this; + } + public function getFieldKey() { return $this->fieldKey; } @@ -136,19 +140,18 @@ final class PhabricatorStandardCustomField } public function readValueFromRequest(AphrontRequest $request) { - $this->setFieldValue($request->getStr($this->getFieldKey())); + $value = $request->getStr($this->getFieldKey()); + if (!strlen($value)) { + $value = null; + } + $this->setFieldValue($value); } public function renderEditControl() { - $type = $this->getFieldType(); - switch ($type) { - case 'text': - default: - return id(new AphrontFormTextControl()) - ->setName($this->getFieldKey()) - ->setValue($this->getFieldValue()) - ->setLabel($this->getFieldName()); - } + return id(new AphrontFormTextControl()) + ->setName($this->getFieldKey()) + ->setValue($this->getFieldValue()) + ->setLabel($this->getFieldName()); } public function newStorageObject() { @@ -176,42 +179,20 @@ final class PhabricatorStandardCustomField } public function buildFieldIndexes() { - $type = $this->getFieldType(); - switch ($type) { - case 'text': - default: - return array( - $this->newStringIndex($this->getFieldValue()), - ); - } + return array(); } public function readApplicationSearchValueFromRequest( PhabricatorApplicationSearchEngine $engine, AphrontRequest $request) { - $type = $this->getFieldType(); - switch ($type) { - case 'text': - default: - return $request->getStr('std:'.$this->getFieldIndex()); - } + return; } public function applyApplicationSearchConstraintToQuery( PhabricatorApplicationSearchEngine $engine, PhabricatorCursorPagedPolicyAwareQuery $query, $value) { - $type = $this->getFieldType(); - switch ($type) { - case 'text': - default: - if (strlen($value)) { - $query->withApplicationSearchContainsConstraint( - $this->newStringIndex(null), - $value); - } - break; - } + return; } public function appendToApplicationSearchForm( @@ -219,19 +200,7 @@ final class PhabricatorStandardCustomField AphrontFormView $form, $value, array $handles) { - - $type = $this->getFieldType(); - switch ($type) { - case 'text': - default: - $form->appendChild( - id(new AphrontFormTextControl()) - ->setLabel($this->getFieldName()) - ->setName('std:'.$this->getFieldIndex()) - ->setValue($value)); - break; - } - + return; } } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php new file mode 100644 index 0000000000..a467b3c6a5 --- /dev/null +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldInt.php @@ -0,0 +1,71 @@ +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 = (int)$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 (strlen($value)) { + $query->withApplicationSearchContainsConstraint( + $this->newNumericIndex(null), + $value); + } + } + + public function appendToApplicationSearchForm( + PhabricatorApplicationSearchEngine $engine, + AphrontFormView $form, + $value, + array $handles) { + + $form->appendChild( + id(new AphrontFormTextControl()) + ->setLabel($this->getFieldName()) + ->setName($this->getFieldKey()) + ->setValue($value)); + } + +} diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php new file mode 100644 index 0000000000..ef4c0a53aa --- /dev/null +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldText.php @@ -0,0 +1,53 @@ +getFieldValue(); + if (strlen($value)) { + $indexes[] = $this->newStringIndex($value); + } + + return $indexes; + } + + public function readApplicationSearchValueFromRequest( + PhabricatorApplicationSearchEngine $engine, + AphrontRequest $request) { + + return $request->getStr($this->getFieldKey()); + } + + public function applyApplicationSearchConstraintToQuery( + PhabricatorApplicationSearchEngine $engine, + PhabricatorCursorPagedPolicyAwareQuery $query, + $value) { + + if (strlen($value)) { + $query->withApplicationSearchContainsConstraint( + $this->newStringIndex(null), + $value); + } + } + + public function appendToApplicationSearchForm( + PhabricatorApplicationSearchEngine $engine, + AphrontFormView $form, + $value, + array $handles) { + + $form->appendChild( + id(new AphrontFormTextControl()) + ->setLabel($this->getFieldName()) + ->setName($this->getFieldKey()) + ->setValue($value)); + } + +}