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

+173
View File
@@ -0,0 +1,173 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Controller\AbstractStandardFormController;
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 "initiative": model mautic.program.model.initiative, permission base
* program:initiatives (from InitiativeModel), translation base mautic.program, session base mautic.program.
*/
class InitiativeController extends AbstractStandardFormController
{
public const ROUTE_INDEX = 'initiative_index';
public const ROUTE_ACTION = 'initiative_action';
protected function getModelName(): string
{
return 'program.initiative';
}
protected function getTemplateBase(): string
{
return '@Program/Initiative';
}
/**
* Core would build mautic_initiative_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;
}
/**
* @param int $page
*/
public function indexAction(Request $request, $page = 1): Response
{
return $this->indexStandard($request, $page);
}
/**
* 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.
*
* @param int $objectId
*/
public function viewAction(Request $request, $objectId): Response
{
$initiative = $this->getModel($this->getModelName())->getEntity((int) $objectId);
if (!$initiative instanceof Initiative) {
return $this->notFound('mautic.program.error.notfound');
}
if (!$this->checkActionPermission('view', $initiative)) {
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(
[
'program:tasks:create',
'program:tasks:editown',
'program:tasks:editother',
],
'RETURN_ARRAY',
null,
true
);
return $this->delegateView([
'viewParameters' => [
'item' => $initiative,
'permissions' => $permissions,
'taskTree' => $this->getTaskModel()->getTaskTree($initiative),
'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' => '#initiative_index',
'mauticContent' => $this->getJsLoadMethodPrefix(),
'route' => $this->generateUrl(self::ROUTE_ACTION, ['objectAction' => 'view', 'objectId' => $initiative->getId()]),
],
]);
}
/**
* Adds the initiative'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
{
$initiative = $args['viewParameters']['entity'] ?? null;
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);
}
private function getTaskModel(): TaskModel
{
$model = $this->getModel('program.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);
}
}