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,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\CommonController;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Entity\SmartLink;
|
||||
use MauticPlugin\MT3SMarketingProgramBundle\Model\SmartLinkModel;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Service\Attribute\Required;
|
||||
|
||||
/**
|
||||
* The public side of the Smart Links: https://{short_link_domain}/l/{slug}.
|
||||
*
|
||||
* The short link only works when Mautic is entered through the configured short link
|
||||
* domain (Settings > Configuration > Smart Links Settings): the call is redirected to
|
||||
* the link's destination — its external URL, or its landing page / standalone form for
|
||||
* Mautic redirects — with its UTM parameters, and one hit is recorded for the statistics.
|
||||
* On any other host, unknown slug, unpublished link or link without destination the
|
||||
* short link doesn't exist: 404.
|
||||
*/
|
||||
class PublicController extends CommonController
|
||||
{
|
||||
private SmartLinkModel $smartLinkModel;
|
||||
|
||||
#[Required]
|
||||
public function autowirePublicController(SmartLinkModel $smartLinkModel): void
|
||||
{
|
||||
$this->smartLinkModel = $smartLinkModel;
|
||||
}
|
||||
|
||||
public function goAction(Request $request, string $slug): Response
|
||||
{
|
||||
// The "if and only if" rule: only the short link domain is an entry point for /l/.
|
||||
$domain = $this->smartLinkModel->getShortLinkDomain();
|
||||
if ('' === $domain || 0 !== strcasecmp(trim($request->getHost()), $domain)) {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
$slug = trim($slug);
|
||||
if ('' === $slug) {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
$link = $this->smartLinkModel->getRepository()->findOneBy(['slug' => $slug]);
|
||||
|
||||
if (null === $link || !$link->isPublished()) {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
// A link without destination goes nowhere, whatever its type.
|
||||
if ($link->getRedirectType()->isMautic()) {
|
||||
if (null === $link->getPage() && null === $link->getForm()) {
|
||||
return $this->notFound();
|
||||
}
|
||||
} elseif ('' === trim((string) $link->getDestinationUrl())) {
|
||||
return $this->notFound();
|
||||
}
|
||||
|
||||
try {
|
||||
$this->smartLinkModel->recordHit($link, $request);
|
||||
} catch (\Throwable $e) {
|
||||
// Statistics must never block the redirect.
|
||||
error_log('Smart Link hit could not be recorded for slug "'.$slug.'": '.$e->getMessage().' in '.$e->getFile().':'.$e->getLine());
|
||||
}
|
||||
|
||||
return new RedirectResponse($this->smartLinkModel->buildRedirectUrl($link), $link->getRedirectCode()->value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?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 smartlinks.smart_link (mautic.smartlinks.model.smart_link), permission base
|
||||
* smartlinks:smart_links, translation base mautic.smartlinks.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 = 'mautic_smartlinks_index';
|
||||
public const ROUTE_ACTION = 'mautic_smartlinks_action';
|
||||
|
||||
protected function getModelName(): string
|
||||
{
|
||||
return 'smartlinks.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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core builds mautic_smartlinkssmartlink from the model name; the JS loader relies on this prefix.
|
||||
*/
|
||||
protected function getJsLoadMethodPrefix(): string
|
||||
{
|
||||
return 'smartlinksSmartLink';
|
||||
}
|
||||
|
||||
/**
|
||||
* Core builds mautic.<model name> (singular smart_link); every key of the feature lives
|
||||
* under mautic.smartlinks.smart_links.
|
||||
*/
|
||||
protected function getTranslationBase(): string
|
||||
{
|
||||
return 'mautic.smartlinks.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('mautic.smartlinks.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();
|
||||
}
|
||||
}
|
||||
@@ -4,37 +4,118 @@ declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MT3SMarketingProgramBundle\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Controller\CommonController;
|
||||
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* UTM Taxonomies: a placeholder page for the coming feature, kept out of the menu since
|
||||
* 0.17.0 (the route stays; the page is reachable at /s/marketing-program-utm-taxonomies).
|
||||
* The content (classifying the UTM parameters of the programs' campaigns and links) comes
|
||||
* later; until then the page shows an empty content block.
|
||||
* Create, edit and delete UTM Taxonomies (Smart Links > UTM Taxonomies), using core's standard
|
||||
* CRUD flow.
|
||||
*
|
||||
* Model smartlinks.utm_taxonomy (mautic.smartlinks.model.utm_taxonomy), permission base
|
||||
* smartlinks:taxonomies, translation base mautic.smartlinks.taxonomies.
|
||||
*
|
||||
* A taxonomy is never cloned: its name is unique, and a clone would collide immediately. A new
|
||||
* taxonomy is created from scratch.
|
||||
*/
|
||||
class UtmTaxonomyController extends CommonController
|
||||
class UtmTaxonomyController extends AbstractStandardFormController
|
||||
{
|
||||
public const ROUTE_INDEX = 'mt3s_marketing_program_utm_taxonomy_index';
|
||||
public const ROUTE_INDEX = 'mautic_smartlinks_taxonomies';
|
||||
public const ROUTE_ACTION = 'mautic_smartlinks_taxonomy_action';
|
||||
|
||||
protected function getModelName(): string
|
||||
{
|
||||
return 'smartlinks.utm_taxonomy';
|
||||
}
|
||||
|
||||
protected function getTemplateBase(): string
|
||||
{
|
||||
return '@MT3SMarketingProgram/UtmTaxonomy';
|
||||
}
|
||||
|
||||
protected function getIndexRoute(): string
|
||||
{
|
||||
return self::ROUTE_INDEX;
|
||||
}
|
||||
|
||||
protected function getActionRoute(): string
|
||||
{
|
||||
return self::ROUTE_ACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Core derives the JS loader method from the model name; no Mautic.<prefix>OnLoad exists for
|
||||
* taxonomies (the form needs none), but the prefix stays deterministic for future use.
|
||||
*/
|
||||
protected function getJsLoadMethodPrefix(): string
|
||||
{
|
||||
return 'smartlinksUtmTaxonomy';
|
||||
}
|
||||
|
||||
/**
|
||||
* Core builds mautic.<model name>; every key of the feature lives under mautic.smartlinks.taxonomies.
|
||||
*/
|
||||
protected function getTranslationBase(): string
|
||||
{
|
||||
return 'mautic.smartlinks.taxonomies';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
*/
|
||||
public function indexAction(Request $request, $page = 1): Response
|
||||
{
|
||||
$tmpl = $request->isXmlHttpRequest() ? $request->get('tmpl', 'index') : 'index';
|
||||
|
||||
return $this->delegateView([
|
||||
'viewParameters' => [
|
||||
'tmpl' => $tmpl,
|
||||
],
|
||||
'contentTemplate' => '@MT3SMarketingProgram/UtmTaxonomy/list.html.twig',
|
||||
'passthroughVars' => [
|
||||
'activeLink' => '#'.self::ROUTE_INDEX,
|
||||
'mauticContent' => 'mt3sMpProgramUtmTaxonomy',
|
||||
'route' => $this->generateUrl(self::ROUTE_INDEX),
|
||||
],
|
||||
]);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Taxonomies don't have a detail page; after Save or Cancel go back to the list.
|
||||
*/
|
||||
protected function getPostActionControllerAction($action): string
|
||||
{
|
||||
return 'index';
|
||||
}
|
||||
|
||||
/**
|
||||
* Order by name: the taxonomy has no other sortable business column.
|
||||
*/
|
||||
protected function getDefaultOrderColumn(): string
|
||||
{
|
||||
return 'name';
|
||||
}
|
||||
|
||||
/**
|
||||
* A saved taxonomy is never cloned: its name is unique, and a clone would collide on save.
|
||||
*/
|
||||
public function cloneAction(Request $request, $objectId): Response
|
||||
{
|
||||
$this->accessDenied();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user