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.
168 lines
5.2 KiB
PHP
168 lines
5.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Controller;
|
|
|
|
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Model\SmartLinkModel;
|
|
use Symfony\Component\Form\Form;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* Create, edit and delete Smart Links (main menu > Smart Links), using core's standard CRUD flow.
|
|
*
|
|
* Model mt3smarketingprogram.smart_link (mautic.mt3smarketingprogram.model.smart_link), permission base
|
|
* mt3smarketingprogram:smart_links, translation base mt3s.smart_links.smart_links.
|
|
*
|
|
* The slug of a saved link is immutable: the form disables the field, the model refuses another
|
|
* slug, and this controller drops the submitted value (nothing to re-check). There is no clone:
|
|
* a new link gets a new slug (the "Generate" button offers one).
|
|
*/
|
|
class SmartLinkController extends AbstractStandardFormController
|
|
{
|
|
public const ROUTE_INDEX = 'mt3s_smart_links_index';
|
|
public const ROUTE_ACTION = 'mt3s_smart_links_action';
|
|
|
|
protected function getModelName(): string
|
|
{
|
|
return 'mt3smarketingprogram.smart_link';
|
|
}
|
|
|
|
protected function getTemplateBase(): string
|
|
{
|
|
return '@MT3SMarketingProgram/SmartLink';
|
|
}
|
|
|
|
protected function getIndexRoute(): string
|
|
{
|
|
return self::ROUTE_INDEX;
|
|
}
|
|
|
|
protected function getActionRoute(): string
|
|
{
|
|
return self::ROUTE_ACTION;
|
|
}
|
|
|
|
/**
|
|
* The OnLoad JS prefix: core dispatches Mautic[getJsLoadMethodPrefix() + "OnLoad"]()
|
|
* (Mautic.mt3sMpSmartLinkOnLoad in Assets/js/mt3s-mp-smartlinks.js). Without this
|
|
* override, core falls back to the model name, which nothing listens to.
|
|
*/
|
|
protected function getJsLoadMethodPrefix(): string
|
|
{
|
|
return 'mt3sMpSmartLink';
|
|
}
|
|
|
|
/**
|
|
* Core builds mautic.<model name> (singular smart_link); every key of the feature lives
|
|
* under mt3s.smart_links.smart_links.
|
|
*/
|
|
protected function getTranslationBase(): string
|
|
{
|
|
return 'mt3s.smart_links.smart_links';
|
|
}
|
|
|
|
/**
|
|
* @param int $page
|
|
*/
|
|
public function indexAction(Request $request, $page = 1): Response
|
|
{
|
|
return $this->indexStandard($request, $page);
|
|
}
|
|
|
|
public function newAction(Request $request): Response
|
|
{
|
|
return $this->newStandard($request);
|
|
}
|
|
|
|
/**
|
|
* @param int $objectId
|
|
* @param bool $ignorePost
|
|
*/
|
|
public function editAction(Request $request, $objectId, $ignorePost = false): Response
|
|
{
|
|
return $this->editStandard($request, $objectId, $ignorePost);
|
|
}
|
|
|
|
/**
|
|
* @param int $objectId
|
|
*/
|
|
public function deleteAction(Request $request, $objectId): Response
|
|
{
|
|
return $this->deleteStandard($request, $objectId);
|
|
}
|
|
|
|
public function batchDeleteAction(Request $request): Response
|
|
{
|
|
return $this->batchDeleteStandard($request);
|
|
}
|
|
|
|
/**
|
|
* Never save the slug of an existing link: it is immutable once created. The field is
|
|
* disabled in the form, so nothing is submitted for it, this is a safety net.
|
|
*/
|
|
protected function beforeEntitySave($entity, Form $form, $action, $objectId = null, $isClone = false): bool
|
|
{
|
|
if ($entity instanceof SmartLink && null !== $entity->getId()) {
|
|
$formSlug = $form->has('slug') ? (string) $form->get('slug')->getData() : '';
|
|
if ('' !== $formSlug && $formSlug !== (string) $entity->getSlug()) {
|
|
$this->addFlashMessage('mt3s.smart_links.smart_links.error.slug_immutable', ['%slug%' => $formSlug], \Mautic\CoreBundle\FlashBag::LEVEL_ERROR);
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return parent::beforeEntitySave($entity, $form, $action, $objectId, $isClone);
|
|
}
|
|
|
|
/**
|
|
* The list shows the short link, built from the configured domain (a reminder of it is
|
|
* also displayed above the form of a link), and the number of hits of each link.
|
|
*
|
|
* @param array<string, mixed> $args
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function getViewArguments(array $args, $action): array
|
|
{
|
|
$args = parent::getViewArguments($args, $action);
|
|
|
|
if ('index' === $action) {
|
|
$model = $this->getModel($this->getModelName());
|
|
\assert($model instanceof SmartLinkModel);
|
|
|
|
$args['viewParameters']['shortLinkDomain'] = $model->getShortLinkDomain();
|
|
$args['viewParameters']['hitCounts'] = $model->getHitCounts();
|
|
}
|
|
|
|
return $args;
|
|
}
|
|
|
|
/**
|
|
* Order by slug: the entity has no "name" column.
|
|
*/
|
|
protected function getDefaultOrderColumn(): string
|
|
{
|
|
return 'slug';
|
|
}
|
|
|
|
/**
|
|
* Smart Links don't have a detail page; after Save or Cancel go back to the list.
|
|
*/
|
|
protected function getPostActionControllerAction($action): string
|
|
{
|
|
return 'index';
|
|
}
|
|
|
|
/**
|
|
* A saved Smart Link is never cloned: its slug is immutable, and a clone would need a new one.
|
|
*/
|
|
public function cloneAction(Request $request, $objectId): Response
|
|
{
|
|
$this->accessDenied();
|
|
}
|
|
}
|