Fix for RichEditor root page links being returned with empty hrefs. (#3085)

Fixes issue found in https://github.com/octobercms/october/issues/3064#issuecomment-326008148, specifically 2nd bullet point. Credit to @joltmode.
This commit is contained in:
Tom 2019-04-19 21:46:13 +03:00 committed by Luke Towers
parent 57d54eb882
commit 04bf359d8c
1 changed files with 7 additions and 0 deletions

View File

@ -224,6 +224,13 @@ class RichEditor extends FormWidgetBase
$linkUrl = substr($linkUrl, strlen($baseUrl));
}
/*
* Root page fallback.
*/
if (strlen($linkUrl) === 0) {
$linkUrl = '/';
}
$linkName = str_repeat(' ', $level * 4);
$linkName .= is_array($link) ? array_get($link, 'title', '') : $link;
$result[] = ['name' => $linkName, 'url' => $linkUrl];