From 10b38792320830e0b34f6fb59ad8054e2b154db1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 19 May 2017 13:45:06 -0700 Subject: [PATCH] Make Project slug/hashtag transactions render a little more nicely Summary: Ref T12732. Use `renderValue()` to build `renderValueList()` so we get nice fancy text for these. Test Plan: {F4967410} Reviewers: chad, amckinley Reviewed By: amckinley Maniphest Tasks: T12732 Differential Revision: https://secure.phabricator.com/D17966 --- .../PhabricatorProjectSlugsTransaction.php | 30 ++++++++++++------- .../PhabricatorModularTransactionType.php | 13 ++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/applications/project/xaction/PhabricatorProjectSlugsTransaction.php b/src/applications/project/xaction/PhabricatorProjectSlugsTransaction.php index d442c39a76..e1f22b3746 100644 --- a/src/applications/project/xaction/PhabricatorProjectSlugsTransaction.php +++ b/src/applications/project/xaction/PhabricatorProjectSlugsTransaction.php @@ -40,26 +40,29 @@ final class PhabricatorProjectSlugsTransaction $add = array_diff($new, $old); $rem = array_diff($old, $new); + $add = $this->renderHashtags($add); + $rem = $this->renderHashtags($rem); + if ($add && $rem) { return pht( '%s changed project hashtag(s), added %d: %s; removed %d: %s.', $this->renderAuthor(), count($add), - $this->renderSlugList($add), + $this->renderValueList($add), count($rem), - $this->renderSlugList($rem)); + $this->renderValueList($rem)); } else if ($add) { return pht( '%s added %d project hashtag(s): %s.', $this->renderAuthor(), count($add), - $this->renderSlugList($add)); + $this->renderValueList($add)); } else if ($rem) { return pht( '%s removed %d project hashtag(s): %s.', $this->renderAuthor(), count($rem), - $this->renderSlugList($rem)); + $this->renderValueList($rem)); } } @@ -70,29 +73,32 @@ final class PhabricatorProjectSlugsTransaction $add = array_diff($new, $old); $rem = array_diff($old, $new); + $add = $this->renderHashtags($add); + $rem = $this->renderHashtags($rem); + if ($add && $rem) { return pht( '%s changed %s hashtag(s), added %d: %s; removed %d: %s.', $this->renderAuthor(), $this->renderObject(), count($add), - $this->renderSlugList($add), + $this->renderValueList($add), count($rem), - $this->renderSlugList($rem)); + $this->renderValueList($rem)); } else if ($add) { return pht( '%s added %d %s hashtag(s): %s.', $this->renderAuthor(), count($add), $this->renderObject(), - $this->renderSlugList($add)); + $this->renderValueList($add)); } else if ($rem) { return pht( '%s removed %d %s hashtag(s): %s.', $this->renderAuthor(), count($rem), $this->renderObject(), - $this->renderSlugList($rem)); + $this->renderValueList($rem)); } } @@ -157,8 +163,12 @@ final class PhabricatorProjectSlugsTransaction return $errors; } - private function renderSlugList($slugs) { - return implode(', ', $slugs); + private function renderHashtags(array $tags) { + $result = array(); + foreach ($tags as $tag) { + $result[] = '#'.$tag; + } + return $result; } } diff --git a/src/applications/transactions/storage/PhabricatorModularTransactionType.php b/src/applications/transactions/storage/PhabricatorModularTransactionType.php index 8a56e8e8ce..128b5c7c19 100644 --- a/src/applications/transactions/storage/PhabricatorModularTransactionType.php +++ b/src/applications/transactions/storage/PhabricatorModularTransactionType.php @@ -208,6 +208,19 @@ abstract class PhabricatorModularTransactionType $value); } + final protected function renderValueList(array $values) { + $result = array(); + foreach ($values as $value) { + $result[] = $this->renderValue($value); + } + + if ($this->isTextMode()) { + return implode(', ', $result); + } + + return phutil_implode_html(', ', $result); + } + final protected function renderOldValue() { return $this->renderValue($this->getOldValue()); }