Files
mautic-marketing-program-bu…/Entity/UtmTaxonomy.php
T
Alexandre Gain dce849610c 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.
2026-11-16 13:48:13 +01:00

143 lines
3.7 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\MT3SMarketingProgramBundle\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\ClassMetadata as OrmClassMetadata;
use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder;
use Mautic\CoreBundle\Entity\FormEntity;
/**
* A UTM Taxonomy: a named set of allowed values for the UTM parameters.
*
* A Smart Link carries one taxonomy; every UTM value of the link is chosen
* among the values the taxonomy defines for its parameter.
*
* The allowed values live in the `parameters` array: parameter key => list of
* {value, label} rows. Only the parameters enabled in Settings > Configuration
* > Smart Links Settings can be given values (the form only offers those).
*/
class UtmTaxonomy extends FormEntity
{
public const TABLE_NAME = 'utm_taxonomies';
public const NAME_MAX_LENGTH = 50;
private ?int $id = null;
private ?string $name = null;
private ?string $description = null;
/**
* Allowed values per parameter: parameter key => list of {value, label}.
*
* @var array<string, list<array{value: string, label: string}>>
*/
private array $parameters = [];
public static function loadMetadata(OrmClassMetadata $metadata): void
{
$builder = new ClassMetadataBuilder($metadata);
$builder->setTable(self::TABLE_NAME)
->setCustomRepositoryClass(UtmTaxonomyRepository::class)
->addIndex(['name'], 'utm_taxonomy_name');
$builder->addId();
$builder->createField('name', Types::STRING)
->length(self::NAME_MAX_LENGTH)
->unique()
->build();
$builder->createField('description', Types::TEXT)
->nullable()
->build();
// Mapped on the raw metadata: ClassMetadataBuilder::addField() forces VARCHAR(191) on strings.
$metadata->mapField([
'fieldName' => 'parameters',
'columnName' => 'parameters',
'type' => Types::JSON,
]);
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->isChanged('name', $name);
$this->name = '' !== trim((string) $name) ? $name : null;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
if (null !== $description && '' === trim($description)) {
$description = null;
}
$this->isChanged('description', $description);
$this->description = $description;
return $this;
}
/**
* @return array<string, list<array{value: string, label: string}>>
*/
public function getParameters(): array
{
return $this->parameters;
}
/**
* @param array<string, list<array{value: string, label: string}>>|null $parameters
*/
public function setParameters(?array $parameters): static
{
$this->isChanged('parameters', $parameters);
$this->parameters = $parameters ?? [];
ksort($this->parameters);
return $this;
}
/**
* The allowed values of one parameter, keyed by value (labels are unique per value).
*
* @return list<array{value: string, label: string}>
*/
public function getParameterValues(string $key): array
{
return $this->parameters[$key] ?? [];
}
/**
* The parameter keys the taxonomy defines, in display order.
*
* @return list<string>
*/
public function getParameterKeys(): array
{
return array_keys($this->parameters);
}
}