Commit ce4bf844 by Alexey Kolmakov Committed by Alexander Makarov

#5467 Allow pass options to Html:a in Formatter:asUrl

parent 6c6afd3f
......@@ -359,9 +359,10 @@ class Formatter extends Component
/**
* Formats the value as a hyperlink.
* @param mixed $value the value to be formatted.
* @param array $options the tag options in terms of name-value pairs. See [[Html::a()]].
* @return string the formatted result.
*/
public function asUrl($value)
public function asUrl($value, $options = [])
{
if ($value === null) {
return $this->nullDisplay;
......@@ -371,7 +372,7 @@ class Formatter extends Component
$url = 'http://' . $url;
}
return Html::a(Html::encode($value), $url);
return Html::a(Html::encode($value), $url, $options);
}
/**
......
......@@ -158,6 +158,8 @@ class FormatterTest extends TestCase
$this->assertSame("<a href=\"http://$value\">$value</a>", $this->formatter->asUrl($value));
$value = 'https://www.yiiframework.com/?name=test&value=5"';
$this->assertSame("<a href=\"https://www.yiiframework.com/?name=test&amp;value=5&quot;\">https://www.yiiframework.com/?name=test&amp;value=5&quot;</a>", $this->formatter->asUrl($value));
$value = 'http://www.yiiframework.com/';
$this->assertSame("<a href=\"$value\" target=\"_blank\">$value</a>", $this->formatter->asUrl($value, ['target' => '_blank']));
// null display
$this->assertSame($this->formatter->nullDisplay, $this->formatter->asUrl(null));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment