Allow open in new tab for side bar links

This commit is contained in:
Pig Fang 2019-06-29 00:07:40 +08:00
parent cd84f1f8a6
commit 5229340412
3 changed files with 6 additions and 3 deletions

View File

@ -18,7 +18,8 @@ class Hook
* [
* 'title' => 'Title', # will be translated by translator
* 'link' => 'user/config', # route link
* 'icon' => 'fa-book' # font-awesome icon
* 'icon' => 'fa-book', # font-awesome icon
* 'new-tab' => false, # open the link in new tab or not, false by default
* ]
* @return void
*/

View File

@ -166,8 +166,9 @@ if (! function_exists('bs_menu')) {
} else {
if ($value) {
$content .= sprintf(
'<a href="%s"><i class="%s %s"></i> &nbsp;<span>%s</span></a>',
'<a href="%s" %s><i class="%s %s"></i> &nbsp;<span>%s</span></a>',
url((string) $value['link']),
Arr::get($value, 'new-tab') ? 'target="_blank"' : '',
$value['icon'] == 'fa-circle' ? 'far' : 'fas',
(string) $value['icon'],
trans((string) $value['title'])

View File

@ -16,11 +16,12 @@ class HookTest extends TestCase
'title' => 'Link A',
'link' => '/to/a',
'icon' => 'fa-book',
'new-tab' => true,
]);
$this->actAs('normal')
->get('/user')
->assertSee('Link A')
->assertSee('/to/a')
->assertSee('/to/a" target="_blank"')
->assertSee('fa-book');
// Out of bound