From 54e2e0f69ad7eb4bfd0c1c51474c9861db4b33f1 Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Fri, 19 Jul 2013 14:45:34 +0200 Subject: [PATCH] Split the code to generate a proper URL/link from setTitleLink() The reason I'm splitting this is that, not only do I want to create a link to the 'title', but also for another param (in my case: link to the AFTv5 permalink page) Change-Id: I834b50ca144e7d08db830726480da19e1b406a27 --- formatters/BasicFormatter.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/formatters/BasicFormatter.php b/formatters/BasicFormatter.php index 6e56f3b6d..3b8be4a25 100644 --- a/formatters/BasicFormatter.php +++ b/formatters/BasicFormatter.php @@ -434,8 +434,22 @@ class EchoBasicFormatter extends EchoNotificationFormatter { return; } - $title = $event->getTitle(); + if ( !isset( $props['fragment'] ) ) { + $props['fragment'] = $this->formatSubjectAnchor( $event ); + } + $link = $this->buildLinkParam( $event->getTitle(), $props ); + $message->params( $link ); + } + + /** + * Build a link, to be used as message parameter, based on output format and + * passed properties. Return value of this function can be used as parameter + * for Message::params() + * $title Title + * $props array + */ + protected function buildLinkParam( $title, $props = array() ) { $param = array(); if ( isset( $props['param'] ) ) { $param = (array)$props['param']; @@ -443,10 +457,8 @@ class EchoBasicFormatter extends EchoNotificationFormatter { if ( isset( $props['fragment'] ) ) { $fragment = $props['fragment']; - } else { - $fragment = $this->formatSubjectAnchor( $event ); + $title->setFragment( "#$fragment" ); } - $title->setFragment( "#$fragment" ); if ( in_array( $this->outputFormat, array( 'html', 'flyout', 'htmlemail' ) ) ) { $attribs = array(); @@ -465,12 +477,12 @@ class EchoBasicFormatter extends EchoNotificationFormatter { $options = array( 'https' ); } - $message->rawParams( Linker::link( $title, $linkText, $attribs, $param, $options ) ); + return array( Message::rawParam( Linker::link( $title, $linkText, $attribs, $param, $options ) ) ); } elseif ( $this->outputFormat === 'email' ) { $url = $title->getFullURL( $param, false, PROTO_HTTPS ); - $message->params( $this->sanitizeEmailLink( $url ) ); + return $this->sanitizeEmailLink( $url ); } else { - $message->params( $title->getFullURL( $param ) ); + return $title->getFullURL( $param ); } }