Merge the Smartlinks plugin (SmartlinksBundle 0.6.0) into the bundle as the Smart Links domain (0.18.0)

Two domains, one MT3S bundle: Marketing Programs (unchanged) and the
imported Smart Links (smart links + UTM taxonomies), each keeping its
own menu, tables, routes and translations.

- Code moved from MauticPlugin\SmartlinksBundle\ to
  MauticPlugin\MT3SMarketingProgramBundle\; template namespace
  @Smartlinks/ -> @MT3SMarketingProgram/; smartlinks.js ->
  Assets/js/mt3s-mp-smartlinks.js; icon -> Assets/img/smartlinks-icon.svg.
- Incoming migrations renamed Version_0_X_0_SmartLinks.php to avoid
  the class-name collision; schema untouched, data intact.
- Permissions folded into MT3SMarketingProgramPermissions:
  smart_links + taxonomies under the mt3smarketingprogram: base
  (roles that had the old smartlinks: grants must be re-granted).
- config.php: Smart Links routes + menu group, public /l/{slug},
  SmartlinksIntegration services, smartlinks_* parameters (legacy
  utm_manager_* keys still readable), version 0.18.0. The 0.17.0
  placeholder /s/marketing-program-utm-taxonomies is replaced by the
  real /s/utm-taxonomies.
- Translations merged (en_US) and added (fr_FR); Tests/ + phpunit moved
  in; readme documents both domains and the 0.18.0 merge history.

Verified live: menus, both config tabs, both lists + forms, program
pages, public redirect with taxonomy UTM values, host + unknown-slug
404s, 90/90 unit tests, full php -l, all ini catalogs parse.
This commit is contained in:
Alexandre Gain committed 2026-11-16 13:48:13 +01:00
1 parent debce4ba4a
commit dce849610c
69 files changed
+8225 -43

No files matched your search

@@ -0,0 +1,146 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\DataTransformer;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterCatalog;
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterMode;
use MauticPlugin\MT3SMarketingProgramBundle\Service\UtmConfigurationNormalizer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Converts between the stored `smartlinks_utm_config` array (parameters keyed by their key)
* and the form structure (catalog parameters + a collection of custom parameters).
*
* @implements DataTransformerInterface<mixed, array<string, mixed>>
*/
final class UtmSettingsTransformer implements DataTransformerInterface
{
public function __construct(
private readonly UtmConfigurationNormalizer $normalizer,
private readonly UtmParameterCatalog $catalog,
private readonly TranslatorInterface $translator,
) {
}
/**
* Stored configuration => form data.
*
* @return array<string, mixed>
*/
public function transform(mixed $value): array
{
$config = $this->normalizer->normalize($value);
$parameters = [];
$custom = [];
foreach ($config['parameters'] as $key => $parameter) {
$definition = $this->catalog->get($key);
$row = [
'enabled' => $parameter['enabled'],
'label' => $parameter['label'],
'mode' => $parameter['mode'],
'values' => $this->valuesToForm($parameter['values'] ?? [], $parameter['default'] ?? null),
];
if (null === $definition) {
$custom[] = ['key' => $key] + $row;
continue;
}
if ('' === $row['label']) {
$row['label'] = $this->translator->trans($definition->getLabelKey());
}
$parameters[$key] = $row;
}
return [
'enforce_lowercase' => $config['enforce_lowercase'],
'separator_replacement' => $config['separator_replacement'],
'parameters' => $parameters,
'custom_parameters' => $custom,
];
}
/**
* Form data => stored configuration.
*
* @return array<string, mixed>
*/
public function reverseTransform(mixed $value): array
{
$value = is_array($value) ? $value : [];
$parameters = [];
foreach ($value['parameters'] ?? [] as $key => $parameter) {
$parameters[(string) $key] = $this->parameterToStorage($parameter);
}
foreach ($value['custom_parameters'] ?? [] as $parameter) {
$key = trim((string) ($parameter['key'] ?? ''));
if ('' !== $key) {
$parameters[$key] = $this->parameterToStorage($parameter);
}
}
return [
'enforce_lowercase' => UtmConfigurationNormalizer::toBool($value['enforce_lowercase'] ?? true),
'separator_replacement' => (string) ($value['separator_replacement'] ?? UtmConfigurationNormalizer::DEFAULT_SEPARATOR),
'parameters' => $parameters,
];
}
/**
* Only `dropdown` parameters keep values and a default; nothing else is stored for the other modes.
*
* @param array<string, mixed> $parameter
*
* @return array<string, mixed>
*/
private function parameterToStorage(array $parameter): array
{
$mode = (string) ($parameter['mode'] ?? UtmParameterMode::DISABLED);
$stored = [
'enabled' => UtmConfigurationNormalizer::toBool($parameter['enabled'] ?? false),
'label' => trim((string) ($parameter['label'] ?? '')),
'mode' => $mode,
];
if (UtmParameterMode::DROPDOWN !== $mode) {
return $stored;
}
$stored['values'] = [];
$stored['default'] = '';
foreach ($parameter['values'] ?? [] as $row) {
$rowValue = trim((string) ($row['value'] ?? ''));
if ('' === $rowValue) {
continue;
}
$stored['values'][] = ['value' => $rowValue, 'label' => trim((string) ($row['label'] ?? ''))];
if ('' === $stored['default'] && !empty($row['is_default'])) {
$stored['default'] = $rowValue;
}
}
return $stored;
}
/**
* @param list<array{value: string, label: string}> $values
*
* @return list<array{value: string, label: string, is_default: bool}>
*/
private function valuesToForm(array $values, ?string $default): array
{
return array_map(
fn (array $row): array => $row + ['is_default' => $row['value'] === $default],
$values
);
}
}