One bundle, two domains (Marketing Programs and Smart Links), one naming scheme.\nNothing in the database changed (no tables, columns, URLs or stored data);\nthe runtime was rebuilt and verified live.\n\n- Route names mautic_smartlinks_* -> mt3s_smartlinks_* (paths unchanged);\n the menu ids follow\n- Model service aliases collapsed to one canonical alias per model:\n mautic.mt3smarketingprogram.model.<entity> (core's mautic.<x>.model.<x>\n pattern), so getModel('mt3smarketingprogram.smart_link'); the dead\n mt3s.* and mautic.mt3smp.*-era aliases are gone\n- Translation keys mautic.smartlinks.* -> mt3s.smart_links.*\n (mautic.config.tab.smartlinksconfig stays: core derives it)\n- Settings parameters smartlinks_utm_config/smartlinks_config ->\n mt3s_smart_links_utm_config/mt3s_smart_links_config, with both legacy\n keys (smartlinks_* of the standalone bundle, utm_manager_* of the\n UtmManagerBundle era) still readable until the settings are saved again\n- JS loader prefixes smartlinksSmartLink/smartlinksUtmTaxonomy ->\n mt3sMpSmartLink/mt3sMpUtmTaxonomy (the mt3sMp* family of the program\n domain)\n- Integration/Support/ConfigSupport -> SmartlinksConfigSupport; integration\n display names aligned ('MT3S Marketing Program' / 'Smart Links'); the\n dead mautic.plugin.smartlinks.name catalog keys removed\n- phpunit suite renamed UtmManagerBundle -> MT3SMarketingProgramBundle;\n version 0.18.1\n\nVerified: full php -l, 90/90 unit tests (phpunit 11.5 phar), cache clear +\nwarm + assets regenerate + plugins reload (as www-data), live: both lists\nand forms (mauticContent mt3sMpSmartLink/mt3sMpUtmTaxonomy), both config\ntabs, the menu labels, the program pages (regression), the public /l/y32b\nredirect through the legacy utm_manager_* settings (302 with the taxonomy's\nUTM values, wrong host and unknown slug 404), all ini catalogs parse, zero\nnew log errors.
147 lines
4.8 KiB
PHP
147 lines
4.8 KiB
PHP
<?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 `mt3s_smart_links_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
|
|
);
|
|
}
|
|
}
|