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.
101 lines
3.4 KiB
PHP
101 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Validator;
|
|
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterCatalog;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterMode;
|
|
|
|
/**
|
|
* Business rules of the UTM Manager configuration form. The form types call these methods
|
|
* from Callback constraints; each method returns translation keys (validators domain) and parameters.
|
|
*/
|
|
final class UtmSettingsValidator
|
|
{
|
|
/** Technical value written in the URL: lowercase letters, digits, "-", "_" and ".". */
|
|
public const VALUE_PATTERN = '/^[a-z0-9._-]+$/';
|
|
|
|
public const MAX_LENGTH = 100;
|
|
|
|
public const ERROR_KEY_INVALID = 'mautic.smartlinks.config.error.key_invalid';
|
|
public const ERROR_KEY_RESERVED = 'mautic.smartlinks.config.error.key_reserved';
|
|
public const ERROR_KEY_DUPLICATE = 'mautic.smartlinks.config.error.key_duplicate';
|
|
public const ERROR_VALUES_REQUIRED = 'mautic.smartlinks.config.error.values_required';
|
|
public const ERROR_VALUE_DUPLICATE = 'mautic.smartlinks.config.error.value_duplicate';
|
|
public const ERROR_DEFAULT_MULTIPLE = 'mautic.smartlinks.config.error.default_multiple';
|
|
|
|
public function __construct(
|
|
private readonly UtmParameterCatalog $catalog,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateCustomKey(string $key): array
|
|
{
|
|
if (1 !== preg_match(UtmParameterCatalog::CUSTOM_KEY_PATTERN, $key)) {
|
|
return [[self::ERROR_KEY_INVALID, ['%key%' => $key]]];
|
|
}
|
|
|
|
if ($this->catalog->isReservedKey($key)) {
|
|
return [[self::ERROR_KEY_RESERVED, ['%key%' => $key]]];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* @param string[] $existingKeys All custom keys of the form, including $key itself
|
|
*
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateKeyIsUnique(string $key, array $existingKeys): array
|
|
{
|
|
$occurrences = count(array_filter($existingKeys, fn (string $other): bool => $other === $key));
|
|
|
|
return $occurrences > 1 ? [[self::ERROR_KEY_DUPLICATE, ['%key%' => $key]]] : [];
|
|
}
|
|
|
|
/**
|
|
* Rules that apply to the whole value list of a `dropdown` parameter. Nothing is checked
|
|
* for other modes: their values are never processed.
|
|
*
|
|
* @param array<array{value?: mixed, label?: mixed, is_default?: mixed}> $rows
|
|
*
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateValueList(string $mode, bool $enabled, array $rows): array
|
|
{
|
|
if (UtmParameterMode::DROPDOWN !== $mode) {
|
|
return [];
|
|
}
|
|
|
|
$errors = [];
|
|
if ($enabled && [] === $rows) {
|
|
$errors[] = [self::ERROR_VALUES_REQUIRED, []];
|
|
}
|
|
|
|
$seen = [];
|
|
foreach ($rows as $row) {
|
|
$value = (string) ($row['value'] ?? '');
|
|
if ('' === $value) {
|
|
continue;
|
|
}
|
|
|
|
if (isset($seen[$value]) && 1 === $seen[$value]) {
|
|
$errors[] = [self::ERROR_VALUE_DUPLICATE, ['%value%' => $value]];
|
|
}
|
|
$seen[$value] = ($seen[$value] ?? 0) + 1;
|
|
}
|
|
|
|
$defaults = array_filter($rows, fn (array $row): bool => !empty($row['is_default']));
|
|
if (count($defaults) > 1) {
|
|
$errors[] = [self::ERROR_DEFAULT_MULTIPLE, []];
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
}
|