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.
185 lines
5.9 KiB
PHP
185 lines
5.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Controller;
|
|
|
|
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Program;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Model\TaskModel;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
/**
|
|
* List, view, create, edit and delete marketing programs, using core's standard CRUD flow.
|
|
*
|
|
* Core derives the model alias and the permission base from the model name
|
|
* "mt3smarketingprogram.program": model mautic.mt3smarketingprogram.model.program, permission
|
|
* base mt3smarketingprogram:programs (from ProgramModel). The views translate under mt3s.marketing_program.*.
|
|
*/
|
|
class ProgramController extends AbstractStandardFormController
|
|
{
|
|
public const ROUTE_INDEX = 'mt3s_marketing_program_index';
|
|
public const ROUTE_ACTION = 'mt3s_marketing_program_action';
|
|
|
|
protected function getModelName(): string
|
|
{
|
|
return 'mt3smarketingprogram.program';
|
|
}
|
|
|
|
protected function getTemplateBase(): string
|
|
{
|
|
return '@MT3SMarketingProgram/Program';
|
|
}
|
|
|
|
/**
|
|
* Core would build mautic_mt3s_marketing_program_index; the plugin's routes use the plan_ prefix.
|
|
*/
|
|
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"]()
|
|
* (mt3sMpProgramOnLoad in Assets/js/mt3s-mp-program.js). Without this override, core
|
|
* falls back to the model name ("mt3smarketingprogram.program"), which nothing listens to.
|
|
*/
|
|
protected function getJsLoadMethodPrefix(): string
|
|
{
|
|
return 'mt3sMpProgram';
|
|
}
|
|
|
|
/**
|
|
* @param int $page
|
|
*/
|
|
public function indexAction(Request $request, $page = 1): Response
|
|
{
|
|
return $this->indexStandard($request, $page);
|
|
}
|
|
|
|
/**
|
|
* The program detail page (tabs: Details, Description, Objectives, Allocations, Audiences, Stakeholders, Tasks).
|
|
*
|
|
* Core's viewStandard() isn't used: for users who aren't administrators it checks an
|
|
* "<entity>:export:enable" permission, which plans don't have.
|
|
*
|
|
* @param int $objectId
|
|
*/
|
|
public function viewAction(Request $request, $objectId): Response
|
|
{
|
|
$program = $this->getModel($this->getModelName())->getEntity((int) $objectId);
|
|
|
|
if (!$program instanceof Program) {
|
|
return $this->notFound('mt3s.marketing_program.error.notfound');
|
|
}
|
|
|
|
if (!$this->checkActionPermission('view', $program)) {
|
|
return $this->accessDenied();
|
|
}
|
|
|
|
$base = $this->getPermissionBase();
|
|
$permissions = $this->security->isGranted(
|
|
[
|
|
$base.':create',
|
|
$base.':editown',
|
|
$base.':editother',
|
|
$base.':deleteown',
|
|
$base.':deleteother',
|
|
],
|
|
'RETURN_ARRAY',
|
|
null,
|
|
true
|
|
);
|
|
|
|
$taskPermissions = $this->security->isGranted(
|
|
[
|
|
'mt3smarketingprogram:tasks:create',
|
|
'mt3smarketingprogram:tasks:editown',
|
|
'mt3smarketingprogram:tasks:editother',
|
|
],
|
|
'RETURN_ARRAY',
|
|
null,
|
|
true
|
|
);
|
|
|
|
return $this->delegateView([
|
|
'viewParameters' => [
|
|
'item' => $program,
|
|
'permissions' => $permissions,
|
|
'taskTree' => $this->getTaskModel()->getTaskTree($program),
|
|
'taskPermissions' => $taskPermissions,
|
|
// Core's page_actions helper would otherwise build mautic_plan_* route names.
|
|
'indexRoute' => self::ROUTE_INDEX,
|
|
'actionRoute' => self::ROUTE_ACTION,
|
|
'tmpl' => $request->isXmlHttpRequest() ? $request->get('tmpl', 'details') : 'details',
|
|
],
|
|
'contentTemplate' => $this->getTemplateName('details.html.twig'),
|
|
'passthroughVars' => [
|
|
'activeLink' => '#mt3s_marketing_program_index',
|
|
'mauticContent' => $this->getJsLoadMethodPrefix(),
|
|
'route' => $this->generateUrl(self::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $program->getId()]),
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Adds the program's task tree to the form, for the read-only Tasks tab.
|
|
*
|
|
* @param array<string, mixed> $args
|
|
* @param string $action
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function getViewArguments(array $args, $action): array
|
|
{
|
|
$program = $args['viewParameters']['entity'] ?? null;
|
|
|
|
if (in_array($action, ['new', 'edit'], true) && $program instanceof Program && null !== $program->getId()) {
|
|
$args['viewParameters']['taskTree'] = $this->getTaskModel()->getTaskTree($program);
|
|
}
|
|
|
|
return parent::getViewArguments($args, $action);
|
|
}
|
|
|
|
private function getTaskModel(): TaskModel
|
|
{
|
|
$model = $this->getModel('mt3smarketingprogram.task');
|
|
\assert($model instanceof TaskModel);
|
|
|
|
return $model;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|