diff --git a/src/docs/user/configuration/custom_fields.diviner b/src/docs/user/configuration/custom_fields.diviner --- a/src/docs/user/configuration/custom_fields.diviner +++ b/src/docs/user/configuration/custom_fields.diviner @@ -119,6 +119,12 @@ 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 diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomField.php @@ -301,6 +301,10 @@ } 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,73 @@ 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': + // TODO maybe expose 'list.icon.alt' for hover stuff. + return 'fa-'.$this->getFieldConfigValue('list.icon'); + case 'attribute': + case 'byline': + $label = $this->getFieldConfigValue('list.label', $this->getFieldName()); /// TODO fall-back to name/caption + 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); } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBlueprints.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBlueprints.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBlueprints.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBlueprints.php @@ -24,7 +24,7 @@ $new); } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { $value = $this->getFieldValue(); if (!$value) { return phutil_tag('em', array(), pht('No authorized blueprints.')); diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldBool.php @@ -36,7 +36,7 @@ } public function setValueFromStorage($value) { - if (strlen($value)) { + if (phutil_nonempty_scalar($value)) { $value = (bool)$value; } else { $value = null; @@ -90,7 +90,7 @@ (bool)$this->getFieldValue()); } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { $value = $this->getFieldValue(); if ($value) { return $this->getString('view.yes', pht('Yes')); diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldCredential.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldCredential.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldCredential.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldCredential.php @@ -53,10 +53,10 @@ 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; } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php @@ -52,7 +52,7 @@ $this->setFieldValue($value); } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { $value = $this->getFieldValue(); if (!$value) { return null; diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldHeader.php @@ -26,7 +26,7 @@ return 'header'; } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { return $this->getFieldName(); } diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldLink.php @@ -18,7 +18,7 @@ return $indexes; } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { $value = $this->getFieldValue(); if (!strlen($value)) { diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldPHIDs.php @@ -72,15 +72,14 @@ 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() { diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldRemarkup.php @@ -27,7 +27,7 @@ ); } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { $value = $this->getFieldValue(); if (!phutil_nonempty_string($value)) { diff --git a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php --- a/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php +++ b/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldSelect.php @@ -72,7 +72,7 @@ ->setOptions($this->getOptions()); } - public function renderPropertyViewValue(array $handles) { + protected function renderValue() { if (!phutil_nonempty_string($this->getFieldValue())) { return null; }