Skip to content

Commit f571343

Browse files
committed
Simplify
1 parent 465ee95 commit f571343

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/View/Helper/TextHelper.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,28 +199,29 @@ protected function _linkUrls(string $text, array $htmlOptions): string {
199199
}
200200

201201
/**
202-
* @param string $link
202+
* @param string $name
203203
* @param array $options Options:
204204
* - stripProtocol: bool (defaults to true)
205205
* - maxLength: int (defaults to 50)
206206
* - ellipsis (defaults to UTF8 version)
207+
*
207208
* @return string html/$plain
208209
*/
209-
public function prepareLinkName(string $link, array $options = []): string {
210+
public function prepareLinkName(string $name, array $options = []): string {
210211
// strip protocol if desired (default)
211212
if (!isset($options['stripProtocol']) || $options['stripProtocol'] !== false) {
212-
$link = $this->stripProtocol($link);
213+
$name = (string)preg_replace('(^https?://)', '', $name);
213214
}
214215
if (!isset($options['maxLength'])) {
215216
$options['maxLength'] = 50; # should be long enough for most cases
216217
}
217218
// shorten display name if desired (default)
218-
if (!empty($options['maxLength']) && mb_strlen($link) > $options['maxLength']) {
219-
$link = mb_substr($link, 0, $options['maxLength']);
220-
$link .= $options['ellipsis'] ?? '';
219+
if (!empty($options['maxLength']) && mb_strlen($name) > $options['maxLength']) {
220+
$name = mb_substr($name, 0, $options['maxLength']);
221+
$name .= $options['ellipsis'] ?? '';
221222
}
222223

223-
return $link;
224+
return $name;
224225
}
225226

226227
}

0 commit comments

Comments
 (0)