1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02: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:
Aviv Eyal 2024-06-21 12:42:57 +03:00
parent 5d479556c3
commit 587530a9bf
11 changed files with 94 additions and 14 deletions

View file

@ -119,6 +119,12 @@ When defining custom fields using a configuration option like
above the control when rendered on the edit view.
- **placeholder**: A placeholder text that appears on text boxes. Only
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
created using another object as a template.
- **limit**: For control types which use a tokenizer control to let the user

View file

@ -301,6 +301,10 @@ abstract class PhabricatorStandardCustomField
}
public function renderPropertyViewValue(array $handles) {
return $this->renderValue();
}
protected function renderValue() {
// If your field needs to render anything more complicated then a string,
// then you should override this method.
$value_str = phutil_string_cast($this->getFieldValue());
@ -311,6 +315,77 @@ abstract class PhabricatorStandardCustomField
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() {
return $this->getFieldConfigValue('search', false);
}

View file

@ -24,7 +24,7 @@ final class PhabricatorStandardCustomFieldBlueprints
$new);
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if (!$value) {
return phutil_tag('em', array(), pht('No authorized blueprints.'));

View file

@ -36,7 +36,7 @@ final class PhabricatorStandardCustomFieldBool
}
public function setValueFromStorage($value) {
if (strlen($value)) {
if (phutil_nonempty_scalar($value)) {
$value = (bool)$value;
} else {
$value = null;
@ -90,7 +90,7 @@ final class PhabricatorStandardCustomFieldBool
(bool)$this->getFieldValue());
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if ($value) {
return $this->getString('view.yes', pht('Yes'));

View file

@ -53,10 +53,10 @@ final class PhabricatorStandardCustomFieldCredential
return array();
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if ($value) {
return $handles[$value]->renderLink();
return $this->getViewer()->renderHandle($value);
}
return null;
}

View file

@ -52,7 +52,7 @@ final class PhabricatorStandardCustomFieldDate
$this->setFieldValue($value);
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if (!$value) {
return null;

View file

@ -26,7 +26,7 @@ final class PhabricatorStandardCustomFieldHeader
return 'header';
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
return $this->getFieldName();
}

View file

@ -18,7 +18,7 @@ final class PhabricatorStandardCustomFieldLink
return $indexes;
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if (!phutil_nonempty_string($value)) {

View file

@ -72,15 +72,14 @@ abstract class PhabricatorStandardCustomFieldPHIDs
return array();
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if (!$value) {
return null;
}
$handles = mpull($handles, 'renderHovercardLink');
$handles = phutil_implode_html(', ', $handles);
return $handles;
return $this->getViewer()->renderHandleList($value)
->setAsInline(true);
}
public function getRequiredHandlePHIDsForEdit() {

View file

@ -27,7 +27,7 @@ final class PhabricatorStandardCustomFieldRemarkup
);
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
$value = $this->getFieldValue();
if (!phutil_nonempty_string($value)) {

View file

@ -72,7 +72,7 @@ final class PhabricatorStandardCustomFieldSelect
->setOptions($this->getOptions());
}
public function renderPropertyViewValue(array $handles) {
protected function renderValue() {
if (!phutil_nonempty_string($this->getFieldValue())) {
return null;
}