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:
1 parent
debce4ba4a
commit
dce849610c
69 files changed
+8225
-43
No files matched your search
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Form\Validator;
|
||||
|
||||
use Mautic\FormBundle\Entity\Form;
|
||||
use Mautic\PageBundle\Entity\Page;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\SmartLinkRedirectType;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Catalog\UtmParameterMode;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\UtmTaxonomy;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Service\UtmConfigurationProvider;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Model\SmartLinkModel;
|
||||
|
||||
/**
|
||||
* Business rules of the Smart Link form. The form type calls these methods from Callback
|
||||
* constraints; each method returns translation keys (validators domain) and parameters.
|
||||
*/
|
||||
final class SmartLinkValidator
|
||||
{
|
||||
public const ERROR_SLUG_TAKEN = 'mautic.smartlinks.smart_links.error.slug_taken';
|
||||
public const ERROR_SLUG_REQUIRED = 'mautic.smartlinks.smart_links.error.slug_required';
|
||||
public const ERROR_SLUG_LENGTH = 'mautic.smartlinks.smart_links.error.slug_length';
|
||||
public const ERROR_DESTINATION_REQUIRED = 'mautic.smartlinks.smart_links.error.destination_required';
|
||||
public const ERROR_DESTINATION_REQUIRED_MAUTIC = 'mautic.smartlinks.smart_links.error.destination_required_mautic';
|
||||
public const ERROR_DESTINATION_INVALID = 'mautic.smartlinks.smart_links.error.destination_invalid';
|
||||
public const ERROR_UTM_VALUE_INVALID = 'mautic.smartlinks.smart_links.error.utm_value_invalid';
|
||||
public const ERROR_UTM_VALUE_NOT_ALLOWED = 'mautic.smartlinks.smart_links.error.utm_value_not_allowed';
|
||||
public const ERROR_TAXONOMY_PARAMETER_UNKNOWN = 'mautic.smartlinks.smart_links.error.taxonomy_parameter_unknown';
|
||||
|
||||
public function __construct(
|
||||
private readonly SmartLinkModel $smartLinkModel,
|
||||
private readonly UtmConfigurationProvider $utmConfiguration,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Unique slug. The rules (lowercase, separator replacement) are applied by the model
|
||||
* before this check, so the comparison uses the final slug.
|
||||
*
|
||||
* @return list<array{0: string, 1: array<string, string>}>
|
||||
*/
|
||||
public function validateSlug(string $slug, ?int $ignoreId = null): array
|
||||
{
|
||||
if ('' === $slug) {
|
||||
return [[self::ERROR_SLUG_REQUIRED, []]];
|
||||
}
|
||||
|
||||
if ($this->smartLinkModel->isSlugTaken($slug, $ignoreId)) {
|
||||
return [[self::ERROR_SLUG_TAKEN, ['%slug%' => $slug]]];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* A destination is required for every redirect type: an URL for external ones, a landing
|
||||
* page or a standalone form for Mautic ones. Only http(s) URLs are accepted.
|
||||
*
|
||||
* @return list<array{0: string, 1: array<string, string>}>
|
||||
*/
|
||||
public function validateDestination(SmartLinkRedirectType $redirectType, ?string $url, ?Page $page = null, ?Form $form = null): array
|
||||
{
|
||||
if ($redirectType->isMautic()) {
|
||||
if (null === $page && null === $form) {
|
||||
return [[self::ERROR_DESTINATION_REQUIRED_MAUTIC, []]];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
$url = trim((string) $url);
|
||||
|
||||
if ('' === $url) {
|
||||
return [[self::ERROR_DESTINATION_REQUIRED, []]];
|
||||
}
|
||||
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL)
|
||||
|| !in_array(parse_url($url, PHP_URL_SCHEME), ['http', 'https'], true)) {
|
||||
return [[self::ERROR_DESTINATION_INVALID, ['%url%' => $url]]];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* UTM values follow the Smart Links Settings the admin defines. With a taxonomy chosen:
|
||||
* every parameter the taxonomy defines limits the value -- the checkbox subset of the
|
||||
* admin's values for a dropdown, the taxonomy's own list for a free parameter. The
|
||||
* values the link carried before the edit stay acceptable (they were chosen when the
|
||||
* taxonomy — or, before the feature, the global configuration — allowed them), so a plain
|
||||
* re-save never errors. Without a taxonomy (links that predate the feature, before their
|
||||
* next edit), the values follow the rules of Smart Links Settings.
|
||||
*
|
||||
* @param array<string, string> $utmParameters
|
||||
* @param array<string, string> $stored the values the link carried before the edit
|
||||
*
|
||||
* @return list<array{0: string, 1: array<string, string>}>
|
||||
*/
|
||||
public function validateUtmParameters(array $utmParameters, ?UtmTaxonomy $taxonomy = null, array $stored = []): array
|
||||
{
|
||||
if (null === $taxonomy) {
|
||||
return $this->validateAgainstGlobalConfiguration($utmParameters, $stored);
|
||||
}
|
||||
|
||||
$errors = [];
|
||||
|
||||
foreach ($utmParameters as $key => $value) {
|
||||
$parameter = $this->utmConfiguration->getParameter($key);
|
||||
|
||||
if (null === $parameter || (!$parameter['enabled']) || UtmParameterMode::DISABLED === $parameter['mode']) {
|
||||
$errors[] = [self::ERROR_UTM_VALUE_INVALID, ['%key%' => $key]];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Every parameter of the taxonomy limits the value: a dropdown subset selected
|
||||
// among the admin's values, or the taxonomy's own list for a free parameter.
|
||||
$allowed = $taxonomy->getParameterValues($key);
|
||||
|
||||
if ([] === $allowed) {
|
||||
$errors[] = [self::ERROR_TAXONOMY_PARAMETER_UNKNOWN, ['%key%' => $key, '%name%' => (string) $taxonomy->getName()]];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($value, array_column($allowed, 'value'), true) || ($stored[$key] ?? null) === $value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$errors[] = [self::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => $key, '%value%' => $value]];
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* The rules of Smart Links Settings: the values belong to enabled parameters, respect the
|
||||
* technical pattern, and dropdown values stay within the configured list — unless the link
|
||||
* already carried them.
|
||||
*
|
||||
* @param array<string, string> $utmParameters
|
||||
* @param array<string, string> $stored
|
||||
*
|
||||
* @return list<array{0: string, 1: array<string, string>}>
|
||||
*/
|
||||
private function validateAgainstGlobalConfiguration(array $utmParameters, array $stored): array
|
||||
{
|
||||
$valuePattern = UtmSettingsValidator::VALUE_PATTERN;
|
||||
$errors = [];
|
||||
|
||||
foreach ($utmParameters as $key => $value) {
|
||||
$parameter = $this->utmConfiguration->getParameter($key);
|
||||
|
||||
if (null === $parameter || (!$parameter['enabled']) || UtmParameterMode::DISABLED === $parameter['mode']) {
|
||||
$errors[] = [self::ERROR_UTM_VALUE_INVALID, ['%key%' => $key]];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (1 !== preg_match($valuePattern, $value)) {
|
||||
$errors[] = [self::ERROR_UTM_VALUE_INVALID, ['%key%' => $key]];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$inList = UtmParameterMode::DROPDOWN !== $parameter['mode']
|
||||
|| in_array($value, array_column($this->utmConfiguration->getDropdownValues($key), 'value'), true);
|
||||
|
||||
if (!$inList && ($stored[$key] ?? null) !== $value) {
|
||||
$errors[] = [self::ERROR_UTM_VALUE_NOT_ALLOWED, ['%key%' => $key, '%value%' => $value]];
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user