refactor(plugin): rename Plan to Program and add audience/UTM routes

Rename the Plan bundle to Program across config, routes, menus, and
controllers (Plan -> Initiative), bump version to 0.16.0, and introduce
new audience and UTM taxonomy routes and permissions to support the
expanded Programs feature set.
This commit is contained in:
Alexandre Gain committed 2026-11-13 22:01:32 +01:00
1 parent 8268fad886
commit 71ff11390b
121 files changed
+5011 -2874

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* List, create, edit and delete audiences (Programs > Audiences), the global directory of who the
* initiatives are aimed at, using core's standard CRUD flow. Audiences are independent of initiatives; initiatives
* link to them from their Audiences tab (InitiativeAudience carries the audience's priority in that
* initiative).
*
* Model program.audience (mautic.program.model.audience), permission base program:audiences, translation
* base mautic.program.audience.
*/
class AudienceController extends AbstractStandardFormController
{
public const ROUTE_INDEX = 'initiative_audience_index';
public const ROUTE_ACTION = 'initiative_audience_action';
protected function getModelName(): string
{
return 'program.audience';
}
protected function getTemplateBase(): string
{
return '@Program/Audience';
}
protected function getIndexRoute(): string
{
return self::ROUTE_INDEX;
}
protected function getActionRoute(): string
{
return self::ROUTE_ACTION;
}
protected function getJsLoadMethodPrefix(): string
{
return 'programAudience';
}
/**
* @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);
}
/**
* The audience's detail page (the directory entry, its persona attributes, its segments and
* the initiatives it is assigned to). The standard controller has no view action of its own, so it
* is routed here.
*
* @param int $objectId
*/
public function viewAction(Request $request, $objectId): Response
{
return $this->viewStandard($request, $objectId, 'audience', 'initiative');
}
/**
* @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);
}
}
@@ -2,37 +2,37 @@
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Controller;
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Model\TaskModel;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Model\TaskModel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* List, view, create, edit and delete plans, using core's standard CRUD flow.
*
* Core derives most names from the model name "plan": model mautic.plan.model.plan, permission base
* plan:plans (from PlanModel), translation base mautic.plan, session base mautic.plan.
* Core derives most names from the model name "initiative": model mautic.program.model.initiative, permission base
* program:initiatives (from InitiativeModel), translation base mautic.program, session base mautic.program.
*/
class PlanController extends AbstractStandardFormController
class InitiativeController extends AbstractStandardFormController
{
public const ROUTE_INDEX = 'plan_index';
public const ROUTE_ACTION = 'plan_action';
public const ROUTE_INDEX = 'initiative_index';
public const ROUTE_ACTION = 'initiative_action';
protected function getModelName(): string
{
return 'plan';
return 'program.initiative';
}
protected function getTemplateBase(): string
{
return '@Plan/Plan';
return '@Program/Initiative';
}
/**
* Core would build mautic_plan_index; the plugin's routes use the plan_ prefix.
* Core would build mautic_initiative_index; the plugin's routes use the plan_ prefix.
*/
protected function getIndexRoute(): string
{
@@ -53,7 +53,7 @@ class PlanController extends AbstractStandardFormController
}
/**
* The plan detail page (tabs: Details, Description, Objectives, Allocations, Targets, Tasks).
* The initiative 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.
@@ -62,13 +62,13 @@ class PlanController extends AbstractStandardFormController
*/
public function viewAction(Request $request, $objectId): Response
{
$plan = $this->getModel($this->getModelName())->getEntity((int) $objectId);
$initiative = $this->getModel($this->getModelName())->getEntity((int) $objectId);
if (!$plan instanceof Plan) {
return $this->notFound('mautic.plan.error.notfound');
if (!$initiative instanceof Initiative) {
return $this->notFound('mautic.program.error.notfound');
}
if (!$this->checkActionPermission('view', $plan)) {
if (!$this->checkActionPermission('view', $initiative)) {
return $this->accessDenied();
}
@@ -88,9 +88,9 @@ class PlanController extends AbstractStandardFormController
$taskPermissions = $this->security->isGranted(
[
'plan:tasks:create',
'plan:tasks:editown',
'plan:tasks:editother',
'program:tasks:create',
'program:tasks:editown',
'program:tasks:editother',
],
'RETURN_ARRAY',
null,
@@ -99,9 +99,9 @@ class PlanController extends AbstractStandardFormController
return $this->delegateView([
'viewParameters' => [
'item' => $plan,
'item' => $initiative,
'permissions' => $permissions,
'taskTree' => $this->getTaskModel()->getTaskTree($plan),
'taskTree' => $this->getTaskModel()->getTaskTree($initiative),
'taskPermissions' => $taskPermissions,
// Core's page_actions helper would otherwise build mautic_plan_* route names.
'indexRoute' => self::ROUTE_INDEX,
@@ -110,15 +110,15 @@ class PlanController extends AbstractStandardFormController
],
'contentTemplate' => $this->getTemplateName('details.html.twig'),
'passthroughVars' => [
'activeLink' => '#plan_index',
'activeLink' => '#initiative_index',
'mauticContent' => $this->getJsLoadMethodPrefix(),
'route' => $this->generateUrl(self::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $plan->getId()]),
'route' => $this->generateUrl(self::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $initiative->getId()]),
],
]);
}
/**
* Adds the plan's task tree to the form, for the read-only Tasks tab.
* Adds the initiative's task tree to the form, for the read-only Tasks tab.
*
* @param array<string, mixed> $args
* @param string $action
@@ -127,10 +127,10 @@ class PlanController extends AbstractStandardFormController
*/
protected function getViewArguments(array $args, $action): array
{
$plan = $args['viewParameters']['entity'] ?? null;
$initiative = $args['viewParameters']['entity'] ?? null;
if (in_array($action, ['new', 'edit'], true) && $plan instanceof Plan && null !== $plan->getId()) {
$args['viewParameters']['taskTree'] = $this->getTaskModel()->getTaskTree($plan);
if (in_array($action, ['new', 'edit'], true) && $initiative instanceof Initiative && null !== $initiative->getId()) {
$args['viewParameters']['taskTree'] = $this->getTaskModel()->getTaskTree($initiative);
}
return parent::getViewArguments($args, $action);
@@ -138,7 +138,7 @@ class PlanController extends AbstractStandardFormController
private function getTaskModel(): TaskModel
{
$model = $this->getModel('plan.task');
$model = $this->getModel('program.task');
\assert($model instanceof TaskModel);
return $model;
+10 -10
View File
@@ -2,33 +2,33 @@
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Controller;
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* List, create, edit and delete stakeholders (Planning > Stakeholders), the global directory, using
* core's standard CRUD flow. Stakeholders are independent of plans; plans link to them from their
* List, create, edit and delete stakeholders (Programs > Stakeholders), the global directory, using
* core's standard CRUD flow. Stakeholders are independent of initiatives; initiatives link to them from their
* Stakeholders tab.
*
* Model plan.stakeholder (mautic.plan.model.stakeholder), permission base plan:stakeholders,
* translation base mautic.plan.stakeholder.
* Model program.stakeholder (mautic.program.model.stakeholder), permission base program:stakeholders,
* translation base mautic.program.stakeholder.
*/
class StakeholderController extends AbstractStandardFormController
{
public const ROUTE_INDEX = 'plan_stakeholder_index';
public const ROUTE_ACTION = 'plan_stakeholder_action';
public const ROUTE_INDEX = 'initiative_stakeholder_index';
public const ROUTE_ACTION = 'initiative_stakeholder_action';
protected function getModelName(): string
{
return 'plan.stakeholder';
return 'program.stakeholder';
}
protected function getTemplateBase(): string
{
return '@Plan/Stakeholder';
return '@Program/Stakeholder';
}
protected function getIndexRoute(): string
@@ -43,7 +43,7 @@ class StakeholderController extends AbstractStandardFormController
protected function getJsLoadMethodPrefix(): string
{
return 'planStakeholder';
return 'programStakeholder';
}
/**
+40 -40
View File
@@ -2,42 +2,42 @@
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Controller;
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\Task;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* List, create, edit and delete tasks (Planning > Tasks), using core's standard CRUD flow.
* List, create, edit and delete tasks (Programs > Tasks), using core's standard CRUD flow.
*
* Model plan.task (mautic.plan.model.task), permission base plan:tasks, translation base mautic.plan.task.
* Model program.task (mautic.program.model.task), permission base program:tasks, translation base mautic.program.task.
*
* Where the user lands after Save or Cancel depends on where the task form was opened from:
* - from Planning > Tasks: back to the task list (core's default);
* - from a plan's Tasks tab (links with ?returnTo=plan): back to that plan.
* - from Programs > Tasks: back to the task list (core's default);
* - from an initiative's Tasks tab (links with ?returnTo=initiative): back to that initiative.
* The origin is kept in the session when the form is opened, because the form posts to a URL
* without the query string.
*/
class TaskController extends AbstractStandardFormController
{
public const ROUTE_INDEX = 'plan_task_index';
public const ROUTE_ACTION = 'plan_task_action';
public const ROUTE_INDEX = 'initiative_task_index';
public const ROUTE_ACTION = 'initiative_task_action';
/**
* Value of the returnTo query parameter that sends the user back to the plan.
* Value of the returnTo query parameter that sends the user back to the initiative.
*/
public const RETURN_TO_PLAN = 'plan';
public const RETURN_TO_PLAN = 'initiative';
private const SESSION_RETURN_PLAN = 'mautic.plan.task.return_plan.';
private const SESSION_RETURN_PLAN = 'mautic.program.task.return_initiative.';
/**
* Plan to preselect on a new task (from ?plan=ID, used by the plan's "Add task" button).
* Initiative to preselect on a new task (from ?initiative=ID, used by the initiative's "Add task" button).
*/
private ?int $preselectedPlanId = null;
private ?int $preselectedInitiativeId = null;
/**
* The task saved during this request, if any.
@@ -45,18 +45,18 @@ class TaskController extends AbstractStandardFormController
private ?Task $savedTask = null;
/**
* Plan to go back to after Save or Cancel, or null for the task list.
* Initiative to go back to after Save or Cancel, or null for the task list.
*/
private ?int $returnPlanId = null;
private ?int $returnInitiativeId = null;
protected function getModelName(): string
{
return 'plan.task';
return 'program.task';
}
protected function getTemplateBase(): string
{
return '@Plan/Task';
return '@Program/Task';
}
protected function getIndexRoute(): string
@@ -71,7 +71,7 @@ class TaskController extends AbstractStandardFormController
protected function getJsLoadMethodPrefix(): string
{
return 'planTask';
return 'programTask';
}
/**
@@ -84,9 +84,9 @@ class TaskController extends AbstractStandardFormController
public function newAction(Request $request): Response
{
$planId = $request->query->getInt('plan');
$this->preselectedPlanId = $planId > 0 ? $planId : null;
$this->returnPlanId = $this->resolveReturnPlan($request, 'new', $this->preselectedPlanId);
$initiativeId = $request->query->getInt('initiative');
$this->preselectedInitiativeId = $initiativeId > 0 ? $initiativeId : null;
$this->returnInitiativeId = $this->resolveReturnInitiative($request, 'new', $this->preselectedInitiativeId);
return $this->newStandard($request);
}
@@ -98,24 +98,24 @@ class TaskController extends AbstractStandardFormController
public function editAction(Request $request, $objectId, $ignorePost = false): Response
{
$task = $this->getModel($this->getModelName())->getEntity((int) $objectId);
$planId = $task instanceof Task ? $task->getPlan()?->getId() : null;
$this->returnPlanId = $this->resolveReturnPlan($request, (string) (int) $objectId, $planId);
$initiativeId = $task instanceof Task ? $task->getInitiative()?->getId() : null;
$this->returnInitiativeId = $this->resolveReturnInitiative($request, (string) (int) $objectId, $initiativeId);
return $this->editStandard($request, $objectId, $ignorePost);
}
/**
* When the form is opened (GET), records whether it came from a plan (?returnTo=plan); when it is
* When the form is opened (GET), records whether it came from an initiative (?returnTo=initiative); when it is
* submitted (POST), reads that record back. Opening the same form from the task list clears it.
*/
private function resolveReturnPlan(Request $request, string $formKey, ?int $planId): ?int
private function resolveReturnInitiative(Request $request, string $formKey, ?int $initiativeId): ?int
{
$session = $request->getSession();
$key = self::SESSION_RETURN_PLAN.$formKey;
if (!$request->isMethod('POST')) {
$fromPlan = self::RETURN_TO_PLAN === $request->query->get('returnTo') && null !== $planId;
$session->set($key, $fromPlan ? $planId : null);
$fromInitiative = self::RETURN_TO_PLAN === $request->query->get('returnTo') && null !== $initiativeId;
$session->set($key, $fromInitiative ? $initiativeId : null);
}
$value = $session->get($key);
@@ -143,10 +143,10 @@ class TaskController extends AbstractStandardFormController
{
$entity = parent::getFormEntity($action, $objectId, $isClone);
if ('new' === $action && $entity instanceof Task && null === $entity->getPlan() && null !== $this->preselectedPlanId) {
$plan = $this->getModel('plan')->getEntity($this->preselectedPlanId);
if ($plan instanceof Plan) {
$entity->setPlan($plan);
if ('new' === $action && $entity instanceof Task && null === $entity->getInitiative() && null !== $this->preselectedInitiativeId) {
$initiative = $this->getModel('program.initiative')->getEntity($this->preselectedInitiativeId);
if ($initiative instanceof Initiative) {
$entity->setInitiative($initiative);
}
}
@@ -163,8 +163,8 @@ class TaskController extends AbstractStandardFormController
}
/**
* After Save or Cancel (not Apply) on a form opened from a plan, go back to that plan. If the task
* was moved to another plan, go to its new plan. Otherwise keep core's default: the task list.
* After Save or Cancel (not Apply) on a form opened from an initiative, go back to that initiative. If the task
* was moved to another initiative, go to its new initiative. Otherwise keep core's default: the task list.
*
* @param array<string, mixed> $args
*
@@ -172,13 +172,13 @@ class TaskController extends AbstractStandardFormController
*/
protected function getPostActionRedirectArguments(array $args, $action): array
{
if (in_array($action, ['new', 'edit'], true) && null !== $this->returnPlanId) {
$planId = $this->savedTask?->getPlan()?->getId() ?? $this->returnPlanId;
if (in_array($action, ['new', 'edit'], true) && null !== $this->returnInitiativeId) {
$initiativeId = $this->savedTask?->getInitiative()?->getId() ?? $this->returnInitiativeId;
$args['returnUrl'] = $this->generateUrl(PlanController::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $planId]);
$args['contentTemplate'] = PlanController::class.'::viewAction';
$args['viewParameters'] = ['objectId' => $planId];
$args['passthroughVars'] = array_merge($args['passthroughVars'] ?? [], ['mauticContent' => 'plan']);
$args['returnUrl'] = $this->generateUrl(InitiativeController::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $initiativeId]);
$args['contentTemplate'] = InitiativeController::class.'::viewAction';
$args['viewParameters'] = ['objectId' => $initiativeId];
$args['passthroughVars'] = array_merge($args['passthroughVars'] ?? [], ['mauticContent' => 'initiative']);
}
return parent::getPostActionRedirectArguments($args, $action);
+39
View File
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Controller\CommonController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* UTM Taxonomies (Programs > UTM Taxonomies): a placeholder for now, so the menu entry has a
* page. The content (classifying the UTM parameters of the programs' campaigns and links) comes
* later; until then the page shows an empty content block.
*/
class UtmTaxonomyController extends CommonController
{
public const ROUTE_INDEX = 'program_utm_taxonomy_index';
/**
* @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' => '@Program/UtmTaxonomy/list.html.twig',
'passthroughVars' => [
'activeLink' => '#'.self::ROUTE_INDEX,
'mauticContent' => 'programUtmTaxonomy',
'route' => $this->generateUrl(self::ROUTE_INDEX),
],
]);
}
}