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.
73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Validator;
|
|
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Model\UtmTaxonomyModel;
|
|
|
|
/**
|
|
* Business rules of the UTM Taxonomy form. The form types call these methods from Callback
|
|
* constraints; each method returns translation keys (validators domain) and parameters.
|
|
*/
|
|
final class UtmTaxonomyValidator
|
|
{
|
|
public const ERROR_NAME_TAKEN = 'mautic.smartlinks.taxonomies.error.name_taken';
|
|
public const ERROR_NAME_CHARACTERS = 'mautic.smartlinks.taxonomies.error.name_characters';
|
|
public const ERROR_VALUE_INVALID = 'mautic.smartlinks.taxonomies.error.value_invalid';
|
|
public const ERROR_VALUE_DUPLICATE = 'mautic.smartlinks.config.error.value_duplicate';
|
|
|
|
public function __construct(
|
|
private readonly UtmTaxonomyModel $taxonomyModel,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Unique, non-empty name. Free of the characters local.php can't carry ("%", "{", "}").
|
|
*
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateName(string $name, ?int $ignoreId = null): array
|
|
{
|
|
if (1 !== preg_match('/^[^%{}]+$/', $name)) {
|
|
return [[self::ERROR_NAME_CHARACTERS, []]];
|
|
}
|
|
|
|
if ($this->taxonomyModel->isNameTaken($name, $ignoreId)) {
|
|
return [[self::ERROR_NAME_TAKEN, ['%name%' => $name]]];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* The value list of a `free` parameter (its editable textarea): every line must respect
|
|
* the technical pattern of the URL values, and duplicates are rejected.
|
|
*
|
|
* @param list<array{0: string, 1: string}> $parsed
|
|
*
|
|
* @return list<array{0: string, 1: array<string, string>}>
|
|
*/
|
|
public function validateValues(array $parsed): array
|
|
{
|
|
$errors = [];
|
|
$seen = [];
|
|
|
|
foreach ($parsed as [$value]) {
|
|
if ('' === $value) {
|
|
continue;
|
|
}
|
|
|
|
if (isset($seen[$value]) && 1 === $seen[$value]) {
|
|
$errors[] = [self::ERROR_VALUE_DUPLICATE, ['%value%' => $value]];
|
|
}
|
|
$seen[$value] = ($seen[$value] ?? 0) + 1;
|
|
|
|
if (1 !== preg_match(UtmSettingsValidator::VALUE_PATTERN, $value)) {
|
|
$errors[] = [self::ERROR_VALUE_INVALID, ['%value%' => $value]];
|
|
}
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
} |