feat: Add TargetType form and migration for plan targets

- Implemented TargetType form for managing target details including name, type, priority, stages, estimated size, profile criteria, pain points, value proposition, and preferred channels.
- Created migration scripts for adding type and priority columns to plan objectives and tasks.
- Added migration for creating plan targets and plan target stages tables, including foreign key constraints.
- Introduced stakeholder management with forms and views for creating, editing, and listing stakeholders.
- Enhanced UI with read more functionality for long text descriptions and filtering options in plan tab tables.
This commit is contained in:
Alexandre Gain committed 2026-11-08 11:54:25 +01:00
1 parent 8c8d7a6f95
commit 8696acd01c
52 files changed
+3178 -125

No files matched your search

+34 -17
View File
@@ -10,15 +10,15 @@ This repository holds only the plugin source. The bundle files are at the reposi
2. Clear the cache and register the plugin:
```bash
php bin/console cache:clear
column
php bin/console mautic:plugins:reload
```
3. In Mautic, go to **Settings > Plugins**, open **Plan** and publish it.
Plans are listed under **Planning > Plans** in the main menu (URL `/s/plans`), and tasks under **Planning > Tasks** (URL `/s/plan-tasks`). Users who aren't administrators need a role with the **Plan Permissions** set in **Settings > Roles**.
Plans are listed under **Planning > Plans** in the main menu (URL `/s/plans`), tasks under **Planning > Tasks** (URL `/s/plan-tasks`), and the stakeholder directory under **Planning > Stakeholders** (URL `/s/plan-stakeholders`). Users who aren't administrators need a role with the **Plan Permissions** set in **Settings > Roles**.
Before using the items of a plan's **Description** and **Allocation** tabs, an administrator sets up their types in **Settings > Configuration > Plan Settings**.
Before using the items of a plan's **Description**, **Objectives**, **Allocations** and **Tasks** tabs, an administrator sets up their types in **Settings > Configuration > Plan Settings**.
## Development
@@ -62,8 +62,8 @@ The plugin uses the IntegrationsBundle conventions:
- `Controller/PlanController.php`: list, detail page, create, edit and delete (single and batch), built on core's `AbstractStandardFormController`
- `Resources/views/Plan/list.html.twig`: the list. A plan's name opens its detail page.
- `Resources/views/Plan/form.html.twig` and `details.html.twig`: the create/edit form and the detail page. Both have the same six tabs, from `_tabs.html.twig`: **Details**, **Description** (description items), **Objectives**, **Allocation** (planned budget, currency and allocation items), **Targets** and **Tasks**.
- `Resources/views/Plan/_task_table.html.twig`: the plan's tasks in the Tasks tab. It has the same columns as **Planning > Tasks** (ID, Name, Description, Start date, End date, Status), in tree order: each task is followed by its sub-tasks, indented, and a task's name shows its number of sub-tasks. On the detail page it has an **Add task** button and links to each task. On the plan form it is read-only, so that following a link doesn't drop unsaved changes.
- `Resources/views/Plan/form.html.twig` and `details.html.twig`: the create/edit form and the detail page. Both have the same six tabs, from `_tabs.html.twig`: **Details**, **Description** (description items), **Objectives**, **Allocations** (planned budget, currency and allocation items), **Targets** and **Tasks**.
- `Resources/views/Plan/_task_table.html.twig`: the plan's tasks in the Tasks tab. It has the harmonized tab columns (pictogram, Type, Name, Description, Start date, End date, Status — no ID), in tree order: each task is followed by its sub-tasks, indented, and a task's name shows its number of sub-tasks. On the detail page it has an **Add task** button, links to each task and the filter/sort of the other tabs. On the plan form it is read-only (no links, no filter), so that following a link doesn't drop unsaved changes.
- `Controller/TaskController.php` and `Resources/views/Task/`: the task list, and the create/edit form (**Planning > Tasks**). `new?plan=ID` preselects the plan. After Save or Cancel, the user goes back to where the form was opened from. Opened from **Planning > Tasks**, that's the task list. Opened from a plan's Tasks tab, whose links carry `returnTo=plan`, that's the plan (its new plan, if the task was moved). The origin is stored in the session when the form is opened, because the form posts without the query string.
- `Assets/js/plan.js`: on the form, the objectives editor (add, remove, drag-and-drop ordering), and after a failed save, marking the tabs that contain errors with an icon and opening the first one. Started by `Mautic.planOnLoad()`.
@@ -79,7 +79,7 @@ Which tab opens on a plan's detail page and form (`Mautic.planInitTabs`):
The main menu has a top-level **Planning** entry, with **Plans** and **Tasks** as its items. Add future planning pages as more children of `mautic.plan.menu.root` in `Config/config.php`.
The **Targets** tab only shows an empty state for now.
The **Targets** tab lists the plan's audiences, harmonized like the other tabs: pictogram (fixed per target type), Type, Name, Priority, Stages, Estimated size, Profile criteria, Pain points, Value proposition, Preferred channels.
| Route | URL | Purpose |
| --- | --- | --- |
@@ -87,12 +87,14 @@ The **Targets** tab only shows an empty state for now.
| `plan_action` | `/s/plans/{objectAction}/{objectId}` | `view`, `new`, `edit`, `delete`, `batchDelete` |
| `plan_task_index` | `/s/plan-tasks/{page}` | Task list, with search on name and description |
| `plan_task_action` | `/s/plan-tasks/{objectAction}/{objectId}` | `new` (optional `?plan=ID`), `edit`, `delete`, `batchDelete` |
| `plan_stakeholder_index` | `/s/plan-stakeholders/{page}` | Stakeholder directory, with search on name, email, role and type |
| `plan_stakeholder_action` | `/s/plan-stakeholders/{objectAction}/{objectId}` | `new`, `edit`, `delete`, `batchDelete` |
The plan templates don't pass `routeBase` to core's button helpers (`page_actions`, `list_actions`) when a "close" button is involved: from `routeBase`, core builds `mautic_<routeBase>_*` route names, which don't exist in this plugin. The other buttons use the `actionRoute` (`plan_action`) that the controller passes to the template.
Permission keys:
- `plan:plans:*` and `plan:tasks:*`: `viewown`, `viewother`, `editown`, `editother`, `create`, `deleteown`, `deleteother`, `publishown`, `publishother`, `full`. "Own" means items the user created (`createdBy`), as in core objects.
- `plan:plans:*`, `plan:tasks:*` and `plan:stakeholders:*`: `viewown`, `viewother`, `editown`, `editother`, `create`, `deleteown`, `deleteother`, `publishown`, `publishother`, `full`. "Own" means items the user created (`createdBy`), as in core objects.
- `plan:categories:*`: managing the `plan` category type.
### The Plan object
@@ -100,7 +102,8 @@ Permission keys:
- `Entity/Plan.php`: the entity (table `plans`), with its Doctrine mapping and validation rules
- `Entity/PlanStatus.php`: the status enum (`draft`, `planned`, `active`, `paused`, `completed`, `archived`)
- `Entity/PlanRepository.php`: the repository
- `Entity/PlanObjective.php` and `PlanObjectiveRepository.php`: a plan's objectives (table `plan_objectives`): title, description, position and an "achieved" flag
- `Entity/PlanObjective.php` and `PlanObjectiveRepository.php`: a plan's objectives (table `plan_objectives`): type (with its pictogram), title, description, position and an "achieved" flag
- `Entity/Target.php`, `TargetType.php`, `TargetPriority.php` and `TargetRepository.php`: a plan's targets (table `plan_targets`), the audiences of the Targets tab: name, a fixed type (persona, ICP, broad audience, lifecycle cohort, partner/influencer — each with its own pictogram), a priority (primary, secondary, exclusion), any number of Mautic stages (join table `plan_target_stages`), an estimated size, profile criteria, pain points, a value proposition, preferred channels (checkboxes: email, SMS, web, social organic, paid social, paid search, events/webinar, outbound sales, partners) and a position. Targets are edited inside the plan form like objectives, and shown in the harmonized table of the Targets tab
- `Model/PlanModel.php`: the model, available as `mautic.plan.model.plan` or with `getModel('plan')`. A new plan from `getEntity()` has the current user as owner.
- `Entity/PlanDescriptionItem.php` and `PlanDescriptionItemRepository.php`: a plan's description items (table `plan_description_items`): type, description and position. They make up the Description tab and replace the former `description` field.
- `Form/Type/PlanType.php`, `PlanObjectiveType.php` and `PlanDescriptionItemType.php`: the create and edit form, with the objectives and the description items as collections
@@ -117,14 +120,18 @@ Behaviour to know about:
- `getObjectives()` and `getDescriptionItems()` return the rows sorted by position, as a new collection. The mapping's `orderBy` isn't enough: after a reorder, the page shown right after saving uses the collection already loaded, in its old order.
- Text typed in the plan form, including in objectives and description items, is kept as typed: line breaks, `&` and quotes are preserved, and HTML tags are removed. This depends on `PlanType` passing a mask array to `CleanFormSubscriber`. Without one, core HTML-encodes every value, again on each save.
### Typed items: description items and allocation items
### Typed items: description items, allocation items and tasks
- A **description item** (Description tab, `Entity/PlanDescriptionItem.php`) has a type and a description. More fields are planned.
- An **allocation item** (Allocation tab, `Entity/PlanAllocationItem.php`, table `plan_allocation_items`) is a cost line: type (with its pictogram), name (optional), description, planned cost and real cost. Costs are `DECIMAL(12,2)`, in the general currency.
- Both kinds are edited inside the plan form, like objectives: add, remove, drag to reorder. They're saved and deleted with the plan.
- An administrator sets up each kind's types in **Settings > Configuration > Plan Settings**, in two sections. Each type has a name and a description for each language installed in Mautic, and the default language (the `locale` parameter) requires a name. Each type also has a pictogram. Users see their own language, or the default language when theirs is empty. The order of the types is the order of the dropdown.
- The types are stored in `config/local.php`, in the `plan_description_item_types` and `plan_allocation_item_types` parameters. Read them with `Service/ItemTypeProvider.php`, passing the kind (`description` or `allocation`). In templates, use the Twig functions `plan_item_type_name(kind, key)`, `plan_item_type_description(kind, key)` and `plan_item_type_icon(kind, key)`, plus `plan_currency()` and `plan_money(amount)` (`Twig/PlanExtension.php`).
- **Every item type has a pictogram**, chosen by the administrator from a list of Remix Icons that Mautic ships (`Service/Pictograms.php`, each checked against Mautic 7's icon stylesheet), with a live preview. It's stored as `icon` in the type. On the plan form it appears next to the type dropdown when a type is chosen. On the detail page, the Description tab is a table with three columns: Pictogram, Type, Description. The Allocation tab's cost lines list has the same Pictogram column, before Type.
- An **objective** (`Entity/PlanObjective.php`) has a type too (with its pictogram), a title, a priority (a whole number from 1, the most important, to 99), a description and the achieved flag. The plan's Objectives tab lists them by priority; ties keep the manual order. The priority is required.
- A **task** (`Entity/Task.php`) has a type too (with its pictogram): see *The Task object* above.
- Description items, allocation items and objectives are edited inside the plan form, like objectives: add, remove, drag to reorder. They're saved and deleted with the plan. Tasks are edited on their own form, where the type's pictogram and description appear around the type dropdown.
- An administrator sets up each kind's types in **Settings > Configuration > Plan Settings**, in four sections. Each type has a name and a description for each language installed in Mautic, and the default language (the `locale` parameter) requires a name. Each type also has a pictogram. Users see their own language, or the default language when theirs is empty. The order of the types is the order of the dropdown.
- The types are stored in `config/local.php`, in the `plan_description_item_types`, `plan_allocation_item_types`, `plan_objective_types` and `plan_task_types` parameters. Read them with `Service/ItemTypeProvider.php`, passing the kind (`description`, `allocation`, `objective` or `task`). In templates, use the Twig functions `plan_item_type_name(kind, key)`, `plan_item_type_description(kind, key)` and `plan_item_type_icon(kind, key)`, plus `plan_currency()` and `plan_money(amount)` (`Twig/PlanExtension.php`).
- **Every item type has a pictogram**, chosen by the administrator from a list of Remix Icons that Mautic ships (`Service/Pictograms.php`, each checked against Mautic 7's icon stylesheet), with a live preview. It's stored as `icon` in the type. On the plan form and the task form it appears next to the type dropdown when a type is chosen.
- **The four item tabs of a plan's detail page are harmonized** (`Resources/views/Plan/details.html.twig`, `_task_table.html.twig`, `_tab_table_filter.html.twig`): every column starts with the pictogram (its header stays empty — no "Pictogram" label), then Type, Name, Description, and the kind's other fields; objectives show their Priority after Description, and tasks end with Status. The plan's Tasks tab doesn't show task IDs (`data-task-id` still carries them). Each tab has one filter box that matches every column, and every column header sorts the rows asc/desc on click (`Mautic.planInitTabTable` in `Assets/js/plan.js`, client-side). The objective's achieved flag is the Status column of its table.
- A description item's long description is **clamped to 10 lines** in the Description tab, with a *Read more* / *Show less* toggle (`_description_read_more.html.twig`, `Mautic.planInitReadMore`). The toggle appears only when the text really overflows: the pane is hidden on page load, so the measurement waits for the tab to be shown.
- Each type has a hidden key, generated when it's created and never changed. Items store that key, so renaming a type renames it everywhere.
- A type that items use can't be removed: the configuration isn't saved, and the error lists the types and how many items use them (`EventListener/ConfigSubscriber.php`, on `CONFIG_PRE_SAVE`).
- On the plan form, the selected type's description is shown under the type dropdown. When no types are set up, the tab says where to set them up.
@@ -134,12 +141,21 @@ Behaviour to know about:
- `Plan::getAllocationTotals()` adds up the allocation items' planned and real costs, in the general currency. The sums are done in cents, as integers.
- The plan detail page shows them under the title, after the plan status, as on an email's page (`publishStatus` block): a "Planned" tag and a "Real" tag. A real total above the planned total is red, otherwise green.
- The Allocation tab of the detail page lists the cost lines, followed by a total row.
- The Allocations tab of the detail page lists the cost lines, followed by a total row.
- `isAchieved` is toggled by hand on the form for now.
### The Stakeholder object
- `Entity/Stakeholder.php` and `StakeholderRepository.php`: a stakeholder (table `plan_stakeholders`), the global directory of the people, companies and teams involved in the plans: name, email (validated, indexed for duplicate detection), phone, role, type and the active flag (`isPublished`). Independent of plans.
- `Entity/PlanStakeholder.php` and `PlanStakeholderRepository.php`: the link between a plan and a stakeholder (table `plan_stakeholders_plan`), with the stakeholder's role in that plan (free text) and a position. Deleting the plan or the stakeholder deletes the link (ON DELETE CASCADE both sides).
- `Model/StakeholderModel.php`: the model, available as `mautic.plan.model.stakeholder` or with `getModel('plan.stakeholder')`. On save, the phone number is normalized to E.164 using the default region from **Settings > Configuration > Plan Settings** (parameter `plan_stakeholder_phone_region`, `FR` by default); a number that doesn't parse is kept exactly as typed, and the save is never blocked.
- `Controller/StakeholderController.php` and `Resources/views/Stakeholder/`: the directory (**Planning > Stakeholders**), with the columns ID, Pictogram, Type, Name, Role, Email (mailto link), Phone (tel link), Active, and **Assigned plans** — the plans the stakeholder is linked to, each with its role in that plan. The detail page lists those plans too.
- The stakeholder's type is the key of a stakeholder type set up in **Settings > Configuration > Plan Settings** (parameter `plan_stakeholder_types`), same pattern as the other item types, pictogram included.
- A plan's **Stakeholders tab** links the directory to the plan: each row picks an active stakeholder and gives its role in the plan. The tab shows the harmonized table (pictogram, Type, Name, Role in the plan, Role, Email, Phone, Active). Unpublished stakeholders are not offered in the picker, but keep their links.
### The Task object
- `Entity/Task.php` and `TaskRepository.php`: a task (table `plan_tasks`): name, description, plan, optional parent task, optional start and end dates, and status
- `Entity/Task.php` and `TaskRepository.php`: a task (table `plan_tasks`): type (with its pictogram), name, description, plan, optional parent task, optional start and end dates, and status
- `Entity/TaskStatus.php`: the status enum. The order of its cases is the order of the dropdown: `new` (New, the default), `todo` (To do), `in_progress` (In progress), `done` (Done). Stored as `VARCHAR(20)`, indexed.
- `Model/TaskModel.php`: the model, available as `mautic.plan.model.task` or with `getModel('plan.task')`. `getTaskTree($plan)` returns a plan's tasks in tree order, with their depth.
- `Form/Type/TaskType.php`: the create and edit form
@@ -149,7 +165,8 @@ Behaviour to know about:
- A task must belong to a plan. A plan can have any number of tasks, including none.
- A task's end date must be on or after its start date, when both are set.
- The task list (**Planning > Tasks**) shows these columns, in this order: ID, Name, Description (first 120 characters), Start date, End date, Status. Every column except Description can be sorted.
- The task list (**Planning > Tasks**) shows these columns, in this order: ID, Pictogram, Type, Name, Description (first 120 characters), Start date, End date, Status. Every column except Pictogram and Description can be sorted.
- A task's type is required. It's the key of a task type set up in **Settings > Configuration > Plan Settings** (parameter `plan_task_types`); on the task form the type's pictogram appears next to the dropdown and its description under it. The plan's Tasks tab shows the same Pictogram and Type columns as the task list, without the ID column.
- Deleting a plan deletes its tasks (`plan_id` `ON DELETE CASCADE`).
- Deleting a task keeps its sub-tasks, which become top-level tasks (`parent_id` `ON DELETE SET NULL`).
- Tasks are edited on their own pages, not inside the plan form: a task can only be picked as a parent once it exists.
@@ -160,7 +177,7 @@ After you change `Assets/js/plan.js`, run `php bin/console mautic:assets:generat
Mautic creates the `plans` table from the entity mapping when it installs the plugin. However, the installer drops foreign keys that point to core tables (`users`, `categories`). `Migrations/Version_0_2_0.php` adds them and only runs when they are missing. Core runs plugin migrations when the plugin version changes, and `EventListener/PluginInstallSubscriber.php` also runs them right after a fresh install.
`Migrations/Version_0_3_0.php` adds `plans.version` and the `plan_objectives` table to installs created before 0.3.0. `Migrations/Version_0_4_0.php` adds the `plan_tasks` table and its two foreign keys, and adds the foreign keys to an existing `plan_tasks` table that lacks them. `Migrations/Version_0_5_0.php` adds the tasks' `start_date`, `end_date` and `status` columns, and existing tasks get the status `new`. `Migrations/Version_0_6_0.php` creates `plan_description_items` with its foreign key to `plans` (`ON DELETE CASCADE`), and drops `plans.description`, deleting its content. `Migrations/Version_0_7_0.php` creates `plan_allocation_items` with its foreign key to `plans` (`ON DELETE CASCADE`). `Migrations/Version_0_8_0.php` drops the currency columns (`plans.currency`, `plan_allocation_items.planned_currency` and `real_currency`), since every amount is now in the general currency. Every migration checks the schema first, so it's safe to run again.
`Migrations/Version_0_3_0.php` adds `plans.version` and the `plan_objectives` table to installs created before 0.3.0. `Migrations/Version_0_4_0.php` adds the `plan_tasks` table and its two foreign keys, and adds the foreign keys to an existing `plan_tasks` table that lacks them. `Migrations/Version_0_5_0.php` adds the tasks' `start_date`, `end_date` and `status` columns, and existing tasks get the status `new`. `Migrations/Version_0_6_0.php` creates `plan_description_items` with its foreign key to `plans` (`ON DELETE CASCADE`), and drops `plans.description`, deleting its content. `Migrations/Version_0_7_0.php` creates `plan_allocation_items` with its foreign key to `plans` (`ON DELETE CASCADE`). `Migrations/Version_0_8_0.php` drops the currency columns (`plans.currency`, `plan_allocation_items.planned_currency` and `real_currency`), since every amount is now in the general currency. `Migrations/Version_0_9_0.php` adds `plan_tasks.type` (nullable; tasks existed before types, so each existing task must be given a type before it can be saved again). `Migrations/Version_0_10_0.php` adds `plan_objectives.type` (nullable; existing objectives must be given a type before the plan can be saved again). `Migrations/Version_0_10_1.php` adds `plan_objectives.priority` (`INT NOT NULL`, default 1; existing objectives get 1). `Migrations/Version_0_11_0.php` creates `plan_targets` and the `plan_target_stages` join table. `Migrations/Version_0_12_0.php` creates `plan_stakeholders` and `plan_stakeholders_plan`, with their foreign keys. Every migration checks the schema first, so it's safe to run again.
If a migration builds its `CREATE TABLE` with Doctrine's `SchemaTool`, keep only the statement for its own table. `SchemaTool` also returns statements for other tables, such as Symfony Messenger's `messenger_messages`. Those fail on an existing install, and the migration engine then reports "There is no active transaction" instead of the real error.