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.
112 lines
3.7 KiB
PHP
112 lines
3.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Model;
|
|
|
|
use libphonenumber\NumberParseException;
|
|
use libphonenumber\PhoneNumberFormat;
|
|
use libphonenumber\PhoneNumberUtil;
|
|
use Mautic\CoreBundle\Model\FormModel;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Stakeholder;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\StakeholderRepository;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Form\Type\StakeholderType;
|
|
use Symfony\Component\Form\FormFactoryInterface;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
|
/**
|
|
* Available as mautic.mt3smarketingprogram.model.stakeholder, or getModel('mt3smarketingprogram.stakeholder').
|
|
*
|
|
* On save, the phone number is normalized to E.164 using the default region from Settings >
|
|
* Configuration > Program Settings (parameter mt3s_marketing_program_stakeholder_phone_region, FR by default). A number that
|
|
* doesn't parse (free input, extensions…) is kept exactly as typed: the save is never blocked.
|
|
*/
|
|
class StakeholderModel extends FormModel
|
|
{
|
|
/**
|
|
* local.php parameter: default region for phone numbers typed without a country prefix.
|
|
*/
|
|
public const PHONE_REGION_PARAMETER = 'mt3s_marketing_program_stakeholder_phone_region';
|
|
|
|
public const DEFAULT_PHONE_REGION = 'FR';
|
|
|
|
public function getRepository(): StakeholderRepository
|
|
{
|
|
$repository = $this->em->getRepository(Stakeholder::class);
|
|
\assert($repository instanceof StakeholderRepository);
|
|
|
|
return $repository;
|
|
}
|
|
|
|
public function getPermissionBase(): string
|
|
{
|
|
return 'mt3smarketingprogram:stakeholders';
|
|
}
|
|
|
|
public function getEntity($id = null): ?Stakeholder
|
|
{
|
|
if (null === $id) {
|
|
return new Stakeholder();
|
|
}
|
|
|
|
$stakeholder = parent::getEntity($id);
|
|
|
|
return $stakeholder instanceof Stakeholder ? $stakeholder : null;
|
|
}
|
|
|
|
/**
|
|
* Normalizes the phone number to E.164 before saving; keeps the raw input when it doesn't parse.
|
|
*/
|
|
public function saveEntity($entity, $unlock = true): void
|
|
{
|
|
if ($entity instanceof Stakeholder && null !== $entity->getPhone() && '' !== trim($entity->getPhone())) {
|
|
$entity->setPhone($this->normalizePhone($entity->getPhone()));
|
|
}
|
|
|
|
parent::saveEntity($entity, $unlock);
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $options
|
|
*/
|
|
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface
|
|
{
|
|
if (!$entity instanceof Stakeholder) {
|
|
throw new MethodNotAllowedHttpException(['Stakeholder']);
|
|
}
|
|
|
|
if (!empty($action)) {
|
|
$options['action'] = $action;
|
|
}
|
|
|
|
return $formFactory->create(StakeholderType::class, $entity, $options);
|
|
}
|
|
|
|
/**
|
|
* The number as E.164 when it parses with the default region, or the raw input as typed when it
|
|
* doesn't ("+33 6 … ext. 12" stays as typed).
|
|
*/
|
|
public function normalizePhone(string $phone): string
|
|
{
|
|
try {
|
|
$number = PhoneNumberUtil::getInstance()->parse(trim($phone), $this->getDefaultPhoneRegion());
|
|
|
|
if (PhoneNumberUtil::getInstance()->isValidNumber($number)) {
|
|
return PhoneNumberUtil::getInstance()->format($number, PhoneNumberFormat::E164);
|
|
}
|
|
} catch (NumberParseException) {
|
|
// Not a parseable number: keep the raw input.
|
|
}
|
|
|
|
return $phone;
|
|
}
|
|
|
|
public function getDefaultPhoneRegion(): string
|
|
{
|
|
$region = $this->coreParametersHelper->get(self::PHONE_REGION_PARAMETER);
|
|
|
|
return is_string($region) && '' !== trim($region) ? strtoupper(trim($region)) : self::DEFAULT_PHONE_REGION;
|
|
}
|
|
}
|