diff --git a/src/applications/audit/editor/PhabricatorAuditEditor.php b/src/applications/audit/editor/PhabricatorAuditEditor.php index 3a6859549d..7fdb586f56 100644 --- a/src/applications/audit/editor/PhabricatorAuditEditor.php +++ b/src/applications/audit/editor/PhabricatorAuditEditor.php @@ -485,7 +485,8 @@ final class PhabricatorAuditEditor return $phids; } - protected function getObjectLinkButtonLabelForMail() { + protected function getObjectLinkButtonLabelForMail( + PhabricatorLiskDAO $object) { return pht('View Commit'); } diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php index 090592046b..88f13ff828 100644 --- a/src/applications/differential/editor/DifferentialTransactionEditor.php +++ b/src/applications/differential/editor/DifferentialTransactionEditor.php @@ -601,7 +601,8 @@ final class DifferentialTransactionEditor return $xactions; } - protected function getObjectLinkButtonLabelForMail() { + protected function getObjectLinkButtonLabelForMail( + PhabricatorLiskDAO $object) { return pht('View Revision'); } @@ -614,8 +615,7 @@ final class DifferentialTransactionEditor $body = id(new PhabricatorMetaMTAMailBody()) ->setViewer($viewer); - $revision_uri = $object->getURI(); - $revision_uri = PhabricatorEnv::getProductionURI($revision_uri); + $revision_uri = $this->getObjectLinkButtonURIForMail($object); $new_uri = $revision_uri.'/new/'; $this->addHeadersAndCommentsToMailBody( diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php index f7e5e25a40..6255903eff 100644 --- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php +++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php @@ -206,7 +206,8 @@ final class ManiphestTransactionEditor ->setSubject("T{$id}: {$title}"); } - protected function getObjectLinkButtonLabelForMail() { + protected function getObjectLinkButtonLabelForMail( + PhabricatorLiskDAO $object) { return pht('View Task'); } diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index bcce014669..da5e4d3634 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -3423,17 +3423,39 @@ abstract class PhabricatorApplicationTransactionEditor ->setContextObject($object); $button_label = $this->getObjectLinkButtonLabelForMail($object); + $button_uri = $this->getObjectLinkButtonURIForMail($object); + + $this->addHeadersAndCommentsToMailBody( + $body, + $xactions, + $button_label, + $button_uri); - $this->addHeadersAndCommentsToMailBody($body, $xactions, $button_label); $this->addCustomFieldsToMailBody($body, $object, $xactions); return $body; } - protected function getObjectLinkButtonLabelForMail() { + protected function getObjectLinkButtonLabelForMail( + PhabricatorLiskDAO $object) { return null; } + protected function getObjectLinkButtonURIForMail( + PhabricatorLiskDAO $object) { + + // Most objects define a "getURI()" method which does what we want, but + // this isn't formally part of an interface at time of writing. Try to + // call the method, expecting an exception if it does not exist. + + try { + $uri = $object->getURI(); + return PhabricatorEnv::getProductionURI($uri); + } catch (Exception $ex) { + return null; + } + } + /** * @task mail */ @@ -3455,7 +3477,7 @@ abstract class PhabricatorApplicationTransactionEditor PhabricatorMetaMTAMailBody $body, array $xactions, $object_label = null, - $object_href = null) { + $object_uri = null) { // First, remove transactions which shouldn't be rendered in mail. foreach ($xactions as $key => $xaction) { @@ -3521,7 +3543,7 @@ abstract class PhabricatorApplicationTransactionEditor $headers_html = phutil_implode_html(phutil_tag('br'), $headers_html); $header_button = null; - if ($object_label !== null) { + if ($object_label !== null && $object_uri !== null) { $button_style = array( 'text-decoration: none;', 'padding: 4px 8px;', @@ -3540,7 +3562,7 @@ abstract class PhabricatorApplicationTransactionEditor 'a', array( 'style' => implode(' ', $button_style), - 'href' => $object_href, + 'href' => $object_uri, ), $object_label); }