Configuration > Smart Links Settings; the form shows it * as a reminder (getShortLinkDomain(), without the scheme). */ final class SmartLinkShortUrlBuilder { public const PATH_PREFIX = '/l/'; public function __construct( private readonly CoreParametersHelper $coreParametersHelper, ) { } /** * The configured short link domain, without scheme or trailing slash, for example lnk.example.com. * Empty when nothing is configured yet. */ public function getShortLinkDomain(): string { $stored = $this->coreParametersHelper->get(SmartLinksConfigType::CONFIG_PARAMETER, []); // Upgrades from < 0.5.0 keep the domain in local.php under the legacy key; serve it until // the Configuration page is saved again (which writes the new key). if (!is_array($stored) || '' === trim((string) ($stored['short_link_domain'] ?? ''))) { $legacy = $this->coreParametersHelper->get(SmartLinksConfigType::LEGACY_CONFIG_PARAMETER, []); if (is_array($legacy) && '' !== trim((string) ($legacy['short_link_domain'] ?? ''))) { $stored = $legacy; } } $domain = trim(is_array($stored) ? (string) ($stored['short_link_domain'] ?? '') : ''); return '' === $domain ? '' : rtrim($domain, '/'); } /** * The short link of a Smart Link, for example https://lnk.example.com/l/ab3x. * Empty when no domain is configured, or when the link has no slug yet. */ public function buildShortUrl(SmartLink $smartLink): string { return $this->buildShortUrlFromSlug((string) ($smartLink->getSlug() ?? '')); } /** * Same as buildShortUrl(), for a slug that was just typed in the form (live preview). */ public function buildShortUrlFromSlug(string $slug): string { $slug = trim($slug); $domain = $this->getShortLinkDomain(); if ('' === $domain || '' === $slug) { return ''; } return 'https://'.$domain.self::PATH_PREFIX.$slug; } }