- {{ include('@MauticCore/Components/content-block.html.twig', {
- 'heading': 'mt3s.marketing_program.utm_taxonomy.onboarding.heading',
- 'subheading': 'mt3s.marketing_program.utm_taxonomy.onboarding.subheading',
- 'copy': 'mt3s.marketing_program.utm_taxonomy.onboarding.copy',
- }) }}
+
+ {# The toolbar belongs to the full page only: ajax reloads (sort, filter, pagination)
+ replace the contents of .page-list, so including it here again would duplicate it. #}
+ {% if isIndex %}
+ {{- include('@MauticCore/Helper/list_toolbar.html.twig', {
+ 'searchValue': searchValue,
+ 'action': currentRoute,
+ 'page_actions': {
+ 'templateButtons': {
+ 'new': permissions[permissionBase ~ ':create'],
+ },
+ 'langVar': 'smartlinks.taxonomies',
+ 'routeBase': 'utm_taxonomies',
+ },
+ 'bulk_actions': {
+ 'langVar': 'smartlinks.taxonomies',
+ 'templateButtons': {
+ 'delete': permissions[permissionBase ~ ':deleteown'] or permissions[permissionBase ~ ':deleteother'],
+ },
+ },
+ }) -}}
+ {% endif %}
+
+ {% if items is defined and items is not empty %}
+
+
+
+
+ {{ include('@MauticCore/Helper/tableheader.html.twig', {
+ 'checkall': 'true',
+ 'target': '#utmTaxonomyTable',
+ }) }}
+ {# Columns: Name, Description, Parameters, Date added. #}
+ {{ include('@MauticCore/Helper/tableheader.html.twig', {
+ 'sessionVar': sessionVar,
+ 'orderBy': tablePrefix ~ '.name',
+ 'text': 'mautic.smartlinks.taxonomies.name',
+ 'class': 'col-utm-taxonomy-name',
+ 'default': true,
+ }) }}
+ {{ include('@MauticCore/Helper/tableheader.html.twig', {
+ 'sessionVar': sessionVar,
+ 'orderBy': tablePrefix ~ '.description',
+ 'text': 'mautic.smartlinks.taxonomies.description',
+ 'class': 'visible-md visible-lg col-utm-taxonomy-description',
+ }) }}
+ {{ include('@MauticCore/Helper/tableheader.html.twig', {
+ 'sessionVar': sessionVar,
+ 'text': 'mautic.smartlinks.taxonomies.parameter_count',
+ 'class': 'visible-md visible-lg col-utm-taxonomy-parameters',
+ }) }}
+ {{ include('@MauticCore/Helper/tableheader.html.twig', {
+ 'sessionVar': sessionVar,
+ 'orderBy': tablePrefix ~ '.dateAdded',
+ 'text': 'mautic.core.date.added',
+ 'class': 'visible-md visible-lg col-utm-taxonomy-date',
+ }) }}
+
+
+
+ {% for item in items %}
+ {% set canEdit = securityHasEntityAccess(permissions[permissionBase ~ ':editown'], permissions[permissionBase ~ ':editother'], item.createdBy) %}
+
+ |
+ {{- include('@MauticCore/Helper/list_actions.html.twig', {
+ 'item': item,
+ 'templateButtons': {
+ 'edit': canEdit,
+ 'delete': securityHasEntityAccess(permissions[permissionBase ~ ':deleteown'], permissions[permissionBase ~ ':deleteother'], item.createdBy),
+ },
+ 'langVar': 'smartlinks.taxonomies',
+ 'routeBase': 'utm_taxonomies',
+ }) -}}
+ |
+
+ {% if canEdit %}
+ {{ item.name }}
+ {% else %}
+ {{ item.name }}
+ {% endif %}
+ |
+
+ {{ item.description|default('—')|slice(0, 120) }}
+ |
+
+
+ {{ item.parameters|length }}
+
+ |
+ {{ dateToFull(item.dateAdded) }} |
+
+ {% endfor %}
+
+
+
+
+ {% elseif searchValue is not empty %}
+ {{ include('@MauticCore/Helper/noresults.html.twig') }}
+ {% else %}
+
+ {{ include('@MauticCore/Components/content-block.html.twig', {
+ 'heading': 'mautic.smartlinks.taxonomies.onboarding.heading',
+ 'subheading': 'mautic.smartlinks.taxonomies.onboarding.subheading',
+ 'copy': 'mautic.smartlinks.taxonomies.onboarding.copy',
+ }) }}
+
+ {% endif %}
{% endblock %}
diff --git a/Security/Permissions/MT3SMarketingProgramPermissions.php b/Security/Permissions/MT3SMarketingProgramPermissions.php
index 046ab86..f2561cd 100644
--- a/Security/Permissions/MT3SMarketingProgramPermissions.php
+++ b/Security/Permissions/MT3SMarketingProgramPermissions.php
@@ -29,6 +29,8 @@ class MT3SMarketingProgramPermissions extends AbstractPermissions
$this->addExtendedPermissions('tasks');
$this->addExtendedPermissions('stakeholders');
$this->addExtendedPermissions('audiences');
+ $this->addExtendedPermissions('smart_links');
+ $this->addExtendedPermissions('taxonomies');
$this->addStandardPermissions('itemtypes');
}
@@ -48,6 +50,8 @@ class MT3SMarketingProgramPermissions extends AbstractPermissions
$this->addExtendedFormFields('mt3smarketingprogram', 'tasks', $builder, $data);
$this->addExtendedFormFields('mt3smarketingprogram', 'stakeholders', $builder, $data);
$this->addExtendedFormFields('mt3smarketingprogram', 'audiences', $builder, $data);
+ $this->addExtendedFormFields('mt3smarketingprogram', 'smart_links', $builder, $data);
+ $this->addExtendedFormFields('mt3smarketingprogram', 'taxonomies', $builder, $data);
$this->addStandardFormFields('mt3smarketingprogram', 'itemtypes', $builder, $data);
}
}
diff --git a/Service/SmartLinkShortUrlBuilder.php b/Service/SmartLinkShortUrlBuilder.php
new file mode 100644
index 0000000..3818c49
--- /dev/null
+++ b/Service/SmartLinkShortUrlBuilder.php
@@ -0,0 +1,70 @@
+ 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;
+ }
+}
diff --git a/Service/UtmConfigurationNormalizer.php b/Service/UtmConfigurationNormalizer.php
new file mode 100644
index 0000000..e789a91
--- /dev/null
+++ b/Service/UtmConfigurationNormalizer.php
@@ -0,0 +1,136 @@
+, default?: ?string}
+ * @phpstan-type UtmConfig array{enforce_lowercase: bool, separator_replacement: string, parameters: array
}
+ */
+final class UtmConfigurationNormalizer
+{
+ public const SEPARATORS = ['-', '_', '.'];
+ public const DEFAULT_SEPARATOR = '-';
+
+ public function __construct(
+ private readonly UtmParameterCatalog $catalog,
+ ) {
+ }
+
+ /**
+ * @return UtmConfig
+ */
+ public function normalize(mixed $raw): array
+ {
+ $raw = is_array($raw) ? $raw : [];
+ $separator = $raw['separator_replacement'] ?? self::DEFAULT_SEPARATOR;
+ $stored = is_array($raw['parameters'] ?? null) ? $raw['parameters'] : [];
+
+ $parameters = [];
+ foreach ($this->catalog->all() as $key => $definition) {
+ $parameters[$key] = $this->normalizeParameter($stored[$key] ?? null, $definition);
+ }
+
+ foreach ($stored as $key => $parameter) {
+ $key = (string) $key;
+ if (isset($parameters[$key]) || !$this->catalog->isValidCustomKey($key)) {
+ continue;
+ }
+
+ $parameters[$key] = $this->normalizeParameter($parameter, null);
+ }
+
+ return [
+ 'enforce_lowercase' => array_key_exists('enforce_lowercase', $raw) ? self::toBool($raw['enforce_lowercase']) : true,
+ 'separator_replacement' => in_array($separator, self::SEPARATORS, true) ? $separator : self::DEFAULT_SEPARATOR,
+ 'parameters' => $parameters,
+ ];
+ }
+
+ /**
+ * @return UtmParameter
+ */
+ private function normalizeParameter(mixed $stored, ?UtmParameterDefinition $definition): array
+ {
+ $defaultMode = $definition?->defaultMode ?? UtmParameterMode::DISABLED;
+ $allowedModes = $definition?->getAllowedModes() ?? UtmParameterMode::ALL;
+
+ if (!is_array($stored)) {
+ // Free parameters start enabled. Dropdown parameters start switched off: an enabled dropdown
+ // needs values, and an invalid default would block saving the whole Configuration page.
+ $stored = ['enabled' => UtmParameterMode::FREE === $defaultMode, 'mode' => $defaultMode];
+ }
+
+ $mode = (string) ($stored['mode'] ?? $defaultMode);
+ if (!in_array($mode, $allowedModes, true)) {
+ $mode = $defaultMode;
+ }
+
+ $parameter = [
+ 'enabled' => self::toBool($stored['enabled'] ?? false),
+ 'label' => trim((string) ($stored['label'] ?? '')),
+ 'mode' => $mode,
+ ];
+
+ if (UtmParameterMode::DROPDOWN !== $mode) {
+ return $parameter;
+ }
+
+ $values = $this->normalizeValues($stored['values'] ?? []);
+ $default = (string) ($stored['default'] ?? '');
+
+ $parameter['values'] = $values;
+ $parameter['default'] = in_array($default, array_column($values, 'value'), true) ? $default : null;
+
+ return $parameter;
+ }
+
+ /**
+ * @return list
+ */
+ private function normalizeValues(mixed $values): array
+ {
+ if (!is_array($values)) {
+ return [];
+ }
+
+ $normalized = [];
+ foreach ($values as $row) {
+ if (!is_array($row)) {
+ continue;
+ }
+
+ $value = trim((string) ($row['value'] ?? ''));
+ if ('' === $value || isset($normalized[$value])) {
+ continue;
+ }
+
+ $label = trim((string) ($row['label'] ?? ''));
+ $normalized[$value] = ['value' => $value, 'label' => '' !== $label ? $label : $value];
+ }
+
+ return array_values($normalized);
+ }
+
+ public static function toBool(mixed $value): bool
+ {
+ if (is_string($value)) {
+ return in_array(strtolower(trim($value)), ['1', 'true', 'yes', 'on'], true);
+ }
+
+ return (bool) $value;
+ }
+}
diff --git a/Service/UtmConfigurationProvider.php b/Service/UtmConfigurationProvider.php
new file mode 100644
index 0000000..42fafdc
--- /dev/null
+++ b/Service/UtmConfigurationProvider.php
@@ -0,0 +1,128 @@
+>
+ */
+ public function getEnabledParameters(): array
+ {
+ $enabled = [];
+ foreach ($this->getConfig()['parameters'] as $key => $parameter) {
+ if ($parameter['enabled'] && UtmParameterMode::DISABLED !== $parameter['mode']) {
+ $enabled[$key] = $this->decorate($key, $parameter);
+ }
+ }
+
+ return $enabled;
+ }
+
+ /**
+ * Any catalog or custom parameter, whatever its state. Null when the key is unknown.
+ *
+ * @return array|null
+ */
+ public function getParameter(string $key): ?array
+ {
+ $parameter = $this->getConfig()['parameters'][$key] ?? null;
+
+ return null === $parameter ? null : $this->decorate($key, $parameter);
+ }
+
+ /**
+ * Allowed values of a `dropdown` parameter. Always empty for `free` and `disabled` parameters.
+ *
+ * @return list
+ */
+ public function getDropdownValues(string $key): array
+ {
+ $parameter = $this->getConfig()['parameters'][$key] ?? null;
+
+ if (null === $parameter || UtmParameterMode::DROPDOWN !== $parameter['mode']) {
+ return [];
+ }
+
+ return $parameter['values'] ?? [];
+ }
+
+ public function isLowercaseEnforced(): bool
+ {
+ return $this->getConfig()['enforce_lowercase'];
+ }
+
+ public function getSeparatorReplacement(): string
+ {
+ return $this->getConfig()['separator_replacement'];
+ }
+
+ /**
+ * @return array{enforce_lowercase: bool, separator_replacement: string, parameters: array>}
+ */
+ private function getConfig(): array
+ {
+ $raw = $this->coreParametersHelper->get(self::CONFIG_PARAMETER, []);
+
+ // Upgrades from < 0.5.0 keep their settings in local.php under the legacy key; serve them
+ // until the Configuration page is saved again (which writes the new key).
+ if (null === $raw || [] === $raw) {
+ $legacy = $this->coreParametersHelper->get(self::LEGACY_CONFIG_PARAMETER, []);
+ if (null !== $legacy && [] !== $legacy) {
+ $raw = $legacy;
+ }
+ }
+
+ return $this->normalizer->normalize($raw);
+ }
+
+ /**
+ * @param array $parameter
+ *
+ * @return array
+ */
+ private function decorate(string $key, array $parameter): array
+ {
+ $definition = $this->catalog->get($key);
+
+ if ('' === $parameter['label']) {
+ $parameter['label'] = null !== $definition ? $this->translator->trans($definition->getLabelKey()) : $key;
+ }
+
+ return ['key' => $key] + $parameter + [
+ 'group' => $definition?->group ?? UtmParameterCatalog::GROUP_CUSTOM,
+ 'custom' => null === $definition,
+ 'auto_generated' => $definition?->autoGenerated ?? false,
+ ];
+ }
+}
diff --git a/Tests/Unit/Catalog/UtmParameterCatalogTest.php b/Tests/Unit/Catalog/UtmParameterCatalogTest.php
new file mode 100644
index 0000000..ffa7772
--- /dev/null
+++ b/Tests/Unit/Catalog/UtmParameterCatalogTest.php
@@ -0,0 +1,147 @@
+ UtmParameterMode::DROPDOWN,
+ 'utm_medium' => UtmParameterMode::DROPDOWN,
+ 'utm_campaign' => UtmParameterMode::FREE,
+ 'utm_term' => UtmParameterMode::FREE,
+ 'utm_content' => UtmParameterMode::FREE,
+ 'utm_id' => UtmParameterMode::FREE,
+ 'utm_source_platform' => UtmParameterMode::DROPDOWN,
+ 'utm_creative_format' => UtmParameterMode::DROPDOWN,
+ 'utm_marketing_tactic' => UtmParameterMode::DROPDOWN,
+ ];
+
+ private const PLATFORM_KEYS = ['gclid', 'gbraid', 'wbraid', 'dclid', 'fbclid', 'msclkid', 'ttclid', 'li_fat_id', 'twclid', 'epik'];
+
+ private UtmParameterCatalog $catalog;
+
+ protected function setUp(): void
+ {
+ $this->catalog = new UtmParameterCatalog();
+ }
+
+ public function testCatalogContainsExactlyTheExpectedKeysInOrder(): void
+ {
+ $this->assertSame(
+ array_merge(array_keys(self::STANDARD_MODES), self::PLATFORM_KEYS),
+ array_keys($this->catalog->all())
+ );
+ }
+
+ public function testStandardParameters(): void
+ {
+ $standard = $this->catalog->getByGroup(UtmParameterCatalog::GROUP_STANDARD);
+ $this->assertSame(array_keys(self::STANDARD_MODES), array_keys($standard));
+
+ foreach (self::STANDARD_MODES as $key => $mode) {
+ $definition = $standard[$key];
+ $this->assertSame($mode, $definition->defaultMode, $key);
+ $this->assertFalse($definition->autoGenerated, $key);
+ $this->assertSame(UtmParameterMode::ALL, $definition->getAllowedModes(), $key);
+ $this->assertSame('mautic.smartlinks.config.parameter.'.$key.'.label', $definition->getLabelKey());
+ $this->assertSame('mautic.smartlinks.config.parameter.'.$key.'.description', $definition->getDescriptionKey());
+ }
+ }
+
+ public function testPlatformParametersAreAutoGeneratedDisabledAndCannotBeDropdowns(): void
+ {
+ $platform = $this->catalog->getByGroup(UtmParameterCatalog::GROUP_PLATFORM);
+ $this->assertSame(self::PLATFORM_KEYS, array_keys($platform));
+
+ foreach ($platform as $key => $definition) {
+ $this->assertTrue($definition->autoGenerated, $key);
+ $this->assertSame(UtmParameterMode::DISABLED, $definition->defaultMode, $key);
+ $this->assertSame([UtmParameterMode::FREE, UtmParameterMode::DISABLED], $definition->getAllowedModes(), $key);
+ $this->assertFalse($definition->isModeAllowed(UtmParameterMode::DROPDOWN), $key);
+ $this->assertSame([], $definition->suggestions, $key);
+ }
+ }
+
+ public function testSuggestionsOnlyForDropdownParameters(): void
+ {
+ $this->assertSame(
+ ['newsletter', 'linkedin', 'facebook', 'instagram', 'google', 'youtube', 'x', 'tiktok', 'partner', 'direct'],
+ $this->catalog->get('utm_source')?->suggestions
+ );
+ $this->assertSame(
+ ['email', 'cpc', 'social', 'social_paid', 'display', 'affiliate', 'referral', 'qr', 'sms', 'print', 'event'],
+ $this->catalog->get('utm_medium')?->suggestions
+ );
+ $this->assertSame(['google_ads', 'meta_ads', 'linkedin_ads', 'microsoft_ads', 'tiktok_ads'], $this->catalog->get('utm_source_platform')?->suggestions);
+ $this->assertSame(['banner', 'video', 'carousel', 'text', 'native'], $this->catalog->get('utm_creative_format')?->suggestions);
+ $this->assertSame(['prospecting', 'remarketing', 'retargeting', 'brand', 'nurturing'], $this->catalog->get('utm_marketing_tactic')?->suggestions);
+
+ foreach ($this->catalog->all() as $key => $definition) {
+ if (UtmParameterMode::DROPDOWN !== $definition->defaultMode) {
+ $this->assertSame([], $definition->suggestions, $key);
+ }
+ }
+
+ $this->assertSame('mautic.smartlinks.config.suggestion.google_ads', UtmParameterDefinition::getSuggestionLabelKey('google_ads'));
+ }
+
+ public function testGetAndHas(): void
+ {
+ $this->assertTrue($this->catalog->has('utm_source'));
+ $this->assertInstanceOf(UtmParameterDefinition::class, $this->catalog->get('gclid'));
+ $this->assertFalse($this->catalog->has('my_param'));
+ $this->assertNull($this->catalog->get('my_param'));
+ }
+
+ #[DataProvider('reservedKeys')]
+ public function testReservedKeys(string $key): void
+ {
+ $this->assertTrue($this->catalog->isReservedKey($key));
+ $this->assertFalse($this->catalog->isValidCustomKey($key));
+ }
+
+ /**
+ * @return iterable
+ */
+ public static function reservedKeys(): iterable
+ {
+ yield 'catalog key' => ['utm_source'];
+ yield 'click id' => ['gclid'];
+ yield 'mautic click tracking' => ['ct'];
+ yield 'utm prefix' => ['utm_custom'];
+ yield 'utm prefix without underscore' => ['utmx'];
+ yield 'mtc prefix' => ['mtc_id'];
+ }
+
+ #[DataProvider('customKeys')]
+ public function testCustomKeyFormat(string $key, bool $valid): void
+ {
+ $this->assertSame($valid, $this->catalog->isValidCustomKey($key));
+ }
+
+ /**
+ * @return iterable
+ */
+ public static function customKeys(): iterable
+ {
+ yield 'simple' => ['ref', true];
+ yield 'with digits and underscore' => ['partner_id2', true];
+ yield 'two characters' => ['ab', true];
+ yield 'max 41 characters' => ['a'.str_repeat('b', 40), true];
+ yield 'one character' => ['a', false];
+ yield 'too long' => ['a'.str_repeat('b', 41), false];
+ yield 'starts with digit' => ['1abc', false];
+ yield 'starts with underscore' => ['_abc', false];
+ yield 'uppercase' => ['Abc', false];
+ yield 'hyphen' => ['my-param', false];
+ yield 'empty' => ['', false];
+ }
+}
diff --git a/Tests/Unit/Entity/SmartLinkHitTest.php b/Tests/Unit/Entity/SmartLinkHitTest.php
new file mode 100644
index 0000000..0db7a3e
--- /dev/null
+++ b/Tests/Unit/Entity/SmartLinkHitTest.php
@@ -0,0 +1,29 @@
+setSmartLink($link);
+ $hit->setIpAddress('2001:db8::1');
+ $hit->setReferer('https://newsletter.example.com/');
+ $hit->setUserAgent('curl/8.18.0');
+
+ $this->assertSame($link, $hit->getSmartLink());
+ $this->assertSame('2001:db8::1', $hit->getIpAddress());
+ $this->assertSame('https://newsletter.example.com/', $hit->getReferer());
+ $this->assertSame('curl/8.18.0', $hit->getUserAgent());
+ $this->assertNull($hit->getId());
+ }
+}
diff --git a/Tests/Unit/Entity/SmartLinkTest.php b/Tests/Unit/Entity/SmartLinkTest.php
new file mode 100644
index 0000000..ca93042
--- /dev/null
+++ b/Tests/Unit/Entity/SmartLinkTest.php
@@ -0,0 +1,82 @@
+setSlug('abc');
+
+ // Not saved yet: the slug can still be set.
+ $link->setSlug('xyz');
+ $this->assertSame('xyz', $link->getSlug());
+
+ $reflection = new \ReflectionClass(SmartLink::class);
+ $property = $reflection->getProperty('id');
+ $property->setValue($link, 1);
+
+ // Saved: the same slug is accepted (no-op), a different one is refused.
+ $link->setSlug('xyz');
+ $this->assertSame('xyz', $link->getSlug());
+
+ $this->expectException(\LogicException::class);
+ $link->setSlug('other');
+ }
+
+ public function testMauticRedirectHasNoDestination(): void
+ {
+ $link = new SmartLink();
+ $link->setRedirectType(SmartLinkRedirectType::External);
+ $link->setDestinationUrl('https://www.example.com');
+ $this->assertSame('https://www.example.com', $link->getDestinationUrl());
+
+ $link->setRedirectType(SmartLinkRedirectType::Mautic);
+ $this->assertNull($link->getDestinationUrl());
+ }
+
+ public function testBlankDestinationIsNormalizedToNull(): void
+ {
+ $link = new SmartLink();
+ $link->setDestinationUrl(' ');
+ $this->assertNull($link->getDestinationUrl());
+ }
+
+ public function testUtmParametersAreStoredAsGiven(): void
+ {
+ // The model (normalizeUtmValues) cleans the values before they reach the entity.
+ $link = new SmartLink();
+ $link->setUtmParameters(['utm_source' => 'newsletter']);
+ $this->assertSame(['utm_source' => 'newsletter'], $link->getUtmParameters());
+
+ $link->setUtmParameters(null);
+ $this->assertSame([], $link->getUtmParameters());
+ }
+
+ public function testShortLinkIsBuiltFromDomainAndSlug(): void
+ {
+ $link = new SmartLink();
+ $link->setSlug('ab3x');
+
+ $this->assertSame('https://lnk.example.com/l/ab3x', $link->getShortLink('lnk.example.com'));
+ $this->assertSame('https://lnk.example.com/l/ab3x', $link->getShortLink('lnk.example.com/'));
+ $this->assertSame('', $link->getShortLink(''));
+ }
+
+ public function testRedirectEnums(): void
+ {
+ $this->assertTrue(SmartLinkRedirectType::External->isExternal());
+ $this->assertTrue(SmartLinkRedirectType::Mautic->isMautic());
+ $this->assertSame(SmartLinkRedirectCode::MovedPermanently, SmartLinkRedirectCode::tryFrom(301));
+ $this->assertSame(SmartLinkRedirectCode::PermanentRedirect, SmartLinkRedirectCode::tryFrom(308));
+ $this->assertNull(SmartLinkRedirectCode::tryFrom(418));
+ }
+}
diff --git a/Tests/Unit/Form/SmartlinksSettingsTypeTest.php b/Tests/Unit/Form/SmartlinksSettingsTypeTest.php
new file mode 100644
index 0000000..e60c5cf
--- /dev/null
+++ b/Tests/Unit/Form/SmartlinksSettingsTypeTest.php
@@ -0,0 +1,275 @@
+submit($this->defaultSubmission());
+
+ $this->assertTrue($form->isSynchronized());
+ $this->assertSame([], $this->errorMessages($form));
+
+ $data = $form->getData();
+ $this->assertTrue($data['enforce_lowercase']);
+ $this->assertSame('-', $data['separator_replacement']);
+ $this->assertSame(['enabled' => true, 'label' => 'mautic.smartlinks.config.parameter.utm_campaign.label', 'mode' => 'free'], $data['parameters']['utm_campaign']);
+ $this->assertSame(['enabled' => false, 'label' => 'mautic.smartlinks.config.parameter.gclid.label', 'mode' => 'disabled'], $data['parameters']['gclid']);
+ $this->assertSame(['enabled', 'label', 'mode', 'values', 'default'], array_keys($data['parameters']['utm_source']));
+ }
+
+ public function testValuesSubmittedForAFreeParameterAreIgnored(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['parameters']['utm_source']['mode'] = 'free';
+ $submission['parameters']['utm_source']['values'] = [
+ ['value' => 'NOT VALID', 'label' => ''],
+ ['value' => 'NOT VALID', 'label' => ''],
+ ];
+
+ $form = $this->submit($submission);
+
+ $this->assertSame([], $this->errorMessages($form));
+ $this->assertSame(['enabled' => false, 'label' => 'mautic.smartlinks.config.parameter.utm_source.label', 'mode' => 'free'], $form->getData()['parameters']['utm_source']);
+ }
+
+ public function testEnabledDropdownWithoutValuesIsRejected(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['parameters']['utm_source']['enabled'] = '1';
+
+ $form = $this->submit($submission);
+
+ $this->assertSame(
+ [UtmSettingsValidator::ERROR_VALUES_REQUIRED],
+ $this->messages($form->get('parameters')->get('utm_source')->get('values'))
+ );
+ }
+
+ public function testDropdownValuesAreStoredInOrderWithTheirDefault(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['parameters']['utm_source']['enabled'] = '1';
+ $submission['parameters']['utm_source']['values'] = [
+ ['value' => 'newsletter', 'label' => 'Newsletter'],
+ ['value' => 'linkedin', 'label' => 'LinkedIn', 'is_default' => '1'],
+ ];
+
+ $form = $this->submit($submission);
+
+ $this->assertSame([], $this->errorMessages($form));
+ $this->assertSame([
+ 'enabled' => true,
+ 'label' => 'mautic.smartlinks.config.parameter.utm_source.label',
+ 'mode' => 'dropdown',
+ 'values' => [
+ ['value' => 'newsletter', 'label' => 'Newsletter'],
+ ['value' => 'linkedin', 'label' => 'LinkedIn'],
+ ],
+ 'default' => 'linkedin',
+ ], $form->getData()['parameters']['utm_source']);
+ }
+
+ public function testDuplicateAndInvalidValuesAreRejected(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['parameters']['utm_medium']['enabled'] = '1';
+ $submission['parameters']['utm_medium']['values'] = [
+ ['value' => 'email', 'label' => 'Email', 'is_default' => '1'],
+ ['value' => 'email', 'label' => 'Email again', 'is_default' => '1'],
+ ['value' => 'Paid Social', 'label' => 'Paid social'],
+ ['value' => str_repeat('a', 101), 'label' => ''],
+ ];
+
+ $form = $this->submit($submission);
+ $values = $form->get('parameters')->get('utm_medium')->get('values');
+
+ $this->assertSame([UtmSettingsValidator::ERROR_VALUE_DUPLICATE, UtmSettingsValidator::ERROR_DEFAULT_MULTIPLE], $this->messages($values));
+ $this->assertSame(['mautic.smartlinks.config.error.value_invalid'], $this->messages($values->get('2')->get('value')));
+ $this->assertSame(['mautic.smartlinks.config.error.value_length'], $this->messages($values->get('3')->get('value')));
+ $this->assertSame(['mautic.smartlinks.config.error.label_required'], $this->messages($values->get('3')->get('label')));
+ }
+
+ public function testDropdownModeIsRefusedForClickIds(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['parameters']['gclid']['mode'] = 'dropdown';
+
+ $form = $this->submit($submission);
+
+ $this->assertSame(['mautic.smartlinks.config.error.mode_invalid'], $this->messages($form->get('parameters')->get('gclid')->get('mode')));
+ }
+
+ public function testCustomParameterIsStoredUnderItsKey(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['custom_parameters'][] = $this->customParameter('partner', 'free');
+
+ $form = $this->submit($submission);
+
+ $this->assertSame([], $this->errorMessages($form));
+ $this->assertSame(['enabled' => true, 'label' => 'Partner', 'mode' => 'free'], $form->getData()['parameters']['partner']);
+ }
+
+ public function testCustomKeyRules(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['custom_parameters'] = [
+ $this->customParameter('Bad-Key'),
+ $this->customParameter('utm_partner'),
+ $this->customParameter('mtc_x'),
+ $this->customParameter('ct'),
+ $this->customParameter('gclid'),
+ $this->customParameter('ref'),
+ $this->customParameter('ref'),
+ $this->customParameter(''),
+ ];
+
+ $custom = $this->submit($submission)->get('custom_parameters');
+
+ $this->assertSame([UtmSettingsValidator::ERROR_KEY_INVALID], $this->messages($custom->get('0')->get('key')));
+ foreach (['1', '2', '3', '4'] as $index) {
+ $this->assertSame([UtmSettingsValidator::ERROR_KEY_RESERVED], $this->messages($custom->get($index)->get('key')), $index);
+ }
+ $this->assertSame([UtmSettingsValidator::ERROR_KEY_DUPLICATE], $this->messages($custom->get('5')->get('key')));
+ $this->assertSame([UtmSettingsValidator::ERROR_KEY_DUPLICATE], $this->messages($custom->get('6')->get('key')));
+ $this->assertSame(['mautic.smartlinks.config.error.key_required'], $this->messages($custom->get('7')->get('key')));
+ }
+
+ public function testLabelCannotContainPercent(): void
+ {
+ $submission = $this->defaultSubmission();
+ $submission['parameters']['utm_campaign']['label'] = '50% off';
+
+ $form = $this->submit($submission);
+
+ $this->assertSame(['mautic.smartlinks.config.error.label_invalid'], $this->messages($form->get('parameters')->get('utm_campaign')->get('label')));
+ }
+
+ public function testStoredConfigurationIsLoadedIntoTheForm(): void
+ {
+ $form = $this->factory->create(SmartlinksSettingsType::class, [
+ 'enforce_lowercase' => '',
+ 'parameters' => [
+ 'utm_source' => ['enabled' => '1', 'label' => 'Src', 'mode' => 'dropdown', 'values' => [['value' => 'a', 'label' => 'A']], 'default' => 'a'],
+ 'partner' => ['enabled' => '1', 'label' => 'Partner', 'mode' => 'free'],
+ ],
+ ]);
+
+ $this->assertFalse($form->get('enforce_lowercase')->getData());
+ $this->assertSame('Src', $form->get('parameters')->get('utm_source')->get('label')->getData());
+ $this->assertSame([['value' => 'a', 'label' => 'A', 'is_default' => true]], $form->get('parameters')->get('utm_source')->get('values')->getData());
+ $this->assertSame('partner', $form->get('custom_parameters')->get('0')->get('key')->getData());
+ }
+
+ /**
+ * @param array $submission
+ *
+ * @return FormInterface
+ */
+ private function submit(array $submission): FormInterface
+ {
+ $form = $this->factory->create(SmartlinksSettingsType::class, []);
+ $form->submit($submission);
+
+ return $form;
+ }
+
+ /**
+ * What the browser posts for an untouched form.
+ *
+ * @return array
+ */
+ private function defaultSubmission(): array
+ {
+ $view = $this->factory->create(SmartlinksSettingsType::class, [])->getViewData();
+
+ $parameters = [];
+ foreach ($view['parameters'] as $key => $parameter) {
+ $parameters[$key] = [
+ 'enabled' => $parameter['enabled'] ? '1' : '0',
+ 'label' => $parameter['label'],
+ 'mode' => $parameter['mode'],
+ 'values' => [],
+ ];
+ }
+
+ return [
+ 'enforce_lowercase' => '1',
+ 'separator_replacement' => '-',
+ 'parameters' => $parameters,
+ 'custom_parameters' => [],
+ ];
+ }
+
+ /**
+ * @return array
+ */
+ private function customParameter(string $key, string $mode = 'free'): array
+ {
+ return ['key' => $key, 'enabled' => '1', 'label' => ucfirst($key) ?: 'Label', 'mode' => $mode, 'values' => []];
+ }
+
+ /**
+ * @param FormInterface $form
+ *
+ * @return string[]
+ */
+ private function messages(FormInterface $form): array
+ {
+ return array_map(
+ fn (FormError $error): string => $error->getMessageTemplate(),
+ iterator_to_array($form->getErrors())
+ );
+ }
+
+ /**
+ * @param FormInterface $form
+ *
+ * @return string[]
+ */
+ private function errorMessages(FormInterface $form): array
+ {
+ return array_map(
+ fn (FormError $error): string => $error->getOrigin()?->getName().': '.$error->getMessageTemplate(),
+ iterator_to_array($form->getErrors(true))
+ );
+ }
+}
diff --git a/Tests/Unit/Form/UtmFieldsApplicatorTest.php b/Tests/Unit/Form/UtmFieldsApplicatorTest.php
new file mode 100644
index 0000000..285b53a
--- /dev/null
+++ b/Tests/Unit/Form/UtmFieldsApplicatorTest.php
@@ -0,0 +1,267 @@
+ 'newsletter', 'label' => 'Newsletter'],
+ ['value' => 'linkedin', 'label' => 'LinkedIn'],
+ ['value' => 'google', 'label' => 'Google'],
+ ];
+
+ public function testDropdownModeRendersConfiguredValuesInOrder(): void
+ {
+ $form = $this->createForm(['utm_source' => $this->dropdown(self::SOURCE_VALUES)]);
+
+ $field = $form->get('utmSource');
+ $this->assertInstanceOf(ChoiceType::class, $field->getConfig()->getType()->getInnerType());
+ $this->assertSame(['newsletter', 'linkedin', 'google'], $field->getConfig()->getOption('choices'));
+ $this->assertSame('mautic.email.campaign_source', $field->getConfig()->getOption('label'), 'Native label kept');
+ $this->assertSame('trans:mautic.smartlinks.form.choose', $field->getConfig()->getOption('placeholder'));
+ $this->assertNull($field->getConfig()->getOption('help'));
+
+ $view = $form->createView()['utmSource'];
+ $labels = array_map(static fn ($choice): string => $choice->label, $view->vars['choices']);
+ $this->assertSame(['Newsletter', 'LinkedIn', 'Google'], array_values($labels));
+ }
+
+ public function testDropdownModeAcceptsConfiguredOrEmptyValue(): void
+ {
+ $form = $this->createForm(['utm_source' => $this->dropdown(self::SOURCE_VALUES)]);
+ $form->submit(['utmSource' => 'linkedin', 'utmMedium' => 'email']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertSame('linkedin', $form->getData()['utmSource']);
+
+ $form = $this->createForm(['utm_source' => $this->dropdown(self::SOURCE_VALUES)]);
+ $form->submit(['utmSource' => '']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertNull($form->getData()['utmSource']);
+ }
+
+ public function testDropdownModeRejectsValueOutsideTaxonomy(): void
+ {
+ $form = $this->createForm(['utm_source' => $this->dropdown(self::SOURCE_VALUES)]);
+ $form->submit(['utmSource' => 'hacked']);
+
+ $this->assertFalse($form->isValid());
+ $errors = $form->get('utmSource')->getErrors();
+ $this->assertCount(1, $errors);
+ $this->assertSame('mautic.smartlinks.form.error.not_in_taxonomy', $errors[0]->getMessageTemplate());
+ }
+
+ public function testFreeModeKeepsNativeTextField(): void
+ {
+ $form = $this->createForm(['utm_campaign' => ['enabled' => '1', 'label' => '', 'mode' => 'free']]);
+
+ $field = $form->get('utmCampaign');
+ $this->assertInstanceOf(TextType::class, $field->getConfig()->getType()->getInnerType());
+ $this->assertSame('mautic.email.campaign_name', $field->getConfig()->getOption('label'));
+
+ $form->submit(['utmCampaign' => 'Spring Sale_2026/FR']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertSame('Spring Sale_2026/FR', $form->getData()['utmCampaign'], 'Value stored as typed');
+ }
+
+ public function testDisabledModeRemovesFieldAndClearsStoredValue(): void
+ {
+ $form = $this->createForm(
+ [
+ 'utm_medium' => ['enabled' => '1', 'label' => '', 'mode' => 'disabled'],
+ 'utm_source' => ['enabled' => '1', 'label' => '', 'mode' => 'free'],
+ ],
+ ['utmMedium' => 'old-medium', 'utmSource' => 'kept'],
+ );
+
+ $this->assertFalse($form->has('utmMedium'));
+ $this->assertArrayNotHasKey('utmMedium', $form->createView()->children);
+
+ // A value posted anyway (stale page, crafted request) is ignored without an "extra fields" error.
+ $form->submit(['utmMedium' => 'posted', 'utmSource' => 'kept']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertNull($form->getData()['utmMedium']);
+ $this->assertSame('kept', $form->getData()['utmSource']);
+ }
+
+ public function testNotEnabledParameterIsTreatedAsDisabled(): void
+ {
+ $form = $this->createForm(
+ ['utm_source' => $this->dropdown(self::SOURCE_VALUES, enabled: '')],
+ ['utmSource' => 'linkedin'],
+ );
+
+ $this->assertFalse($form->has('utmSource'));
+
+ $form->submit([]);
+
+ $this->assertTrue($form->isValid());
+ $this->assertNull($form->getData()['utmSource']);
+ }
+
+ public function testLegacyValueIsOfferedAndCanBeKept(): void
+ {
+ $form = $this->createForm(['utm_source' => $this->dropdown(self::SOURCE_VALUES)], ['utmSource' => 'Old Source']);
+
+ $field = $form->get('utmSource');
+ $this->assertSame(['newsletter', 'linkedin', 'google', 'Old Source'], $field->getConfig()->getOption('choices'));
+ $this->assertSame('mautic.smartlinks.form.legacy_warning', $field->getConfig()->getOption('help'));
+
+ $view = $form->createView()['utmSource'];
+ $this->assertSame('Old Source', $view->vars['value'], 'Legacy value selected');
+ $this->assertSame('trans:mautic.smartlinks.form.legacy_choice|Old Source', end($view->vars['choices'])->label);
+
+ $form->submit(['utmSource' => 'Old Source']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertSame('Old Source', $form->getData()['utmSource'], 'Legacy value not rewritten');
+ }
+
+ public function testLegacyValueCanBeReplacedButNotByAnotherUnknownValue(): void
+ {
+ $config = ['utm_source' => $this->dropdown(self::SOURCE_VALUES)];
+
+ $form = $this->createForm($config, ['utmSource' => 'Old Source']);
+ $form->submit(['utmSource' => 'google']);
+ $this->assertTrue($form->isValid());
+ $this->assertSame('google', $form->getData()['utmSource']);
+
+ $form = $this->createForm($config, ['utmSource' => 'Old Source']);
+ $form->submit(['utmSource' => 'another-unknown']);
+ $this->assertFalse($form->isValid());
+ }
+
+ public function testNumericLegacyValueWrittenByApi(): void
+ {
+ $form = $this->createForm(['utm_source' => $this->dropdown(self::SOURCE_VALUES)], ['utmSource' => 42]);
+ $form->submit(['utmSource' => '42']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertSame('42', $form->getData()['utmSource']);
+ }
+
+ public function testEmptyDropdownListShowsOnlyEmptyChoiceAndNotice(): void
+ {
+ $form = $this->createForm(['utm_source' => $this->dropdown([])]);
+
+ $field = $form->get('utmSource');
+ $this->assertSame([], $field->getConfig()->getOption('choices'));
+ $this->assertSame('mautic.smartlinks.form.no_values', $field->getConfig()->getOption('help'));
+
+ $form->submit(['utmSource' => '']);
+ $this->assertTrue($form->isValid());
+ }
+
+ public function testCustomLabelReplacesNativeLabel(): void
+ {
+ $form = $this->createForm([
+ 'utm_source' => $this->dropdown(self::SOURCE_VALUES, label: 'Traffic source'),
+ 'utm_campaign' => ['enabled' => '1', 'label' => 'Campaign code', 'mode' => 'free'],
+ ]);
+
+ $this->assertSame('Traffic source', $form->get('utmSource')->getConfig()->getOption('label'));
+ $this->assertSame('Campaign code', $form->get('utmCampaign')->getConfig()->getOption('label'));
+ $this->assertInstanceOf(TextType::class, $form->get('utmCampaign')->getConfig()->getType()->getInnerType());
+ }
+
+ public function testDropdownOnContentKeepsNativeLengthConstraint(): void
+ {
+ $form = $this->createForm(['utm_content' => $this->dropdown([['value' => 'hero', 'label' => 'Hero']])]);
+
+ $constraints = $form->get('utmContent')->getConfig()->getOption('constraints');
+ $this->assertNotEmpty($constraints);
+ $this->assertInstanceOf(Length::class, is_array($constraints) ? $constraints[0] : $constraints);
+ }
+
+ public function testNativeFieldOrderIsKept(): void
+ {
+ $form = $this->createForm([
+ 'utm_source' => $this->dropdown(self::SOURCE_VALUES),
+ 'utm_medium' => $this->dropdown([['value' => 'email', 'label' => 'Email']]),
+ 'utm_campaign' => ['enabled' => '1', 'label' => '', 'mode' => 'free'],
+ 'utm_content' => ['enabled' => '1', 'label' => 'Variant', 'mode' => 'free'],
+ ]);
+
+ $this->assertSame(['utmSource', 'utmMedium', 'utmCampaign', 'utmContent'], array_keys($form->createView()->children));
+ }
+
+ public function testKeysWithoutNativeFieldArePreserved(): void
+ {
+ $form = $this->createForm(
+ ['utm_source' => $this->dropdown(self::SOURCE_VALUES)],
+ ['utmSource' => 'google', 'utmTerm' => 'from-api'],
+ );
+ $form->submit(['utmSource' => 'google']);
+
+ $this->assertTrue($form->isValid());
+ $this->assertSame('from-api', $form->getData()['utmTerm']);
+ }
+
+ /**
+ * @param list $values
+ *
+ * @return array
+ */
+ private function dropdown(array $values, string $enabled = '1', string $label = ''): array
+ {
+ return ['enabled' => $enabled, 'label' => $label, 'mode' => 'dropdown', 'values' => $values, 'default' => ''];
+ }
+
+ /**
+ * @param array> $parameters Stored configuration (local.php shape), other parameters keep their defaults
+ * @param array $storedTags The entity's current utmTags
+ *
+ * @return FormInterface
+ */
+ private function createForm(array $parameters, array $storedTags = []): FormInterface
+ {
+ $coreParameters = $this->createMock(CoreParametersHelper::class);
+ $coreParameters->method('get')
+ ->with(UtmConfigurationProvider::CONFIG_PARAMETER)
+ ->willReturn(['enforce_lowercase' => '', 'separator_replacement' => '_', 'parameters' => $parameters]);
+
+ // Catalog labels translate to themselves, so an empty configured label resolves to the catalog key.
+ $translator = $this->createMock(TranslatorInterface::class);
+ $translator->method('trans')->willReturnCallback(
+ static fn (string $id, array $parameters = []): string => str_starts_with($id, 'mautic.smartlinks.config.parameter.')
+ ? $id
+ : 'trans:'.$id.([] === $parameters ? '' : '|'.implode(',', $parameters))
+ );
+
+ $catalog = new UtmParameterCatalog();
+ $provider = new UtmConfigurationProvider($coreParameters, new UtmConfigurationNormalizer($catalog), $catalog, $translator);
+ $applicator = new UtmFieldsApplicator($provider, $catalog, $translator);
+
+ $factory = Forms::createFormFactoryBuilder()
+ ->addExtension(new ValidatorExtension(Validation::createValidator()))
+ ->addTypeExtension(new UtmTagsTypeExtension($applicator))
+ ->getFormFactory();
+
+ return $factory->create(EmailUtmTagsType::class, $storedTags);
+ }
+}
diff --git a/Tests/Unit/Form/UtmSettingsValidatorTest.php b/Tests/Unit/Form/UtmSettingsValidatorTest.php
new file mode 100644
index 0000000..e70a46f
--- /dev/null
+++ b/Tests/Unit/Form/UtmSettingsValidatorTest.php
@@ -0,0 +1,82 @@
+validator = new UtmSettingsValidator(new UtmParameterCatalog());
+ }
+
+ public function testCustomKeyRegex(): void
+ {
+ $this->assertSame([], $this->validator->validateCustomKey('partner_id'));
+ $this->assertSame([[UtmSettingsValidator::ERROR_KEY_INVALID, ['%key%' => 'Partner']]], $this->validator->validateCustomKey('Partner'));
+ $this->assertSame(UtmSettingsValidator::ERROR_KEY_INVALID, $this->validator->validateCustomKey('9lives')[0][0]);
+ $this->assertSame(UtmSettingsValidator::ERROR_KEY_INVALID, $this->validator->validateCustomKey('x')[0][0]);
+ }
+
+ public function testCustomKeyCollisions(): void
+ {
+ foreach (['utm_source', 'gclid', 'ct', 'utm_partner', 'mtc_id'] as $key) {
+ $this->assertSame([[UtmSettingsValidator::ERROR_KEY_RESERVED, ['%key%' => $key]]], $this->validator->validateCustomKey($key), $key);
+ }
+ }
+
+ public function testCustomKeyUniqueness(): void
+ {
+ $this->assertSame([], $this->validator->validateKeyIsUnique('ref', ['ref', 'partner']));
+ $this->assertSame(
+ [[UtmSettingsValidator::ERROR_KEY_DUPLICATE, ['%key%' => 'ref']]],
+ $this->validator->validateKeyIsUnique('ref', ['ref', 'partner', 'ref'])
+ );
+ }
+
+ public function testEnabledDropdownNeedsValues(): void
+ {
+ $this->assertSame(
+ [[UtmSettingsValidator::ERROR_VALUES_REQUIRED, []]],
+ $this->validator->validateValueList(UtmParameterMode::DROPDOWN, true, [])
+ );
+ $this->assertSame([], $this->validator->validateValueList(UtmParameterMode::DROPDOWN, false, []));
+ }
+
+ public function testDuplicateValuesAreReportedOnce(): void
+ {
+ $rows = [['value' => 'email'], ['value' => 'email'], ['value' => 'email'], ['value' => 'sms']];
+
+ $this->assertSame(
+ [[UtmSettingsValidator::ERROR_VALUE_DUPLICATE, ['%value%' => 'email']]],
+ $this->validator->validateValueList(UtmParameterMode::DROPDOWN, true, $rows)
+ );
+ }
+
+ public function testOnlyOneDefault(): void
+ {
+ $rows = [['value' => 'a', 'is_default' => true], ['value' => 'b', 'is_default' => true]];
+
+ $this->assertSame(
+ [[UtmSettingsValidator::ERROR_DEFAULT_MULTIPLE, []]],
+ $this->validator->validateValueList(UtmParameterMode::DROPDOWN, true, $rows)
+ );
+ }
+
+ public function testNothingIsCheckedOutsideDropdownMode(): void
+ {
+ $rows = [['value' => 'a', 'is_default' => true], ['value' => 'a', 'is_default' => true]];
+
+ $this->assertSame([], $this->validator->validateValueList(UtmParameterMode::FREE, true, $rows));
+ $this->assertSame([], $this->validator->validateValueList(UtmParameterMode::DISABLED, true, $rows));
+ $this->assertSame([], $this->validator->validateValueList(UtmParameterMode::FREE, true, []));
+ }
+}
diff --git a/Tests/Unit/Form/Validator/SmartLinkValidatorTest.php b/Tests/Unit/Form/Validator/SmartLinkValidatorTest.php
new file mode 100644
index 0000000..2fbcc3a
--- /dev/null
+++ b/Tests/Unit/Form/Validator/SmartLinkValidatorTest.php
@@ -0,0 +1,155 @@
+ '1',
+ 'separator_replacement' => '-',
+ 'parameters' => [
+ 'utm_source' => [
+ 'enabled' => '1', 'label' => 'Source', 'mode' => 'dropdown',
+ 'values' => [
+ ['value' => 'newsletter', 'label' => 'Newsletter'],
+ ['value' => 'linkedin', 'label' => 'LinkedIn'],
+ ],
+ ],
+ 'utm_campaign' => ['enabled' => '1', 'label' => 'Campaign', 'mode' => 'free'],
+ ],
+ ];
+
+ private function createValidator(array $raw = self::RAW_CONFIG): SmartLinkValidator
+ {
+ $parameters = $this->createMock(CoreParametersHelper::class);
+ $parameters->method('get')->willReturnMap([
+ [UtmConfigurationProvider::CONFIG_PARAMETER, [], $raw],
+ ]);
+
+ $translator = $this->createMock(TranslatorInterface::class);
+ $translator->method('trans')->willReturnCallback(fn (string $id): string => $id);
+
+ $provider = new UtmConfigurationProvider(
+ $parameters,
+ new UtmConfigurationNormalizer(new UtmParameterCatalog()),
+ new UtmParameterCatalog(),
+ $translator
+ );
+
+ return new SmartLinkValidator($this->createMock(SmartLinkModel::class), $provider);
+ }
+
+ private function createTaxonomy(array $parameters): UtmTaxonomy
+ {
+ $taxonomy = new UtmTaxonomy();
+ $taxonomy->setName('Spring campaigns');
+ $taxonomy->setParameters($parameters);
+
+ return $taxonomy;
+ }
+
+ public function testTaxonomyValuesAreAccepted(): void
+ {
+ $taxonomy = $this->createTaxonomy([
+ 'utm_source' => [['value' => 'newsletter', 'label' => 'Newsletter']],
+ 'utm_campaign' => [['value' => 'spring', 'label' => 'Spring']],
+ ]);
+
+ $this->assertSame([], $this->createValidator()->validateUtmParameters([
+ 'utm_source' => 'newsletter',
+ 'utm_campaign' => 'spring',
+ ], $taxonomy));
+ }
+
+ public function testValuesOutsideTheTaxonomyAreRejected(): void
+ {
+ $taxonomy = $this->createTaxonomy([
+ 'utm_source' => [['value' => 'newsletter', 'label' => 'Newsletter']],
+ ]);
+
+ $errors = $this->createValidator()->validateUtmParameters([
+ 'utm_source' => 'linkedin',
+ ], $taxonomy);
+
+ $this->assertSame([[SmartLinkValidator::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => 'utm_source', '%value%' => 'linkedin']]], $errors);
+ }
+
+ public function testAStoredValueSurvivesAPlainReSave(): void
+ {
+ $taxonomy = $this->createTaxonomy([
+ 'utm_source' => [['value' => 'newsletter', 'label' => 'Newsletter']],
+ ]);
+
+ $this->assertSame([], $this->createValidator()->validateUtmParameters(
+ ['utm_source' => 'legacy_banner'],
+ $taxonomy,
+ ['utm_source' => 'legacy_banner']
+ ));
+ }
+
+ public function testFreeParametersTakeTheirValuesFromTheTaxonomyList(): void
+ {
+ // The admin left utm_campaign free, but the taxonomy carries its own value list: the
+ // link picks a value from it, nothing is free-typed.
+ $taxonomy = $this->createTaxonomy([
+ 'utm_campaign' => [
+ ['value' => 'spring', 'label' => 'Spring'],
+ ['value' => 'summer', 'label' => 'Summer'],
+ ],
+ ]);
+
+ $this->assertSame([], $this->createValidator()->validateUtmParameters([
+ 'utm_campaign' => 'spring',
+ ], $taxonomy));
+
+ $this->assertSame(
+ [[SmartLinkValidator::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => 'utm_campaign', '%value%' => 'autumn']]],
+ $this->createValidator()->validateUtmParameters(['utm_campaign' => 'autumn'], $taxonomy)
+ );
+ }
+
+ public function testParametersTheTaxonomyDoesntDefineAreRejected(): void
+ {
+ // The taxonomy defines neither the configured dropdown utm_source nor the free
+ // utm_campaign: both are unknown to it.
+ $taxonomy = $this->createTaxonomy([]);
+
+ $this->assertSame(
+ [[SmartLinkValidator::ERROR_TAXONOMY_PARAMETER_UNKNOWN, ['%key%' => 'utm_source', '%name%' => 'Spring campaigns']]],
+ $this->createValidator()->validateUtmParameters(['utm_source' => 'newsletter'], $taxonomy)
+ );
+ $this->assertSame(
+ [[SmartLinkValidator::ERROR_TAXONOMY_PARAMETER_UNKNOWN, ['%key%' => 'utm_campaign', '%name%' => 'Spring campaigns']]],
+ $this->createValidator()->validateUtmParameters(['utm_campaign' => 'spring'], $taxonomy)
+ );
+ }
+
+ public function testWithoutATaxonomyTheGlobalConfigurationApplies(): void
+ {
+ $validator = $this->createValidator();
+
+ // Free parameter: any well-formed value; dropdown: only the configured list.
+ $this->assertSame([], $validator->validateUtmParameters(['utm_campaign' => 'spring', 'utm_source' => 'newsletter']));
+ $this->assertSame([], $validator->validateUtmParameters(['utm_campaign' => 'spring'], null, ['utm_campaign' => 'spring']));
+ $this->assertSame(
+ [[SmartLinkValidator::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => 'utm_source', '%value%' => 'facebook']]],
+ $validator->validateUtmParameters(['utm_source' => 'facebook'])
+ );
+ }
+}
\ No newline at end of file
diff --git a/Tests/Unit/Model/SmartLinkModelTest.php b/Tests/Unit/Model/SmartLinkModelTest.php
new file mode 100644
index 0000000..69af8ee
--- /dev/null
+++ b/Tests/Unit/Model/SmartLinkModelTest.php
@@ -0,0 +1,250 @@
+createMock(CoreParametersHelper::class);
+ $parameters->method('get')->willReturnMap([
+ [UtmConfigurationProvider::CONFIG_PARAMETER, [], $raw],
+ ]);
+
+ $translator = $this->createMock(TranslatorInterface::class);
+ $translator->method('trans')->willReturnCallback(fn (string $id): string => $id);
+
+ return new UtmConfigurationProvider(
+ $parameters,
+ new UtmConfigurationNormalizer(new UtmParameterCatalog()),
+ new UtmParameterCatalog(),
+ $translator
+ );
+ }
+
+ /**
+ * The model with mocked core dependencies; the UTM configuration is real.
+ */
+ private function createModel(array $raw, ?PageModel $pageModel = null, ?UrlGeneratorInterface $router = null): SmartLinkModel
+ {
+ return new SmartLinkModel(
+ $this->createMock(EntityManagerInterface::class),
+ $this->createMock(CorePermissions::class),
+ $this->createMock(EventDispatcherInterface::class),
+ $router ?? $this->createMock(UrlGeneratorInterface::class),
+ $this->createMock(TranslatorInterface::class),
+ $this->createMock(UserHelper::class),
+ $this->createMock(LoggerInterface::class),
+ $this->createMock(CoreParametersHelper::class),
+ $this->createProvider($raw),
+ $pageModel ?? $this->createMock(PageModel::class)
+ );
+ }
+
+ public function testSlugRulesApplyOnNewLink(): void
+ {
+ $model = $this->createModel(['separator_replacement' => '_', 'enforce_lowercase' => '1']);
+ $link = $model->getEntity();
+
+ $model->applySlugRules($link, 'Big Camp');
+ $this->assertSame('big_camp', $link->getSlug());
+ }
+
+ public function testSlugRulesWithLowercaseDisabled(): void
+ {
+ $model = $this->createModel(['separator_replacement' => '-', 'enforce_lowercase' => '']);
+ $link = $model->getEntity();
+
+ $model->applySlugRules($link, 'Big Camp');
+ $this->assertSame('Big-Camp', $link->getSlug());
+ }
+
+ public function testSlugRulesKeepStoredSlugOnEdit(): void
+ {
+ $model = $this->createModel([]);
+
+ $reflection = new \ReflectionClass(\MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink::class);
+ $link = new \MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink();
+ $reflection->getProperty('id')->setValue($link, 1);
+ $link->setSlug('stored');
+
+ // The user never edits the slug of a saved link: the submitted value is ignored...
+ $model->applySlugRules($link);
+ $this->assertSame('stored', $link->getSlug());
+
+ // ...and passing a different slug explicitly is refused.
+ $this->expectException(\LogicException::class);
+ $model->applySlugRules($link, 'other');
+ }
+
+ public function testNormalizeUtmValues(): void
+ {
+ $model = $this->createModel(['enforce_lowercase' => '1']);
+
+ $this->assertSame(
+ // The model sorts the keys, so the stored array is deterministic.
+ ['utm_medium' => 'email', 'utm_source' => 'acme'],
+ $model->normalizeUtmValues(['utm_source' => 'ACME ', 'utm_medium' => 'Email', 'utm_term' => ''])
+ );
+
+ $modelNoLower = $this->createModel(['enforce_lowercase' => '']);
+ $this->assertSame(
+ ['utm_source' => 'ACME'],
+ $modelNoLower->normalizeUtmValues(['utm_source' => 'ACME'])
+ );
+ }
+
+ public function testNormalizeUtmValuesUsesValuePatternToo(): void
+ {
+ $model = $this->createModel(['enforce_lowercase' => '1']);
+ // Values of disabled parameters and empty values are dropped by the form; the model
+ // only applies the case and separator rules.
+ $this->assertSame(['a' => 'b'], $model->normalizeUtmValues(['a' => 'b', 'x' => null]));
+ }
+
+ public function testEnabledParameterDefaultModeIsRespected(): void
+ {
+ // An empty configuration leaves the utm_source dropdown switched off: an enabled
+ // dropdown needs values, and they are configured on the Configuration page.
+ $provider = $this->createProvider([]);
+ $source = $provider->getParameter('utm_source');
+
+ $this->assertNotNull($source);
+ $this->assertFalse($source['enabled']);
+ $this->assertSame(UtmParameterMode::DROPDOWN, $source['mode']);
+ $this->assertSame([], $provider->getDropdownValues('utm_source'));
+
+ // Enabled with stored values it stays a dropdown and serves them.
+ $enabled = $this->createProvider(['parameters' => [
+ 'utm_source' => [
+ 'enabled' => '1',
+ 'label' => 'Source',
+ 'mode' => 'dropdown',
+ 'values' => [['value' => 'newsletter', 'label' => 'Newsletter']],
+ ],
+ ]]);
+ $source = $enabled->getParameter('utm_source');
+ $this->assertTrue($source['enabled']);
+ $this->assertSame(UtmParameterMode::DROPDOWN, $source['mode']);
+ $this->assertNotSame([], $enabled->getDropdownValues('utm_source'));
+ }
+
+ /**
+ * @param array $utms
+ */
+ #[DataProvider('redirectUrlProvider')]
+ public function testBuildRedirectUrl(string $destination, array $utms, string $expected): void
+ {
+ $link = new \MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink();
+ $link->setDestinationUrl($destination);
+ $link->setUtmParameters($utms);
+
+ $this->assertSame($expected, $this->createModel([])->buildRedirectUrl($link));
+ }
+
+ /**
+ * @return iterable, 2: string}>
+ */
+ public static function redirectUrlProvider(): iterable
+ {
+ yield 'no utm parameters keeps destination as-is' => [
+ 'https://www.example.com/spring',
+ [],
+ 'https://www.example.com/spring',
+ ];
+
+ yield 'parameters are appended to a bare destination' => [
+ 'https://www.example.com/spring',
+ ['utm_source' => 'newsletter', 'utm_medium' => 'email'],
+ 'https://www.example.com/spring?utm_source=newsletter&utm_medium=email',
+ ];
+
+ yield 'existing query is kept, link parameters override same-named ones' => [
+ 'https://www.example.com/spring?foo=bar&utm_medium=paid',
+ ['utm_medium' => 'email', 'utm_source' => 'newsletter'],
+ 'https://www.example.com/spring?foo=bar&utm_medium=email&utm_source=newsletter',
+ ];
+
+ yield 'fragment and parts of the destination survive' => [
+ 'https://user.example.com:8443/path/page#section',
+ ['utm_source' => 'x'],
+ 'https://user.example.com:8443/path/page?utm_source=x#section',
+ ];
+ }
+
+ public function testBuildMauticDestinationUrlWithoutDestinationIsEmpty(): void
+ {
+ $link = new \MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink();
+
+ $this->assertSame('', $this->createModel([])->buildMauticDestinationUrl($link));
+ }
+
+ public function testBuildMauticDestinationUrlUsesThePageModel(): void
+ {
+ $pageModel = $this->createMock(PageModel::class);
+ $pageModel->method('generateUrl')->willReturn('https://mautic.example.com/landing');
+
+ $link = new \MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink();
+ $reflection = new \ReflectionClass(\MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink::class);
+ $reflection->getProperty('page')->setValue($link, $this->createMock(\Mautic\PageBundle\Entity\Page::class));
+
+ $this->assertSame('https://mautic.example.com/landing', $this->createModel([], $pageModel)->buildMauticDestinationUrl($link));
+ }
+
+ public function testBuildMauticDestinationUrlUsesTheFormPreviewRoute(): void
+ {
+ $router = $this->createMock(UrlGeneratorInterface::class);
+ $router->method('generate')
+ ->with('mautic_form_preview', ['id' => 7], UrlGeneratorInterface::ABSOLUTE_URL)
+ ->willReturn('https://mautic.example.com/form/7');
+
+ $form = $this->createMock(\Mautic\FormBundle\Entity\Form::class);
+ $form->method('getId')->willReturn(7);
+
+ $link = new \MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink();
+ $reflection = new \ReflectionClass(\MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink::class);
+ $reflection->getProperty('form')->setValue($link, $form);
+
+ $this->assertSame('https://mautic.example.com/form/7', $this->createModel([], null, $router)->buildMauticDestinationUrl($link));
+ }
+
+ public function testBuildRedirectUrlAppendsUtmToMauticDestinations(): void
+ {
+ $pageModel = $this->createMock(PageModel::class);
+ $pageModel->method('generateUrl')->willReturn('https://mautic.example.com/landing');
+
+ $link = new \MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink();
+ $link->setRedirectType(\MauticPlugin\MT3SMarketingProgramBundle\Catalog\SmartLinkRedirectType::Mautic);
+ $link->setUtmParameters(['utm_source' => 'newsletter']);
+ $reflection = new \ReflectionClass(\MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink::class);
+ $reflection->getProperty('page')->setValue($link, $this->createMock(\Mautic\PageBundle\Entity\Page::class));
+
+ $this->assertSame(
+ 'https://mautic.example.com/landing?utm_source=newsletter',
+ $this->createModel([], $pageModel)->buildRedirectUrl($link)
+ );
+ }
+}
diff --git a/Tests/Unit/Model/UtmTaxonomyModelTest.php b/Tests/Unit/Model/UtmTaxonomyModelTest.php
new file mode 100644
index 0000000..89838cd
--- /dev/null
+++ b/Tests/Unit/Model/UtmTaxonomyModelTest.php
@@ -0,0 +1,67 @@
+createMock(EntityManagerInterface::class),
+ $this->createMock(CorePermissions::class),
+ $this->createMock(EventDispatcherInterface::class),
+ $this->createMock(UrlGeneratorInterface::class),
+ $this->createMock(TranslatorInterface::class),
+ $this->createMock(UserHelper::class),
+ $this->createMock(LoggerInterface::class),
+ $this->createMock(CoreParametersHelper::class)
+ );
+ }
+
+ public function testNormalizeParametersTrimsDeduplicatesSortsAndFallsBackToTheValueAsLabel(): void
+ {
+ $clean = $this->createModel()->normalizeParameters([
+ 'utm_source' => [
+ ['value' => ' newsletter ', 'label' => 'Newsletter'],
+ ['value' => 'newsletter', 'label' => 'Duplicate value, dropped'],
+ ['value' => '', 'label' => 'Empty value, dropped'],
+ 'not-an-array',
+ ],
+ 'utm_campaign' => [
+ ['value' => 'spring', 'label' => ''],
+ ],
+ ' ' => [['value' => 'x', 'label' => 'X']],
+ 'not-an-array' => 'nope',
+ ]);
+
+ $this->assertSame([
+ 'utm_campaign' => [
+ ['value' => 'spring', 'label' => 'spring'],
+ ],
+ 'utm_source' => [
+ ['value' => 'newsletter', 'label' => 'Newsletter'],
+ ],
+ ], $clean);
+ }
+
+ public function testNormalizeParametersDropsParametersWithoutValues(): void
+ {
+ $this->assertSame([], $this->createModel()->normalizeParameters([
+ 'utm_source' => [['value' => '', 'label' => 'Empty']],
+ 'gclid' => [],
+ ]));
+ }
+}
\ No newline at end of file
diff --git a/Tests/Unit/Service/UtmConfigurationProviderTest.php b/Tests/Unit/Service/UtmConfigurationProviderTest.php
new file mode 100644
index 0000000..938c29b
--- /dev/null
+++ b/Tests/Unit/Service/UtmConfigurationProviderTest.php
@@ -0,0 +1,193 @@
+ '',
+ 'separator_replacement' => '_',
+ 'parameters' => [
+ 'utm_source' => [
+ 'enabled' => '1',
+ 'label' => 'Source',
+ 'mode' => 'dropdown',
+ 'values' => [
+ ['value' => 'newsletter', 'label' => 'Newsletter'],
+ ['value' => 'linkedin', 'label' => 'LinkedIn'],
+ ],
+ 'default' => 'linkedin',
+ ],
+ 'utm_medium' => [
+ 'enabled' => '',
+ 'label' => 'Medium',
+ 'mode' => 'dropdown',
+ 'values' => [['value' => 'email', 'label' => 'Email']],
+ 'default' => '',
+ ],
+ // Values left in storage for a free parameter must never be exposed.
+ 'utm_campaign' => [
+ 'enabled' => '1',
+ 'label' => '',
+ 'mode' => 'free',
+ 'values' => [['value' => 'should_not_appear', 'label' => 'x']],
+ 'default' => 'should_not_appear',
+ ],
+ 'utm_term' => ['enabled' => '1', 'label' => 'Term', 'mode' => 'disabled'],
+ 'gclid' => ['enabled' => '1', 'label' => 'GCLID', 'mode' => 'free'],
+ // Dropdown isn't allowed for click IDs: falls back to the default mode (disabled).
+ 'fbclid' => ['enabled' => '1', 'label' => 'FB', 'mode' => 'dropdown', 'values' => [['value' => 'a', 'label' => 'a']]],
+ 'partner' => ['enabled' => '1', 'label' => 'Partner', 'mode' => 'dropdown', 'values' => [['value' => 'acme', 'label' => 'ACME']], 'default' => ''],
+ 'utm_hack' => ['enabled' => '1', 'label' => 'Invalid custom key', 'mode' => 'free'],
+ ],
+ ];
+
+ public function testGetEnabledParameters(): void
+ {
+ $enabled = $this->createProvider(self::STORED)->getEnabledParameters();
+
+ // Enabled and not in disabled mode, catalog order first, then custom parameters.
+ $this->assertSame(['utm_source', 'utm_campaign', 'utm_content', 'utm_id', 'gclid', 'partner'], array_keys($enabled));
+
+ $this->assertSame([
+ 'key' => 'utm_source',
+ 'enabled' => true,
+ 'label' => 'Source',
+ 'mode' => UtmParameterMode::DROPDOWN,
+ 'values' => [
+ ['value' => 'newsletter', 'label' => 'Newsletter'],
+ ['value' => 'linkedin', 'label' => 'LinkedIn'],
+ ],
+ 'default' => 'linkedin',
+ 'group' => UtmParameterCatalog::GROUP_STANDARD,
+ 'custom' => false,
+ 'auto_generated' => false,
+ ], $enabled['utm_source']);
+
+ $this->assertTrue($enabled['partner']['custom']);
+ $this->assertSame(UtmParameterCatalog::GROUP_CUSTOM, $enabled['partner']['group']);
+ $this->assertTrue($enabled['gclid']['auto_generated']);
+ }
+
+ public function testFreeParameterExposesNoValues(): void
+ {
+ $provider = $this->createProvider(self::STORED);
+ $campaign = $provider->getParameter('utm_campaign');
+
+ $this->assertSame([
+ 'key' => 'utm_campaign',
+ 'enabled' => true,
+ 'label' => 'translated:mautic.smartlinks.config.parameter.utm_campaign.label',
+ 'mode' => UtmParameterMode::FREE,
+ 'group' => UtmParameterCatalog::GROUP_STANDARD,
+ 'custom' => false,
+ 'auto_generated' => false,
+ ], $campaign);
+ $this->assertSame([], $provider->getDropdownValues('utm_campaign'));
+ }
+
+ public function testGetParameter(): void
+ {
+ $provider = $this->createProvider(self::STORED);
+
+ $this->assertSame(UtmParameterMode::DISABLED, $provider->getParameter('utm_term')['mode'] ?? null);
+ $this->assertArrayNotHasKey('values', $provider->getParameter('utm_term') ?? []);
+ $this->assertSame(UtmParameterMode::DISABLED, $provider->getParameter('fbclid')['mode'] ?? null);
+ $this->assertFalse($provider->getParameter('utm_medium')['enabled'] ?? null);
+ $this->assertArrayHasKey('default', $provider->getParameter('utm_medium'));
+ $this->assertNull($provider->getParameter('utm_medium')['default']);
+ $this->assertSame('Partner', $provider->getParameter('partner')['label'] ?? null);
+ $this->assertNull($provider->getParameter('unknown'));
+ $this->assertNull($provider->getParameter('utm_hack'), 'Custom keys with a reserved prefix are ignored.');
+ }
+
+ public function testGetDropdownValues(): void
+ {
+ $provider = $this->createProvider(self::STORED);
+
+ $this->assertSame(
+ [['value' => 'newsletter', 'label' => 'Newsletter'], ['value' => 'linkedin', 'label' => 'LinkedIn']],
+ $provider->getDropdownValues('utm_source')
+ );
+ $this->assertSame([['value' => 'acme', 'label' => 'ACME']], $provider->getDropdownValues('partner'));
+ $this->assertSame([['value' => 'email', 'label' => 'Email']], $provider->getDropdownValues('utm_medium'));
+ $this->assertSame([], $provider->getDropdownValues('utm_term'));
+ $this->assertSame([], $provider->getDropdownValues('gclid'));
+ $this->assertSame([], $provider->getDropdownValues('fbclid'));
+ $this->assertSame([], $provider->getDropdownValues('unknown'));
+ }
+
+ public function testGeneralSettings(): void
+ {
+ $provider = $this->createProvider(self::STORED);
+
+ $this->assertFalse($provider->isLowercaseEnforced());
+ $this->assertSame('_', $provider->getSeparatorReplacement());
+ }
+
+ public function testDefaultsWhenNothingIsStored(): void
+ {
+ $provider = $this->createProvider(null);
+
+ $this->assertTrue($provider->isLowercaseEnforced());
+ $this->assertSame('-', $provider->getSeparatorReplacement());
+
+ // Free catalog parameters are enabled by default, dropdown parameters wait for values, click IDs are disabled.
+ $this->assertSame(['utm_campaign', 'utm_term', 'utm_content', 'utm_id'], array_keys($provider->getEnabledParameters()));
+ $this->assertSame(UtmParameterMode::DROPDOWN, $provider->getParameter('utm_source')['mode'] ?? null);
+ $this->assertFalse($provider->getParameter('utm_source')['enabled'] ?? null);
+ $this->assertSame([], $provider->getDropdownValues('utm_source'));
+ $this->assertSame(UtmParameterMode::DISABLED, $provider->getParameter('gclid')['mode'] ?? null);
+ }
+
+ public function testInvalidSeparatorFallsBackToHyphen(): void
+ {
+ $this->assertSame('-', $this->createProvider(['separator_replacement' => ' '])->getSeparatorReplacement());
+ }
+
+ public function testLegacyParameterIsServedUntilTheNewOneIsSaved(): void
+ {
+ // Upgrades from < 0.5.0: the new key is empty, the settings live under the legacy key.
+ $provider = $this->createProvider([], self::STORED);
+
+ $this->assertFalse($provider->isLowercaseEnforced());
+ $this->assertSame('_', $provider->getSeparatorReplacement());
+ $this->assertSame(
+ ['utm_source', 'utm_campaign', 'utm_content', 'utm_id', 'gclid', 'partner'],
+ array_keys($provider->getEnabledParameters())
+ );
+ }
+
+ private function createProvider(mixed $stored, ?array $legacy = null): UtmConfigurationProvider
+ {
+ $parameters = $this->createMock(CoreParametersHelper::class);
+ $parameters->method('get')
+ ->willReturnCallback(
+ fn (string $name, mixed $default = null): mixed => match (true) {
+ UtmConfigurationProvider::CONFIG_PARAMETER === $name => $stored,
+ UtmConfigurationProvider::LEGACY_CONFIG_PARAMETER === $name && null !== $legacy => $legacy,
+ default => $default,
+ }
+ );
+
+ $translator = $this->createMock(TranslatorInterface::class);
+ $translator->method('trans')->willReturnCallback(fn (string $key): string => 'translated:'.$key);
+
+ $catalog = new UtmParameterCatalog();
+
+ return new UtmConfigurationProvider($parameters, new UtmConfigurationNormalizer($catalog), $catalog, $translator);
+ }
+}
diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php
new file mode 100644
index 0000000..449569c
--- /dev/null
+++ b/Tests/bootstrap.php
@@ -0,0 +1,19 @@
+ Configuration tab title. Core builds this key from the form alias (mautic.config.tab.).
+mautic.config.tab.smartlinksconfig="Smart Links Settings"
+; Settings > Configuration > Smart Links Settings.
+mautic.smartlinks.settings.description="Settings for Smart Links: the UTM parameters they carry, the general rules and the domain of their short links."
+mautic.smartlinks.settings.short_link_domain="Short Link Domain"
+mautic.smartlinks.settings.short_link_domain.tooltip="Domain used to create future short links, for example lnk.example.com. Do not include https://."
+mautic.smartlinks.settings.placeholder="Smart Links will appear here."
+; Smart Links (main menu > Smart Links). Translation base mautic.smartlinks.smart_links.
+mautic.smartlinks.smart_links.header.index="Smart Links"
+mautic.smartlinks.smart_links.header.new="New Smart Link"
+mautic.smartlinks.smart_links.header.edit="Smart Link - %slug%"
+mautic.smartlinks.smart_links.slug="Slug"
+mautic.smartlinks.smart_links.slug.tooltip="Short text (max 9 characters). Spaces are replaced by the configured character, uppercase is turned into lowercase when the link is saved. The slug can't be changed after the link is created."
+mautic.smartlinks.smart_links.slug.generate="Generate"
+mautic.smartlinks.smart_links.slug.generate.tooltip="Use a random slug of 4 letters and digits."
+mautic.smartlinks.smart_links.short_link="Short link"
+mautic.smartlinks.smart_links.domain.reminder="Short links domain:"
+mautic.smartlinks.smart_links.domain.reminder.empty="No short links domain configured. Set it in Settings > Configuration > Smart Links Settings."
+mautic.smartlinks.smart_links.redirect_type="Redirect type"
+mautic.smartlinks.smart_links.redirect_type.mautic="Mautic"
+mautic.smartlinks.smart_links.redirect_type.external="External"
+mautic.smartlinks.smart_links.redirect_code="Redirect HTTP code"
+mautic.smartlinks.smart_links.redirect_code.301="301 - Moved permanently — permanent"
+mautic.smartlinks.smart_links.redirect_code.302="302 - Found — temporary"
+mautic.smartlinks.smart_links.redirect_code.307="307 - Temporary redirect — temporary"
+mautic.smartlinks.smart_links.redirect_code.308="308 - Permanent redirect — permanent"
+mautic.smartlinks.smart_links.destination_url="Destination URL"
+mautic.smartlinks.smart_links.destination_url.tooltip="Where the visitor lands, for example https://www.example.com/page. Only used for external redirects."
+mautic.smartlinks.smart_links.destination="Destination"
+mautic.smartlinks.smart_links.destination.tooltip="The landing page or the standalone form the visitor is redirected to. Only used for Mautic redirects."
+mautic.smartlinks.smart_links.destination.pages="Landing pages"
+mautic.smartlinks.smart_links.destination.forms="Standalone forms"
+mautic.smartlinks.smart_links.destination.unpublished="No longer published"
+mautic.smartlinks.smart_links.utm_parameters="UTM parameters"
+mautic.smartlinks.smart_links.utm_parameters.help="Choose the UTM Taxonomy first: each value below is picked among the values it allows."
+mautic.smartlinks.smart_links.onboarding.heading="No Smart Links yet"
+mautic.smartlinks.smart_links.onboarding.subheading="Smart Links are short links that carry your UTM parameters."
+mautic.smartlinks.smart_links.onboarding.copy="Use the New button above to create one. Its slug can't be changed after creation; delete it and create a new one instead."
+mautic.smartlinks.smart_links.menu.new="New Smart Link"
+mautic.smartlinks.smart_links.menu.edit="Edit %name%"
+mautic.smartlinks.smart_links.menu.delete="Delete %name%"
+mautic.smartlinks.smart_links.form.confirmdelete="Delete the Smart Link %name%? It can't be restored."
+mautic.smartlinks.smart_links.form.confirmbatchdelete="Delete the selected Smart Links? They can't be restored."
+mautic.smartlinks.smart_links.error.notfound="No Smart Link with the ID %id% was found."
+mautic.smartlinks.smart_links.permissions.header="Smart Links - User has access to"
+mautic.smartlinks.smart_links.hits="Hits"
+mautic.smartlinks.smart_links.hits.tooltip="Number of times the short link redirected a visitor."
+mautic.smartlinks.config.description="Define the UTM parameters offered by the link builder and how each one is presented."
+mautic.smartlinks.config.section.utm_settings="UTM Settings"
+mautic.smartlinks.config.section.parameters="Parameters"
+mautic.smartlinks.config.group.standard="Standard UTM"
+mautic.smartlinks.config.group.platform="Platform identifiers"
+mautic.smartlinks.config.group.custom="Custom parameters"
+mautic.smartlinks.config.enforce_lowercase="Enforce lowercase on all values"
+mautic.smartlinks.config.enforce_lowercase.tooltip="The link builder converts every parameter value to lowercase."
+mautic.smartlinks.config.separator_replacement="Value separator replacement"
+mautic.smartlinks.config.separator_replacement.tooltip="Character that replaces spaces in parameter values."
+mautic.smartlinks.config.separator.hyphen="Hyphen ( - )"
+mautic.smartlinks.config.separator.underscore="Underscore ( _ )"
+mautic.smartlinks.config.separator.dot="Dot ( . )"
+mautic.smartlinks.config.parameter.enabled="Enabled"
+mautic.smartlinks.config.parameter.label="Label"
+mautic.smartlinks.config.parameter.mode="Mode"
+mautic.smartlinks.config.parameter.key="Key"
+mautic.smartlinks.config.parameter.key.tooltip="Name of the URL parameter: lowercase letters, digits and underscores, starting with a letter (2 to 41 characters)."
+mautic.smartlinks.config.mode.dropdown="Dropdown (list of values)"
+mautic.smartlinks.config.mode.free="Free text"
+mautic.smartlinks.config.mode.disabled="Disabled"
+mautic.smartlinks.config.auto_generated.badge="Auto"
+mautic.smartlinks.config.auto_generated.tooltip="Usually added automatically by the ad platform. Only enable if you need to handle it manually."
+mautic.smartlinks.config.values="Allowed values"
+mautic.smartlinks.config.values.value="Value"
+mautic.smartlinks.config.values.label="Label"
+mautic.smartlinks.config.values.default="Default"
+mautic.smartlinks.config.values.add="Add value"
+mautic.smartlinks.config.values.remove="Remove value"
+mautic.smartlinks.config.values.drag="Drag to reorder"
+mautic.smartlinks.config.values.empty="No values yet."
+mautic.smartlinks.config.values.suggestions="Load suggested values"
+mautic.smartlinks.config.values.import="Paste values (one per line, or value;label)"
+mautic.smartlinks.config.values.import.placeholder="newsletter;Newsletter"
+mautic.smartlinks.config.values.import.button="Import"
+mautic.smartlinks.config.custom.add="Add custom parameter"
+mautic.smartlinks.config.custom.remove="Delete"
+mautic.smartlinks.config.custom.new="new parameter"
+mautic.smartlinks.config.custom.empty="No custom parameters."
+mautic.smartlinks.config.parameter.utm_source.label="Source"
+mautic.smartlinks.config.parameter.utm_source.description="Traffic origin, for example newsletter, linkedin or google."
+mautic.smartlinks.config.parameter.utm_medium.label="Medium"
+mautic.smartlinks.config.parameter.utm_medium.description="Channel type, for example email, cpc, social or referral."
+mautic.smartlinks.config.parameter.utm_campaign.label="Campaign"
+mautic.smartlinks.config.parameter.utm_campaign.description="Campaign name."
+mautic.smartlinks.config.parameter.utm_term.label="Term"
+mautic.smartlinks.config.parameter.utm_term.description="Paid search keyword."
+mautic.smartlinks.config.parameter.utm_content.label="Content"
+mautic.smartlinks.config.parameter.utm_content.description="Differentiates variants or links that point to the same URL."
+mautic.smartlinks.config.parameter.utm_id.label="Campaign ID"
+mautic.smartlinks.config.parameter.utm_id.description="Campaign ID, used by GA4 data import."
+mautic.smartlinks.config.parameter.utm_source_platform.label="Source platform"
+mautic.smartlinks.config.parameter.utm_source_platform.description="Platform that manages the campaign, for example Google Ads."
+mautic.smartlinks.config.parameter.utm_creative_format.label="Creative format"
+mautic.smartlinks.config.parameter.utm_creative_format.description="Creative type, for example display, video or native."
+mautic.smartlinks.config.parameter.utm_marketing_tactic.label="Marketing tactic"
+mautic.smartlinks.config.parameter.utm_marketing_tactic.description="Targeting tactic, for example prospecting or remarketing."
+mautic.smartlinks.config.parameter.gclid.label="Google Ads click ID"
+mautic.smartlinks.config.parameter.gclid.description="Click ID added by Google Ads."
+mautic.smartlinks.config.parameter.gbraid.label="Google Ads iOS web-to-app ID"
+mautic.smartlinks.config.parameter.gbraid.description="Click ID added by Google Ads for iOS web-to-app measurement."
+mautic.smartlinks.config.parameter.wbraid.label="Google Ads iOS app-to-web ID"
+mautic.smartlinks.config.parameter.wbraid.description="Click ID added by Google Ads for iOS app-to-web measurement."
+mautic.smartlinks.config.parameter.dclid.label="Display & Video 360 click ID"
+mautic.smartlinks.config.parameter.dclid.description="Click ID added by Google Display & Video 360."
+mautic.smartlinks.config.parameter.fbclid.label="Meta click ID"
+mautic.smartlinks.config.parameter.fbclid.description="Click ID added by Meta (Facebook, Instagram)."
+mautic.smartlinks.config.parameter.msclkid.label="Microsoft Advertising click ID"
+mautic.smartlinks.config.parameter.msclkid.description="Click ID added by Microsoft Advertising."
+mautic.smartlinks.config.parameter.ttclid.label="TikTok click ID"
+mautic.smartlinks.config.parameter.ttclid.description="Click ID added by TikTok."
+mautic.smartlinks.config.parameter.li_fat_id.label="LinkedIn click ID"
+mautic.smartlinks.config.parameter.li_fat_id.description="Click ID added by LinkedIn."
+mautic.smartlinks.config.parameter.twclid.label="X click ID"
+mautic.smartlinks.config.parameter.twclid.description="Click ID added by X (Twitter)."
+mautic.smartlinks.config.parameter.epik.label="Pinterest click ID"
+mautic.smartlinks.config.parameter.epik.description="Click ID added by Pinterest."
+mautic.smartlinks.config.suggestion.newsletter="Newsletter"
+mautic.smartlinks.config.suggestion.linkedin="LinkedIn"
+mautic.smartlinks.config.suggestion.facebook="Facebook"
+mautic.smartlinks.config.suggestion.instagram="Instagram"
+mautic.smartlinks.config.suggestion.google="Google"
+mautic.smartlinks.config.suggestion.youtube="YouTube"
+mautic.smartlinks.config.suggestion.x="X"
+mautic.smartlinks.config.suggestion.tiktok="TikTok"
+mautic.smartlinks.config.suggestion.partner="Partner"
+mautic.smartlinks.config.suggestion.direct="Direct"
+mautic.smartlinks.config.suggestion.email="Email"
+mautic.smartlinks.config.suggestion.cpc="Cost per click"
+mautic.smartlinks.config.suggestion.social="Social"
+mautic.smartlinks.config.suggestion.social_paid="Paid social"
+mautic.smartlinks.config.suggestion.display="Display"
+mautic.smartlinks.config.suggestion.affiliate="Affiliate"
+mautic.smartlinks.config.suggestion.referral="Referral"
+mautic.smartlinks.config.suggestion.qr="QR code"
+mautic.smartlinks.config.suggestion.sms="SMS"
+mautic.smartlinks.config.suggestion.print="Print"
+mautic.smartlinks.config.suggestion.event="Event"
+mautic.smartlinks.config.suggestion.google_ads="Google Ads"
+mautic.smartlinks.config.suggestion.meta_ads="Meta Ads"
+mautic.smartlinks.config.suggestion.linkedin_ads="LinkedIn Ads"
+mautic.smartlinks.config.suggestion.microsoft_ads="Microsoft Ads"
+mautic.smartlinks.config.suggestion.tiktok_ads="TikTok Ads"
+mautic.smartlinks.config.suggestion.banner="Banner"
+mautic.smartlinks.config.suggestion.video="Video"
+mautic.smartlinks.config.suggestion.carousel="Carousel"
+mautic.smartlinks.config.suggestion.text="Text"
+mautic.smartlinks.config.suggestion.native="Native"
+mautic.smartlinks.config.suggestion.prospecting="Prospecting"
+mautic.smartlinks.config.suggestion.remarketing="Remarketing"
+mautic.smartlinks.config.suggestion.retargeting="Retargeting"
+mautic.smartlinks.config.suggestion.brand="Brand"
+mautic.smartlinks.config.suggestion.nurturing="Nurturing"
+; "UTM tags" section of the Email and Focus Item forms.
+mautic.smartlinks.form.choose="Choose..."
+mautic.smartlinks.form.legacy_choice="%value% (not in taxonomy)"
+mautic.smartlinks.form.legacy_warning="This value is not part of the UTM taxonomy."
+mautic.smartlinks.form.no_values="No values configured for this parameter. Ask an administrator."
+; Smart Link form and UTM Taxonomies (Smart Links > UTM Taxonomies). Translation base mautic.smartlinks.taxonomies.
+mautic.smartlinks.smart_links.taxonomy="UTM Taxonomy"
+mautic.smartlinks.smart_links.taxonomy.tooltip="The set of allowed values for the UTM parameters of this link. Every value of the link is picked among the values the taxonomy allows."
+mautic.smartlinks.taxonomies.header.index="UTM Taxonomies"
+mautic.smartlinks.taxonomies.header.new="New UTM Taxonomy"
+mautic.smartlinks.taxonomies.header.edit="UTM Taxonomy - %name%"
+mautic.smartlinks.taxonomies.name="Name"
+mautic.smartlinks.taxonomies.name.tooltip="A unique, short name identifying this set of allowed UTM values."
+mautic.smartlinks.taxonomies.description="Description"
+mautic.smartlinks.taxonomies.parameters="UTM parameters"
+mautic.smartlinks.taxonomies.parameters.help="Every parameter enabled in Smart Links Settings appears. Dropdown parameters offer the values the admin configured: check the ones a Smart Link may carry. Free-text parameters get their own value list here: a link then picks a value from it instead of typing freely."
+mautic.smartlinks.taxonomies.parameter_count="Parameters"
+mautic.smartlinks.taxonomies.parameter_count.tooltip="The number of parameters this taxonomy defines values for."
+mautic.smartlinks.taxonomies.menu.new="New UTM Taxonomy"
+mautic.smartlinks.taxonomies.menu.edit="Edit %name%"
+mautic.smartlinks.taxonomies.menu.delete="Delete %name%"
+mautic.smartlinks.taxonomies.form.confirmdelete="Delete the UTM Taxonomy %name%? It cannot be restored. The Smart Links that use it keep the values they already carry and ask for a new taxonomy on their next edit."
+mautic.smartlinks.taxonomies.form.confirmbatchdelete="Delete the selected UTM Taxonomies? They cannot be restored."
+mautic.smartlinks.taxonomies.error.notfound="No UTM Taxonomy with the id %id%."
+mautic.smartlinks.taxonomies.permissions.header="UTM Taxonomies - The user has access to"
+mautic.smartlinks.taxonomies.onboarding.heading="No UTM Taxonomies yet"
+mautic.smartlinks.taxonomies.onboarding.subheading="UTM Taxonomies are sets of allowed values for the UTM parameters of your Smart Links."
+mautic.smartlinks.taxonomies.onboarding.copy="Use the New button above to create one. A Smart Link carries one taxonomy; every UTM value it carries is picked among the values the taxonomy allows."
+mautic.smartlinks.taxonomies.unpublished_choice="%name% (no longer published)"
+mautic.smartlinks.taxonomies.free_values.tooltip="The allowed values of this parameter for the links using this taxonomy. One value per line, optionally value;Label for a display label."
+mautic.smartlinks.taxonomies.free_values.placeholder="one value per line"
+mautic.smartlinks.taxonomies.no_values.tooltip="No values are configured for this parameter in Smart Links Settings yet: ask the admin to configure some."
diff --git a/Translations/en_US/validators.ini b/Translations/en_US/validators.ini
index 7142bb4..1c23433 100644
--- a/Translations/en_US/validators.ini
+++ b/Translations/en_US/validators.ini
@@ -21,3 +21,41 @@ mt3s.marketing_program.description_item.type.required="Choose a type."
mt3s.marketing_program.config.type.name.required="A type needs a name in the default language."
mt3s.marketing_program.config.type.in_use="These types are in use and can't be removed: %types%. Change the items or tasks that use them to another type first."
mt3s.marketing_program.allocation_item.type.required="Choose a type."
+
+; Form validation messages of Settings > Configuration > UTM Settings (Symfony translates them in the validators domain).
+mautic.smartlinks.config.error.key_required="Enter a key for the custom parameter."
+mautic.smartlinks.config.error.key_invalid="The key \"%key%\" is invalid. Use 2 to 41 lowercase letters, digits or underscores, starting with a letter."
+mautic.smartlinks.config.error.key_reserved="The key \"%key%\" is reserved. Keys of the catalog, \"ct\", keys starting with \"utm\" and keys starting with \"mtc_\" can't be used."
+mautic.smartlinks.config.error.key_duplicate="The key \"%key%\" is used by more than one custom parameter."
+mautic.smartlinks.config.error.mode_invalid="This mode isn't available for this parameter."
+mautic.smartlinks.config.error.separator_invalid="Choose a hyphen, an underscore or a dot."
+mautic.smartlinks.config.error.label_required="Enter a label."
+mautic.smartlinks.config.error.label_length="The label can't be longer than {{ limit }} characters."
+mautic.smartlinks.config.error.label_invalid="The label can't contain the % character."
+mautic.smartlinks.config.error.value_required="Enter a value."
+mautic.smartlinks.config.error.value_length="The value can't be longer than {{ limit }} characters."
+mautic.smartlinks.config.error.value_invalid="Use only lowercase letters, digits, hyphens, underscores and dots in values."
+mautic.smartlinks.config.error.value_duplicate="The value \"%value%\" appears more than once."
+mautic.smartlinks.config.error.values_required="An enabled parameter in dropdown mode needs at least one value."
+mautic.smartlinks.config.error.default_multiple="Only one value can be the default."
+; "UTM tags" section of the Email and Focus Item forms.
+mautic.smartlinks.form.error.not_in_taxonomy="This value is not part of the UTM taxonomy. Choose a value from the list."
+; Smart Link form (main menu > Smart Links).
+mautic.smartlinks.smart_links.error.slug_required="Enter a slug."
+mautic.smartlinks.smart_links.error.slug_length="The slug can't be longer than {{ limit }} characters."
+mautic.smartlinks.smart_links.error.slug_characters="Use only letters, digits, hyphens, underscores and dots in the slug."
+mautic.smartlinks.smart_links.error.slug_taken="Another Smart Link already uses the slug \"%slug%\". Choose a different one."
+mautic.smartlinks.smart_links.error.slug_immutable="The slug of a Smart Link can't be changed. Delete it and create a new one."
+mautic.smartlinks.smart_links.error.destination_required="Enter the destination URL of the external redirect."
+mautic.smartlinks.smart_links.error.destination_required_mautic="Choose a landing page or a standalone form as the destination of the Mautic redirect."
+mautic.smartlinks.smart_links.error.destination_invalid="The destination URL must be a valid http(s) URL."
+mautic.smartlinks.smart_links.error.utm_value_invalid="The parameter \"%key%\" is not enabled, or its value is invalid. Use only lowercase letters, digits, hyphens, underscores and dots."
+mautic.smartlinks.smart_links.error.utm_value_not_allowed="The value \"%value%\" of the parameter \"%key%\" is not part of its allowed values."
+; UTM Taxonomy form and taxonomy-driven Smart Link values.
+mautic.smartlinks.taxonomies.error.name_required="Enter a name."
+mautic.smartlinks.taxonomies.error.name_length="The name cannot be longer than {{ limit }} characters."
+mautic.smartlinks.taxonomies.error.name_taken="Another UTM Taxonomy already uses the name %name%."
+mautic.smartlinks.taxonomies.error.name_characters="The name cannot contain the characters %, { or }."
+mautic.smartlinks.taxonomies.error.value_invalid="The value %value% is invalid. Use only lowercase letters, digits, hyphens, underscores and dots."
+mautic.smartlinks.smart_links.error.taxonomy_required="Choose a UTM Taxonomy."
+mautic.smartlinks.smart_links.error.taxonomy_parameter_unknown="The parameter %key% is not part of the taxonomy %name%."
diff --git a/Translations/fr_FR/messages.ini b/Translations/fr_FR/messages.ini
new file mode 100644
index 0000000..747ebba
--- /dev/null
+++ b/Translations/fr_FR/messages.ini
@@ -0,0 +1,210 @@
+mautic.plugin.smartlinks.name="Smartlinks"
+mautic.smartlinks.menu.root="Smart Links"
+mautic.smartlinks.menu.smartlinks="Smart Links"
+mautic.smartlinks.menu.taxonomies="Taxonomies UTM"
+
+
+; Titre de l'onglet dans Paramètres > Configuration. Le cœur construit cette clé à partir de l'alias du formulaire.
+mautic.config.tab.smartlinksconfig="Paramètres Smart Links"
+
+; Paramètres > Configuration > Smart Links Settings.
+mautic.smartlinks.settings.description="Réglages des Smart Links : les paramètres UTM qu'ils transportent, les règles générales et le domaine de leurs liens courts."
+mautic.smartlinks.settings.short_link_domain="Domaine de liens courts"
+mautic.smartlinks.settings.short_link_domain.tooltip="Domaine utilisé pour créer les futurs liens courts, par exemple lnk.exemple.com. N'incluez pas https://."
+mautic.smartlinks.settings.placeholder="Les Smart Links apparaîtront ici."
+
+; Smart Links (menu principal > Smart Links). Base de traduction mautic.smartlinks.smart_links.
+mautic.smartlinks.smart_links.header.index="Smart Links"
+mautic.smartlinks.smart_links.header.new="Nouveau Smart Link"
+mautic.smartlinks.smart_links.header.edit="Smart Link - %slug%"
+mautic.smartlinks.smart_links.slug="Slug"
+mautic.smartlinks.smart_links.slug.tooltip="Texte court (9 caractères maximum). Les espaces sont remplacés par le caractère configuré, les majuscules sont converties en minuscules à l'enregistrement. Le slug ne peut plus être modifié après la création du lien."
+mautic.smartlinks.smart_links.slug.generate="Générer"
+mautic.smartlinks.smart_links.slug.generate.tooltip="Utiliser un slug aléatoire de 4 lettres et chiffres."
+mautic.smartlinks.smart_links.short_link="Lien court"
+mautic.smartlinks.smart_links.domain.reminder="Domaine des liens courts :"
+mautic.smartlinks.smart_links.domain.reminder.empty="Aucun domaine de liens courts configuré. Définissez-le dans Paramètres > Configuration > Paramètres Smart Links."
+mautic.smartlinks.smart_links.redirect_type="Type de redirection"
+mautic.smartlinks.smart_links.redirect_type.mautic="Mautic"
+mautic.smartlinks.smart_links.redirect_type.external="Externe"
+mautic.smartlinks.smart_links.redirect_code="Code HTTP de redirection"
+mautic.smartlinks.smart_links.redirect_code.301="301 - Déplacé de façon permanente — permanent"
+mautic.smartlinks.smart_links.redirect_code.302="302 - Trouvé — temporaire"
+mautic.smartlinks.smart_links.redirect_code.307="307 - Redirection temporaire — temporaire"
+mautic.smartlinks.smart_links.redirect_code.308="308 - Redirection permanente — permanent"
+mautic.smartlinks.smart_links.destination_url="URL de destination"
+mautic.smartlinks.smart_links.destination_url.tooltip="Page d'arrivée du visiteur, par exemple https://www.exemple.com/page. Utilisée uniquement pour les redirections externes."
+mautic.smartlinks.smart_links.destination="Destination"
+mautic.smartlinks.smart_links.destination.tooltip="La landing page ou le formulaire autonome vers lequel le visiteur est redirigé. Utilisé uniquement pour les redirections Mautic."
+mautic.smartlinks.smart_links.destination.pages="Landing pages"
+mautic.smartlinks.smart_links.destination.forms="Formulaires autonomes"
+mautic.smartlinks.smart_links.destination.unpublished="Plus publié"
+mautic.smartlinks.smart_links.utm_parameters="Paramètres UTM"
+mautic.smartlinks.smart_links.utm_parameters.help="Choisissez d’abord la taxonomie UTM : chaque valeur ci-dessous est choisie parmi celles qu’elle autorise."
+
+mautic.smartlinks.smart_links.onboarding.heading="Aucun Smart Link"
+mautic.smartlinks.smart_links.onboarding.subheading="Les Smart Links sont des liens courts qui transportent vos paramètres UTM."
+mautic.smartlinks.smart_links.onboarding.copy="Utilisez le bouton Nouveau ci-dessus pour en créer un. Son slug ne peut pas être modifié après la création ; supprimez-le et créez-en un nouveau."
+mautic.smartlinks.smart_links.menu.new="Nouveau Smart Link"
+mautic.smartlinks.smart_links.menu.edit="Modifier %name%"
+mautic.smartlinks.smart_links.menu.delete="Supprimer %name%"
+mautic.smartlinks.smart_links.form.confirmdelete="Supprimer le Smart Link %name% ? Il ne pourra pas être restauré."
+mautic.smartlinks.smart_links.form.confirmbatchdelete="Supprimer les Smart Links sélectionnés ? Ils ne pourront pas être restaurés."
+mautic.smartlinks.smart_links.error.notfound="Aucun Smart Link avec l'identifiant %id%."
+mautic.smartlinks.smart_links.permissions.header="Smart Links - L'utilisateur a accès à"
+mautic.smartlinks.smart_links.hits="Clics"
+mautic.smartlinks.smart_links.hits.tooltip="Nombre de fois où le lien court a redirigé un visiteur."
+
+mautic.smartlinks.config.description="Définissez les paramètres UTM proposés par le générateur de liens et leur mode de saisie."
+mautic.smartlinks.config.section.utm_settings="Paramètres UTM"
+mautic.smartlinks.config.section.parameters="Paramètres"
+mautic.smartlinks.config.group.standard="UTM standards"
+mautic.smartlinks.config.group.platform="Identifiants de plateformes"
+mautic.smartlinks.config.group.custom="Paramètres personnalisés"
+
+mautic.smartlinks.config.enforce_lowercase="Forcer les minuscules sur toutes les valeurs"
+mautic.smartlinks.config.enforce_lowercase.tooltip="Le générateur de liens convertit toutes les valeurs des paramètres en minuscules."
+mautic.smartlinks.config.separator_replacement="Caractère de remplacement des espaces"
+mautic.smartlinks.config.separator_replacement.tooltip="Caractère qui remplace les espaces dans les valeurs des paramètres."
+mautic.smartlinks.config.separator.hyphen="Tiret ( - )"
+mautic.smartlinks.config.separator.underscore="Tiret bas ( _ )"
+mautic.smartlinks.config.separator.dot="Point ( . )"
+
+mautic.smartlinks.config.parameter.enabled="Activé"
+mautic.smartlinks.config.parameter.label="Libellé"
+mautic.smartlinks.config.parameter.mode="Mode"
+mautic.smartlinks.config.parameter.key="Clé"
+mautic.smartlinks.config.parameter.key.tooltip="Nom du paramètre dans l'URL : lettres minuscules, chiffres et tirets bas, commençant par une lettre (2 à 41 caractères)."
+mautic.smartlinks.config.mode.dropdown="Liste déroulante (liste de valeurs)"
+mautic.smartlinks.config.mode.free="Texte libre"
+mautic.smartlinks.config.mode.disabled="Désactivé"
+mautic.smartlinks.config.auto_generated.badge="Auto"
+mautic.smartlinks.config.auto_generated.tooltip="Généralement ajouté automatiquement par la plateforme publicitaire. Activez-le uniquement si vous devez le gérer manuellement."
+
+mautic.smartlinks.config.values="Valeurs autorisées"
+mautic.smartlinks.config.values.value="Valeur"
+mautic.smartlinks.config.values.label="Libellé"
+mautic.smartlinks.config.values.default="Par défaut"
+mautic.smartlinks.config.values.add="Ajouter une valeur"
+mautic.smartlinks.config.values.remove="Supprimer la valeur"
+mautic.smartlinks.config.values.drag="Glisser pour réordonner"
+mautic.smartlinks.config.values.empty="Aucune valeur pour le moment."
+mautic.smartlinks.config.values.suggestions="Charger les valeurs suggérées"
+mautic.smartlinks.config.values.import="Coller des valeurs (une par ligne, ou valeur;libellé)"
+mautic.smartlinks.config.values.import.placeholder="newsletter;Newsletter"
+mautic.smartlinks.config.values.import.button="Importer"
+
+mautic.smartlinks.config.custom.add="Ajouter un paramètre personnalisé"
+mautic.smartlinks.config.custom.remove="Supprimer"
+mautic.smartlinks.config.custom.new="nouveau paramètre"
+mautic.smartlinks.config.custom.empty="Aucun paramètre personnalisé."
+
+mautic.smartlinks.config.parameter.utm_source.label="Source"
+mautic.smartlinks.config.parameter.utm_source.description="Origine du trafic, par exemple newsletter, linkedin ou google."
+mautic.smartlinks.config.parameter.utm_medium.label="Support"
+mautic.smartlinks.config.parameter.utm_medium.description="Type de canal, par exemple email, cpc, social ou referral."
+mautic.smartlinks.config.parameter.utm_campaign.label="Campagne"
+mautic.smartlinks.config.parameter.utm_campaign.description="Nom de la campagne."
+mautic.smartlinks.config.parameter.utm_term.label="Terme"
+mautic.smartlinks.config.parameter.utm_term.description="Mot-clé de la recherche payante."
+mautic.smartlinks.config.parameter.utm_content.label="Contenu"
+mautic.smartlinks.config.parameter.utm_content.description="Distingue les variantes ou les liens qui pointent vers la même URL."
+mautic.smartlinks.config.parameter.utm_id.label="ID de campagne"
+mautic.smartlinks.config.parameter.utm_id.description="Identifiant de campagne, utilisé par l'import de données GA4."
+mautic.smartlinks.config.parameter.utm_source_platform.label="Plateforme source"
+mautic.smartlinks.config.parameter.utm_source_platform.description="Plateforme qui gère la campagne, par exemple Google Ads."
+mautic.smartlinks.config.parameter.utm_creative_format.label="Format créatif"
+mautic.smartlinks.config.parameter.utm_creative_format.description="Type de création, par exemple display, vidéo ou native."
+mautic.smartlinks.config.parameter.utm_marketing_tactic.label="Tactique marketing"
+mautic.smartlinks.config.parameter.utm_marketing_tactic.description="Tactique de ciblage, par exemple prospection ou remarketing."
+mautic.smartlinks.config.parameter.gclid.label="ID de clic Google Ads"
+mautic.smartlinks.config.parameter.gclid.description="Identifiant de clic ajouté par Google Ads."
+mautic.smartlinks.config.parameter.gbraid.label="ID Google Ads iOS web vers app"
+mautic.smartlinks.config.parameter.gbraid.description="Identifiant de clic ajouté par Google Ads pour la mesure iOS du web vers l'application."
+mautic.smartlinks.config.parameter.wbraid.label="ID Google Ads iOS app vers web"
+mautic.smartlinks.config.parameter.wbraid.description="Identifiant de clic ajouté par Google Ads pour la mesure iOS de l'application vers le web."
+mautic.smartlinks.config.parameter.dclid.label="ID de clic Display & Video 360"
+mautic.smartlinks.config.parameter.dclid.description="Identifiant de clic ajouté par Google Display & Video 360."
+mautic.smartlinks.config.parameter.fbclid.label="ID de clic Meta"
+mautic.smartlinks.config.parameter.fbclid.description="Identifiant de clic ajouté par Meta (Facebook, Instagram)."
+mautic.smartlinks.config.parameter.msclkid.label="ID de clic Microsoft Advertising"
+mautic.smartlinks.config.parameter.msclkid.description="Identifiant de clic ajouté par Microsoft Advertising."
+mautic.smartlinks.config.parameter.ttclid.label="ID de clic TikTok"
+mautic.smartlinks.config.parameter.ttclid.description="Identifiant de clic ajouté par TikTok."
+mautic.smartlinks.config.parameter.li_fat_id.label="ID de clic LinkedIn"
+mautic.smartlinks.config.parameter.li_fat_id.description="Identifiant de clic ajouté par LinkedIn."
+mautic.smartlinks.config.parameter.twclid.label="ID de clic X"
+mautic.smartlinks.config.parameter.twclid.description="Identifiant de clic ajouté par X (Twitter)."
+mautic.smartlinks.config.parameter.epik.label="ID de clic Pinterest"
+mautic.smartlinks.config.parameter.epik.description="Identifiant de clic ajouté par Pinterest."
+
+mautic.smartlinks.config.suggestion.newsletter="Newsletter"
+mautic.smartlinks.config.suggestion.linkedin="LinkedIn"
+mautic.smartlinks.config.suggestion.facebook="Facebook"
+mautic.smartlinks.config.suggestion.instagram="Instagram"
+mautic.smartlinks.config.suggestion.google="Google"
+mautic.smartlinks.config.suggestion.youtube="YouTube"
+mautic.smartlinks.config.suggestion.x="X"
+mautic.smartlinks.config.suggestion.tiktok="TikTok"
+mautic.smartlinks.config.suggestion.partner="Partenaire"
+mautic.smartlinks.config.suggestion.direct="Direct"
+mautic.smartlinks.config.suggestion.email="E-mail"
+mautic.smartlinks.config.suggestion.cpc="Coût par clic"
+mautic.smartlinks.config.suggestion.social="Réseaux sociaux"
+mautic.smartlinks.config.suggestion.social_paid="Réseaux sociaux payants"
+mautic.smartlinks.config.suggestion.display="Display"
+mautic.smartlinks.config.suggestion.affiliate="Affiliation"
+mautic.smartlinks.config.suggestion.referral="Site référent"
+mautic.smartlinks.config.suggestion.qr="QR code"
+mautic.smartlinks.config.suggestion.sms="SMS"
+mautic.smartlinks.config.suggestion.print="Imprimé"
+mautic.smartlinks.config.suggestion.event="Événement"
+mautic.smartlinks.config.suggestion.google_ads="Google Ads"
+mautic.smartlinks.config.suggestion.meta_ads="Meta Ads"
+mautic.smartlinks.config.suggestion.linkedin_ads="LinkedIn Ads"
+mautic.smartlinks.config.suggestion.microsoft_ads="Microsoft Ads"
+mautic.smartlinks.config.suggestion.tiktok_ads="TikTok Ads"
+mautic.smartlinks.config.suggestion.banner="Bannière"
+mautic.smartlinks.config.suggestion.video="Vidéo"
+mautic.smartlinks.config.suggestion.carousel="Carrousel"
+mautic.smartlinks.config.suggestion.text="Texte"
+mautic.smartlinks.config.suggestion.native="Native"
+mautic.smartlinks.config.suggestion.prospecting="Prospection"
+mautic.smartlinks.config.suggestion.remarketing="Remarketing"
+mautic.smartlinks.config.suggestion.retargeting="Retargeting"
+mautic.smartlinks.config.suggestion.brand="Marque"
+mautic.smartlinks.config.suggestion.nurturing="Nurturing"
+
+; Section « UTM tags » des formulaires Email et Focus.
+mautic.smartlinks.form.choose="Choisir..."
+mautic.smartlinks.form.legacy_choice="%value% (hors taxonomie)"
+mautic.smartlinks.form.legacy_warning="Cette valeur ne fait pas partie de la taxonomie UTM."
+mautic.smartlinks.form.no_values="Aucune valeur configurée pour ce paramètre. Contactez un administrateur."
+
+; Formulaire Smart Link et taxonomies UTM (Smart Links > Taxonomies UTM). Base de traduction mautic.smartlinks.taxonomies.
+mautic.smartlinks.smart_links.taxonomy="Taxonomie UTM"
+mautic.smartlinks.smart_links.taxonomy.tooltip="L’ensemble des valeurs autorisées pour les paramètres UTM de ce lien. Chaque valeur du lien est choisie parmi celles qu’autorise la taxonomie."
+mautic.smartlinks.taxonomies.header.index="Taxonomies UTM"
+mautic.smartlinks.taxonomies.header.new="Nouvelle taxonomie UTM"
+mautic.smartlinks.taxonomies.header.edit="Taxonomie UTM - %name%"
+mautic.smartlinks.taxonomies.name="Nom"
+mautic.smartlinks.taxonomies.name.tooltip="Un nom court et unique identifiant cet ensemble de valeurs UTM autorisées."
+mautic.smartlinks.taxonomies.description="Description"
+mautic.smartlinks.taxonomies.parameters="Paramètres UTM"
+mautic.smartlinks.taxonomies.parameters.help="Chaque paramètre activé dans Paramètres Smart Links apparaît. Les paramètres en liste déroulante offrent les valeurs définies par l’administrateur : cochez celles qu’un Smart Link peut porter. Les paramètres en texte libre reçoivent ici leur propre liste de valeurs : le lien y choisira une valeur au lieu de saisir librement."
+mautic.smartlinks.taxonomies.parameter_count="Paramètres"
+mautic.smartlinks.taxonomies.parameter_count.tooltip="Le nombre de paramètres pour lesquels cette taxonomie définit des valeurs."
+mautic.smartlinks.taxonomies.menu.new="Nouvelle taxonomie UTM"
+mautic.smartlinks.taxonomies.menu.edit="Modifier %name%"
+mautic.smartlinks.taxonomies.menu.delete="Supprimer %name%"
+mautic.smartlinks.taxonomies.form.confirmdelete="Supprimer la taxonomie UTM %name% ? Elle ne pourra pas être restaurée. Les Smart Links qui l’utilisent conservent les valeurs qu’ils portent déjà et demanderont une nouvelle taxonomie à leur prochaine modification."
+mautic.smartlinks.taxonomies.form.confirmbatchdelete="Supprimer les taxonomies UTM sélectionnées ? Elles ne pourront pas être restaurées."
+mautic.smartlinks.taxonomies.error.notfound="Aucune taxonomie UTM avec l’identifiant %id%."
+mautic.smartlinks.taxonomies.permissions.header="Taxonomies UTM - L’utilisateur a accès à"
+mautic.smartlinks.taxonomies.onboarding.heading="Aucune taxonomie UTM"
+mautic.smartlinks.taxonomies.onboarding.subheading="Les taxonomies UTM sont des ensembles de valeurs autorisées pour les paramètres UTM de vos Smart Links."
+mautic.smartlinks.taxonomies.onboarding.copy="Utilisez le bouton Nouveau ci-dessus pour en créer une. Un Smart Link porte une taxonomie ; chaque valeur UTM qu’il porte est choisie parmi celles que la taxonomie autorise."
+mautic.smartlinks.taxonomies.unpublished_choice="%name% (plus publiée)"
+mautic.smartlinks.taxonomies.free_values.tooltip="Les valeurs autorisées de ce paramètre pour les liens utilisant cette taxonomie. Une valeur par ligne, éventuellement valeur;Libellé."
+mautic.smartlinks.taxonomies.free_values.placeholder="une valeur par ligne"
+mautic.smartlinks.taxonomies.no_values.tooltip="Aucune valeur n’est encore configurée pour ce paramètre dans Paramètres Smart Links : demandez à l’administrateur d’en configurer."
diff --git a/Translations/fr_FR/validators.ini b/Translations/fr_FR/validators.ini
new file mode 100644
index 0000000..b91b996
--- /dev/null
+++ b/Translations/fr_FR/validators.ini
@@ -0,0 +1,40 @@
+; Messages de validation de Paramètres > Configuration > Paramètres UTM (domaine validators de Symfony).
+mautic.smartlinks.config.error.key_required="Saisissez une clé pour le paramètre personnalisé."
+mautic.smartlinks.config.error.key_invalid="La clé « %key% » n'est pas valide. Utilisez de 2 à 41 lettres minuscules, chiffres ou tirets bas, en commençant par une lettre."
+mautic.smartlinks.config.error.key_reserved="La clé « %key% » est réservée. Les clés du catalogue, « ct », les clés commençant par « utm » et celles commençant par « mtc_ » ne peuvent pas être utilisées."
+mautic.smartlinks.config.error.key_duplicate="La clé « %key% » est utilisée par plusieurs paramètres personnalisés."
+mautic.smartlinks.config.error.mode_invalid="Ce mode n'est pas disponible pour ce paramètre."
+mautic.smartlinks.config.error.separator_invalid="Choisissez un tiret, un tiret bas ou un point."
+mautic.smartlinks.config.error.label_required="Saisissez un libellé."
+mautic.smartlinks.config.error.label_length="Le libellé ne peut pas dépasser {{ limit }} caractères."
+mautic.smartlinks.config.error.label_invalid="Le libellé ne peut pas contenir le caractère %."
+mautic.smartlinks.config.error.value_required="Saisissez une valeur."
+mautic.smartlinks.config.error.value_length="La valeur ne peut pas dépasser {{ limit }} caractères."
+mautic.smartlinks.config.error.value_invalid="Les valeurs ne peuvent contenir que des lettres minuscules, des chiffres, des tirets, des tirets bas et des points."
+mautic.smartlinks.config.error.value_duplicate="La valeur « %value% » apparaît plusieurs fois."
+mautic.smartlinks.config.error.values_required="Un paramètre activé en mode liste déroulante doit avoir au moins une valeur."
+mautic.smartlinks.config.error.default_multiple="Une seule valeur peut être la valeur par défaut."
+
+; Section « UTM tags » des formulaires Email et Focus.
+mautic.smartlinks.form.error.not_in_taxonomy="Cette valeur ne fait pas partie de la taxonomie UTM. Choisissez une valeur de la liste."
+
+; Formulaire Smart Link (menu principal > Smart Links).
+mautic.smartlinks.smart_links.error.slug_required="Saisissez un slug."
+mautic.smartlinks.smart_links.error.slug_length="Le slug ne peut pas dépasser {{ limit }} caractères."
+mautic.smartlinks.smart_links.error.slug_characters="Le slug ne peut contenir que des lettres, des chiffres, des tirets, des tirets bas et des points."
+mautic.smartlinks.smart_links.error.slug_taken="Un autre Smart Link utilise déjà le slug « %slug% ». Choisissez-en un autre."
+mautic.smartlinks.smart_links.error.slug_immutable="Le slug d'un Smart Link ne peut pas être modifié. Supprimez-le et créez-en un nouveau."
+mautic.smartlinks.smart_links.error.destination_required="Saisissez l'URL de destination de la redirection externe."
+mautic.smartlinks.smart_links.error.destination_required_mautic="Choisissez une landing page ou un formulaire autonome comme destination de la redirection Mautic."
+mautic.smartlinks.smart_links.error.destination_invalid="L'URL de destination doit être une URL http(s) valide."
+mautic.smartlinks.smart_links.error.utm_value_invalid="Le paramètre « %key% » n'est pas activé, ou sa valeur n'est pas valide. Utilisez uniquement des lettres minuscules, des chiffres, des tirets, des tirets bas et des points."
+mautic.smartlinks.smart_links.error.utm_value_not_allowed="La valeur « %value% » du paramètre « %key% » ne fait pas partie des valeurs autorisées."
+
+; Formulaire de taxonomie UTM et valeurs des Smart Links pilotées par taxonomie.
+mautic.smartlinks.taxonomies.error.name_required="Saisissez un nom."
+mautic.smartlinks.taxonomies.error.name_length="Le nom ne peut pas dépasser {{ limit }} caractères."
+mautic.smartlinks.taxonomies.error.name_taken="Une autre taxonomie UTM utilise déjà le nom %name%."
+mautic.smartlinks.taxonomies.error.name_characters="Le nom ne peut pas contenir les caractères %, { ou }."
+mautic.smartlinks.taxonomies.error.value_invalid="La valeur %value% est invalide. Utilisez uniquement des lettres minuscules, des chiffres, des tirets, des tirets bas et des points."
+mautic.smartlinks.smart_links.error.taxonomy_required="Choisissez une taxonomie UTM."
+mautic.smartlinks.smart_links.error.taxonomy_parameter_unknown="Le paramètre %key% ne fait pas partie de la taxonomie %name%."
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 0000000..53a70ad
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,13 @@
+
+
+
+
+
+ Tests
+
+
+
diff --git a/readme.md b/readme.md
index 09fa9ab..aec99ec 100644
--- a/readme.md
+++ b/readme.md
@@ -1,8 +1,8 @@
-# Mautic Marketing Program plugin
+# Mautic MT3S Marketing plugin
-A custom Mautic 7 plugin (`MT3SMarketingProgramBundle`) for managing marketing programs: a name, status, owner, dates, budget and category, with their mt3s_mp_programs.
+A custom Mautic 7 plugin (`MT3SMarketingProgramBundle`) by MT3 Solutions with two separate domains: **Marketing Programs** — programs with a name, status, owner, dates, budget and category, with their mt3s_mp_programs — and **Smart Links** — short links (`/l/{slug}`) that tag the click with the UTM parameters of a UTM taxonomy before redirecting. The two domains share one bundle, one permission base (`mt3smarketingprogram:*`), one Plugins page entry and one config page, but keep separate menus, tables and code.
-This repository holds only the plugin source. The bundle files are at the repository root, and Mautic loads them from `docroot/plugins/MT3SMarketingProgramBundle`. The plugin was called `PlanBundle` before 0.16.0 and `ProgramBundle` (with programs) before 0.17.0: see *Rename history* below.
+This repository holds only the plugin source. The bundle files are at the repository root, and Mautic loads them from `docroot/plugins/MT3SMarketingProgramBundle`. The plugin was called `PlanBundle` before 0.16.0 and `ProgramBundle` (with programs) before 0.17.0, and the Smart Links used to be a separate `SmartlinksBundle` plugin before 0.18.0: see *Rename history* below.
## Installation
@@ -16,7 +16,15 @@ This repository holds only the plugin source. The bundle files are at the reposi
3. In Mautic, go to **Settings > Plugins**, open **MT3S Marketing Program** and publish it.
-Programs are listed under **Marketing Programs** in the main menu (URL `/s/marketing-programs`), tasks under **Marketing Programs > Tasks** (URL `/s/marketing-program-tasks`), the stakeholder directory under **Marketing Programs > Stakeholders** (URL `/s/marketing-program-stakeholders`), and the audience directory under **Marketing Programs > Audiences** (URL `/s/marketing-program-audiences`). The item type lists are edited under **Marketing Programs > Item types** (URL `/s/marketing-program-item-types`). The UTM Taxonomies page (URL `/s/marketing-program-utm-taxonomies`) is a placeholder for a coming feature and is kept out of the menu. Users who aren't administrators need a role with the **Marketing Program Permissions** set in **Settings > Roles**.
+Programs are listed under **Marketing Programs** in the main menu (URL `/s/marketing-programs`), tasks under **Marketing Programs > Tasks** (URL `/s/marketing-program-tasks`), the stakeholder directory under **Marketing Programs > Stakeholders** (URL `/s/marketing-program-stakeholders`), and the audience directory under **Marketing Programs > Audiences** (URL `/s/marketing-program-audiences`). The item type lists are edited under **Marketing Programs > Item types** (URL `/s/marketing-program-item-types`). The Smart Links of the second domain are listed under **Smart Links > Smart Links** (URL `/s/smart-links`) and their UTM taxonomies under **Smart Links > UTM Taxonomies** (URL `/s/utm-taxonomies`). Users who aren't administrators need a role with the **Marketing Program Permissions** set in **Settings > Roles** (the Smart Links domain adds `mt3smarketingprogram:smart_links:*` and `mt3smarketingprogram:taxonomies:*`; the marketing program domain uses `mt3smarketingprogram:programs:*` and its other keys).
+
+### Smart Links
+
+- A **smart link** is a short link: a slug (like `https://m.shrl.be/l/y32b`), a destination URL, and an optional **UTM taxonomy**. When it is hit, the visitor is redirected to the destination with the taxonomy's UTM parameters appended, and the hit is recorded (`smart_link_hits`).
+- The **UTM taxonomies** (`/s/utm-taxonomies`) define, per UTM parameter (`utm_source`, `utm_medium`, `utm_campaign`, `utm_content`, `utm_term`), whether and how the taxonomy's values apply: as a fixed value, as a pick list on the link, or as a free text field. The Smart Link form then shows exactly the fields the taxonomy allows, and rejects values outside a pick list.
+- The **short link domain** is set under **Settings > Configuration > Smart Links Settings**, together with which UTM parameters to use and their modes. The public `/l/{slug}` route only answers on the configured domain (404 elsewhere), doesn't require authentication, and records one hit for the statistics; a statistics failure never blocks the redirect. The redirect status code (301, 302, …) is per link.
+- A link redirects to its external **destination URL**, or — redirect type `mautic` — to its Mautic **landing page or standalone form**. The redirect never happens for an unknown slug, an unpublished link, or a link without destination: 404.
+- The Smart Links domain was merged from the standalone `SmartlinksBundle` plugin (versions 0.1.0 to 0.6.0) in 0.18.0: routes, tables, URL format and translation keys are unchanged, so existing short links keep working. Roles must be re-granted (`smartlinks:smart_links:*` → `mt3smarketingprogram:smart_links:*`, `smartlinks:taxonomies:*` → `mt3smarketingprogram:taxonomies:*`).
Before using the items of a program's **Insights**, **Objectives**, **Allocations** and **Tasks** tabs, set up their types under **Marketing Programs > Item types** (`mt3smarketingprogram:itemtypes:view` to see the page, `mt3smarketingprogram:itemtypes:edit` to save it).
@@ -69,7 +77,11 @@ The plugin uses the IntegrationsBundle conventions:
- `Resources/views/Program/form.html.twig` and `details.html.twig`: the create/edit form and the detail page. Both have the same seven tabs, from `_tabs.html.twig`: **Details**, **Insights** (description items), **Objectives**, **Allocations** (planned budget, currency and allocation items), **Audiences**, **Stakeholders** and **Tasks**.
- `Resources/views/Program/_task_table.html.twig`: the program's tasks in the Tasks tab. It has the harmonized tab columns (pictogram, Type, Name with kind badge for milestones and phases, Description, Start date, End date, Status — no ID), one row per task, no tree: a phase's or milestone's badge marks it in the name column. On the detail page it has an **Add task** button, links to each task and the filter/sort of the other tabs. On the program form it is read-only (no links, no filter), so that following a link doesn't drop unsaved changes.
- `Controller/TaskController.php` and `Resources/views/Task/`: the task list, and the create/edit form (**Marketing Programs > Tasks**). `new?program=ID` preselects the program. After Save or Cancel, the user goes back to where the form was opened from. Opened from **Marketing Programs > Tasks**, that's the task list. Opened from a program's Tasks tab, whose links carry `returnTo=program`, that's the program (its new program, if the task was moved). The origin is stored in the session when the form is opened, because the form posts without the query string.
-- `Controller/UtmTaxonomyController.php` and `Resources/views/UtmTaxonomy/`: the placeholder page for the coming UTM Taxonomies feature, kept out of the menu (reachable at `/s/marketing-program-utm-taxonomies`).
+- `Controller/SmartLinkController.php` and `Resources/views/SmartLink/`: the Smart Links list and form (**Smart Links > Smart Links**, `/s/smart-links`), built on core's `AbstractStandardFormController`.
+- `Controller/UtmTaxonomyController.php` and `Resources/views/UtmTaxonomy/`: the UTM taxonomies list and form (**Smart Links > UTM Taxonomies**, `/s/utm-taxonomies`). Replaced the placeholder page of 0.17.0 in 0.18.0. `Model/UtmTaxonomyModel.php`, `Model/SmartLinkModel.php`, `Entity/SmartLink.php`, `Entity/SmartLinkHit.php`, `Entity/UtmTaxonomy.php` (tables `smart_links`, `smart_link_hits`, `utm_taxonomies` — unchanged from the standalone plugin), `Catalog/` (redirect codes 301/302/307/308, redirect types `external`/`mautic`, the UTM parameter catalog and its modes), `Form/` (the link and taxonomy forms, the per-taxonomy UTM fields via `Form/UtmFieldsApplicator.php`, the validators) and `Controller/PublicController.php` (the public `/l/{slug}`) make up the Smart Links domain.
+- `EventListener/SmartLinksConfigSubscriber.php`: adds the **Smart Links Settings** tab to Settings > Configuration (`Form/Type/SmartLinksConfigType.php`, `Form/Type/SmartlinksSettingsType.php`, `Integration/Support/ConfigSupport.php`), next to the plugin's **Program Settings** tab; `Service/UtmConfigurationProvider.php` and `Service/UtmConfigurationNormalizer.php` read those parameters, `Service/SmartLinkShortUrlBuilder.php` builds the redirect URLs.
+- `Assets/js/mt3s-mp-smartlinks.js`: the Smart Links form script (started by `Mautic.smartlinksSmartLinkOnLoad()` when a page's `mauticContent` is `smartlinksSmartLink`).
+- `Tests/Unit/` and `phpunit.xml.dist`: the plugin's unit test suite (mostly covering the Smart Links domain: the catalog, the entities, the form type, the fields applicator, the validators, the models and the configuration provider).
- `Controller/ItemTypesController.php` and `Resources/views/ItemTypes/form.html.twig`: the Item types page (**Marketing Programs > Item types**). The type lists that used to be sections of **Settings > Configuration > Marketing Program Settings** (insights, allocation, objective, task, stakeholder types and the audience decision roles and tones) are edited here. `Form/Type/ItemTypesType.php` builds the lists, `Service/ItemTypeInUseGuard.php` refuses to remove a type that items still use, and the page saves through core's `Configurator` exactly like the Settings pages do: merge into `config/local.php`, write, refresh the config cache. **Settings > Configuration > Marketing Program Settings** keeps only the plugin's general settings: the currency, the stakeholder phone region and the audience attribute toggles.
- `Assets/js/mt3s-mp-program.js`: on the form, the objectives editor (add, remove, drag-and-drop ordering), and after a failed save, marking the tabs that contain errors with an icon and opening the first one. Started by `Mautic.mt3sMpProgramOnLoad()`.
@@ -218,6 +230,7 @@ The plugin was born as `PlanBundle` with a `Plan` entity (table `plans`) and men
- Before 0.15.0: "targets" were renamed to "audiences" (entity `Audience`, table `plan_targets` → `plan_audiences`), with Mautic segments attached to each audience.
- 0.16.0: the full rename to `ProgramBundle` / `Program` (and a "plan" became an "initiative"). The bundle namespace, class names, the `plugins` DB row (`ProgramBundle`), all tables (`plan_*` → `initiative_*`), all columns (`plan_id` → `initiative_id`, `role_in_plan` → `role_in_initiative`), all permission keys (`plan:*` → `program:*`), the config parameters and the menu (root **Programs**, entry **Initiatives**, plus the placeholder **UTM Taxonomies**) took the new names. The data was kept: the migration renames the tables, it doesn't rebuild them.
- 0.17.0: the rename to `MT3SMarketingProgramBundle` / "MT3S Marketing Program", and an initiative became a marketing program. The bundle namespace, class names, the `plugins` DB row (`MT3SMarketingProgramBundle`, name "MT3S Marketing Program"), all tables (`initiative_*` → `mt3s_mp_program_*`), all columns (`initiative_id` → `program_id`, `role_in_initiative` → `role_in_program`), all permission keys (`program:*` → `mt3smarketingprogram:*`), the routes, the service IDs, the config parameters, the URLs (`/s/marketing-programs`, …) and the menu (root **Marketing Programs**, entry **Marketing Programs**) took the new names, and the plugin's events (`mt3s.marketing_program.*`) and the `mt3s:marketing-program:refresh-stats` command were added. The data was kept again: `Version_0_17_0.php` renames the tables and carries over the rows the rename orphans — the plugins row, the roles' permission rows (which the 0.16.0 rename had missed), the categories (`plan`- and `initiative`-era rows) and the audit log.
+- 0.18.0: the merge of the standalone **Smartlinks** plugin (`SmartlinksBundle`, versions 0.1.0–0.6.0) into this bundle. The Smart Links and UTM Taxonomies code, tables (`smart_links`, `smart_link_hits`, `utm_taxonomies`), routes (`/s/smart-links`, `/s/utm-taxonomies`, the public `/l/{slug}`), translation keys (`mautic.smartlinks.*`) and settings keys (`smartlinks_*`, with the legacy `utm_manager_*` keys still readable) are unchanged; only the PHP namespace (`MauticPlugin\SmartlinksBundle\` → `MauticPlugin\MT3SMarketingProgramBundle\`), the service IDs, the template namespace (`@Smartlinks/` → `@MT3SMarketingProgram/`), the **Plugins page entry** (one row: "MT3S Marketing Program") and the **permission base** changed (`smartlinks:smart_links:*` → `mt3smarketingprogram:smart_links:*`, `smartlinks:taxonomies:*` → `mt3smarketingprogram:taxonomies:*` — roles must be re-granted). The incoming migrations were renamed `Version_0_X_0_SmartLinks.php` to avoid the class-name collision with this bundle's own migrations. The old placeholder page `/s/marketing-program-utm-taxonomies` is gone (the real feature is at `/s/utm-taxonomies`), and the dev environment mounts only this repository. The source repository is archived at its `post-merge-v1` tag.
- The old URLs (`/s/plans`, `/s/plan-tasks`, `/s/programs`, `/s/program-tasks`, …) are gone: the routes were renamed and the old names return 404.
A rename like this needs care: