diff --git a/src/applications/drydock/logtype/DrydockLeaseNoAuthorizationsLogType.php b/src/applications/drydock/logtype/DrydockLeaseNoAuthorizationsLogType.php index b5a7ca1b13..cce98956a1 100644 --- a/src/applications/drydock/logtype/DrydockLeaseNoAuthorizationsLogType.php +++ b/src/applications/drydock/logtype/DrydockLeaseNoAuthorizationsLogType.php @@ -13,14 +13,13 @@ final class DrydockLeaseNoAuthorizationsLogType extends DrydockLogType { } public function renderLog(array $data) { - $viewer = $this->getViewer(); $authorizing_phid = idx($data, 'authorizingPHID'); return pht( 'The object which authorized this lease (%s) is not authorized to use '. 'any of the blueprints the lease lists. Approve the authorizations '. 'before using the lease.', - $viewer->renderHandle($authorizing_phid)->render()); + $this->renderHandle($authorizing_phid)); } } diff --git a/src/applications/drydock/logtype/DrydockLeaseReclaimLogType.php b/src/applications/drydock/logtype/DrydockLeaseReclaimLogType.php index 8dbc13d9d4..6e145a24ae 100644 --- a/src/applications/drydock/logtype/DrydockLeaseReclaimLogType.php +++ b/src/applications/drydock/logtype/DrydockLeaseReclaimLogType.php @@ -13,13 +13,11 @@ final class DrydockLeaseReclaimLogType extends DrydockLogType { } public function renderLog(array $data) { - $viewer = $this->getViewer(); - $resource_phids = idx($data, 'resourcePHIDs', array()); return pht( 'Reclaimed resource %s.', - $viewer->renderHandleList($resource_phids)->render()); + $this->renderHandleList($resource_phids)); } } diff --git a/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php b/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php index 46ab965b36..bb91acb030 100644 --- a/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php +++ b/src/applications/drydock/logtype/DrydockLeaseWaitingForResourcesLogType.php @@ -13,13 +13,11 @@ final class DrydockLeaseWaitingForResourcesLogType extends DrydockLogType { } public function renderLog(array $data) { - $viewer = $this->getViewer(); - $blueprint_phids = idx($data, 'blueprintPHIDs', array()); return pht( 'Waiting for available resources from: %s.', - $viewer->renderHandleList($blueprint_phids)->render()); + $this->renderHandleList($blueprint_phids)); } } diff --git a/src/applications/drydock/logtype/DrydockLogType.php b/src/applications/drydock/logtype/DrydockLogType.php index 7faab42dfe..690ffc5670 100644 --- a/src/applications/drydock/logtype/DrydockLogType.php +++ b/src/applications/drydock/logtype/DrydockLogType.php @@ -4,17 +4,18 @@ abstract class DrydockLogType extends Phobject { private $viewer; private $log; + private $renderingMode = 'text'; abstract public function getLogTypeName(); abstract public function getLogTypeIcon(array $data); abstract public function renderLog(array $data); - public function setViewer(PhabricatorUser $viewer) { + final public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; } - public function getViewer() { + final public function getViewer() { return $this->viewer; } @@ -38,4 +39,36 @@ abstract class DrydockLogType extends Phobject { ->execute(); } + final public function renderLogForText($data) { + $this->renderingMode = 'text'; + return $this->renderLog($data); + } + + final public function renderLogForHTML($data) { + $this->renderingMode = 'html'; + return $this->renderLog($data); + } + + final protected function renderHandle($phid) { + $viewer = $this->getViewer(); + $handle = $viewer->renderHandle($phid); + + if ($this->renderingMode == 'html') { + return $handle->render(); + } else { + return $handle->setAsText(true)->render(); + } + } + + final protected function renderHandleList(array $phids) { + $viewer = $this->getViewer(); + $handle_list = $viewer->renderHandleList($phids); + + if ($this->renderingMode == 'html') { + return $handle_list->render(); + } else { + return $handle_list->setAsText(true)->render(); + } + } + } diff --git a/src/applications/drydock/logtype/DrydockResourceReclaimLogType.php b/src/applications/drydock/logtype/DrydockResourceReclaimLogType.php index 9e9d5fdef3..aa989e97df 100644 --- a/src/applications/drydock/logtype/DrydockResourceReclaimLogType.php +++ b/src/applications/drydock/logtype/DrydockResourceReclaimLogType.php @@ -13,12 +13,11 @@ final class DrydockResourceReclaimLogType extends DrydockLogType { } public function renderLog(array $data) { - $viewer = $this->getViewer(); $reclaimer_phid = idx($data, 'reclaimerPHID'); return pht( 'Resource reclaimed by %s.', - $viewer->renderHandle($reclaimer_phid)->render()); + $this->renderHandle($reclaimer_phid)); } } diff --git a/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php b/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php index 8c3f682042..75636dab09 100644 --- a/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php +++ b/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php @@ -163,7 +163,7 @@ final class DrydockManagementLeaseWorkflow $log_data = $log->getData(); $type = $type_object->getLogTypeName(); - $data = $type_object->renderLog($log_data); + $data = $type_object->renderLogForText($log_data); } else { $type = pht('Unknown ("%s")', $type_key); $data = null; diff --git a/src/applications/drydock/view/DrydockLogListView.php b/src/applications/drydock/view/DrydockLogListView.php index cb66813507..61fde7cee7 100644 --- a/src/applications/drydock/view/DrydockLogListView.php +++ b/src/applications/drydock/view/DrydockLogListView.php @@ -52,7 +52,7 @@ final class DrydockLogListView extends AphrontView { $type = $type_object->getLogTypeName(); $icon = $type_object->getLogTypeIcon($log_data); - $data = $type_object->renderLog($log_data); + $data = $type_object->renderLogForHTML($log_data); $data = phutil_escape_html_newlines($data); } else { $type = pht('', $type_key);