mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
Add Standard Custom Fields to Item List
Summary: Allow "Standard" (config-based") custom fields to be displayed in search-results. Depends on D25548. Ref T15750. Test Plan: Set `maniphest.custom-field-definitions` to the value of P32, and start playing with custom values on tasks. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: 20after4, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15750 Differential Revision: https://we.phorge.it/D25549
This commit is contained in:
parent
5d479556c3
commit
587530a9bf
11 changed files with 94 additions and 14 deletions
|
@ -119,6 +119,12 @@ When defining custom fields using a configuration option like
|
||||||
above the control when rendered on the edit view.
|
above the control when rendered on the edit view.
|
||||||
- **placeholder**: A placeholder text that appears on text boxes. Only
|
- **placeholder**: A placeholder text that appears on text boxes. Only
|
||||||
supported in text, int and remarkup fields (optional).
|
supported in text, int and remarkup fields (optional).
|
||||||
|
- **list**: If set to `icon`, `attribute` or `byline`, the value of the field
|
||||||
|
will be shown in list-view.
|
||||||
|
- **list.icon**: If `list` is set to `icon`, use this icon. These are the
|
||||||
|
same icons that can be used in the `{icon}` syntax for Remarkup.
|
||||||
|
- **list.label**: When rendering value in a list, use this label (instead of
|
||||||
|
`name`).
|
||||||
- **copy**: If true, this field's value will be copied when an object is
|
- **copy**: If true, this field's value will be copied when an object is
|
||||||
created using another object as a template.
|
created using another object as a template.
|
||||||
- **limit**: For control types which use a tokenizer control to let the user
|
- **limit**: For control types which use a tokenizer control to let the user
|
||||||
|
|
|
@ -301,6 +301,10 @@ abstract class PhabricatorStandardCustomField
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
public function renderPropertyViewValue(array $handles) {
|
||||||
|
return $this->renderValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderValue() {
|
||||||
// If your field needs to render anything more complicated then a string,
|
// If your field needs to render anything more complicated then a string,
|
||||||
// then you should override this method.
|
// then you should override this method.
|
||||||
$value_str = phutil_string_cast($this->getFieldValue());
|
$value_str = phutil_string_cast($this->getFieldValue());
|
||||||
|
@ -311,6 +315,77 @@ abstract class PhabricatorStandardCustomField
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function shouldAppearInListView() {
|
||||||
|
return $this->getFieldConfigValue('list', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStyleForListItemView() {
|
||||||
|
return $this->getFieldConfigValue('list');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderListItemValue() {
|
||||||
|
return $this->renderValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isValue($something) {
|
||||||
|
if (is_object($something)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return phutil_nonempty_scalar($something);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValueForListItem() {
|
||||||
|
$style = $this->getStyleForListItemView();
|
||||||
|
$value = $this->renderListItemValue();
|
||||||
|
if (!$this->isValue($value) || !$style) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
switch ($style) {
|
||||||
|
case 'icon':
|
||||||
|
// maybe expose 'list.icon.alt' for hover stuff?
|
||||||
|
// also icon's "label", and other features supported by
|
||||||
|
// PHUIObjectItemView::addIcon().
|
||||||
|
return 'fa-'.$this->getFieldConfigValue('list.icon');
|
||||||
|
case 'attribute':
|
||||||
|
case 'byline':
|
||||||
|
$label = $this->getFieldConfigValue(
|
||||||
|
'list.label',
|
||||||
|
$this->getFieldName());
|
||||||
|
if (phutil_nonempty_string($label)) {
|
||||||
|
return pht('%s: %s', $label, $value);
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
default:
|
||||||
|
throw new Exception(
|
||||||
|
pht(
|
||||||
|
"Unknown field list-item view style '%s'; valid styles are ".
|
||||||
|
"'%s', '%s'and '%s'.",
|
||||||
|
$style,
|
||||||
|
'icon',
|
||||||
|
'attribute',
|
||||||
|
'byline'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderOnListItem(PHUIObjectItemView $view) {
|
||||||
|
$value = $this->getValueForListItem();
|
||||||
|
if (!$this->isValue($value)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($this->getStyleForListItemView()) {
|
||||||
|
case 'icon':
|
||||||
|
$view->addIcon($value);
|
||||||
|
break;
|
||||||
|
case 'attribute':
|
||||||
|
$view->addAttribute($value);
|
||||||
|
break;
|
||||||
|
case 'byline':
|
||||||
|
$view->addByline($value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function shouldAppearInApplicationSearch() {
|
public function shouldAppearInApplicationSearch() {
|
||||||
return $this->getFieldConfigValue('search', false);
|
return $this->getFieldConfigValue('search', false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ final class PhabricatorStandardCustomFieldBlueprints
|
||||||
$new);
|
$new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
if (!$value) {
|
if (!$value) {
|
||||||
return phutil_tag('em', array(), pht('No authorized blueprints.'));
|
return phutil_tag('em', array(), pht('No authorized blueprints.'));
|
||||||
|
|
|
@ -36,7 +36,7 @@ final class PhabricatorStandardCustomFieldBool
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setValueFromStorage($value) {
|
public function setValueFromStorage($value) {
|
||||||
if (strlen($value)) {
|
if (phutil_nonempty_scalar($value)) {
|
||||||
$value = (bool)$value;
|
$value = (bool)$value;
|
||||||
} else {
|
} else {
|
||||||
$value = null;
|
$value = null;
|
||||||
|
@ -90,7 +90,7 @@ final class PhabricatorStandardCustomFieldBool
|
||||||
(bool)$this->getFieldValue());
|
(bool)$this->getFieldValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
if ($value) {
|
if ($value) {
|
||||||
return $this->getString('view.yes', pht('Yes'));
|
return $this->getString('view.yes', pht('Yes'));
|
||||||
|
|
|
@ -53,10 +53,10 @@ final class PhabricatorStandardCustomFieldCredential
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
if ($value) {
|
if ($value) {
|
||||||
return $handles[$value]->renderLink();
|
return $this->getViewer()->renderHandle($value);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ final class PhabricatorStandardCustomFieldDate
|
||||||
$this->setFieldValue($value);
|
$this->setFieldValue($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
if (!$value) {
|
if (!$value) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -26,7 +26,7 @@ final class PhabricatorStandardCustomFieldHeader
|
||||||
return 'header';
|
return 'header';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
return $this->getFieldName();
|
return $this->getFieldName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ final class PhabricatorStandardCustomFieldLink
|
||||||
return $indexes;
|
return $indexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
|
|
||||||
if (!phutil_nonempty_string($value)) {
|
if (!phutil_nonempty_string($value)) {
|
||||||
|
|
|
@ -72,15 +72,14 @@ abstract class PhabricatorStandardCustomFieldPHIDs
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
if (!$value) {
|
if (!$value) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$handles = mpull($handles, 'renderHovercardLink');
|
return $this->getViewer()->renderHandleList($value)
|
||||||
$handles = phutil_implode_html(', ', $handles);
|
->setAsInline(true);
|
||||||
return $handles;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRequiredHandlePHIDsForEdit() {
|
public function getRequiredHandlePHIDsForEdit() {
|
||||||
|
|
|
@ -27,7 +27,7 @@ final class PhabricatorStandardCustomFieldRemarkup
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
$value = $this->getFieldValue();
|
$value = $this->getFieldValue();
|
||||||
|
|
||||||
if (!phutil_nonempty_string($value)) {
|
if (!phutil_nonempty_string($value)) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ final class PhabricatorStandardCustomFieldSelect
|
||||||
->setOptions($this->getOptions());
|
->setOptions($this->getOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderPropertyViewValue(array $handles) {
|
protected function renderValue() {
|
||||||
if (!phutil_nonempty_string($this->getFieldValue())) {
|
if (!phutil_nonempty_string($this->getFieldValue())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue