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 keep the domain in local.php under a legacy key (the standalone // SmartlinksBundle wrote `smartlinks_config`, the UtmManagerBundle before it // `utm_manager_smart_links`); serve it until the Configuration page is saved again. $legacyKeys = [ SmartLinksConfigType::LEGACY_SMARTLINKS_PARAMETER, SmartLinksConfigType::LEGACY_CONFIG_PARAMETER, ]; foreach ($legacyKeys as $legacyKey) { if (!is_array($stored) || '' === trim((string) ($stored['short_link_domain'] ?? ''))) { $legacy = $this->coreParametersHelper->get($legacyKey, []); 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; } }