refactor(program): move item types out of Settings > Configuration

Relocate the item type lists (insights, allocations, objectives, tasks,
stakeholders, audience values) from the Configuration tab to a dedicated
"Item types" page under Programs, served by ItemTypesController at
/program-item-types and guarded by the new program:itemtypes:view
permission. The Program settings tab in Configuration now only holds the
general settings (currency, stakeholder phone region, audience attribute
toggles), so ConfigSubscriber no longer needs the item repositories; the
in-use type protection moved to ItemTypeInUseGuard.
This commit is contained in:
Alexandre Gain committed 2026-11-14 09:20:21 +01:00
1 parent 71ff11390b
commit 687d33d30c
14 files changed
+444 -219

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Service;
use MauticPlugin\ProgramBundle\Entity\InitiativeAllocationItemRepository;
use MauticPlugin\ProgramBundle\Entity\InitiativeDescriptionItemRepository;
use MauticPlugin\ProgramBundle\Entity\InitiativeObjectiveRepository;
use MauticPlugin\ProgramBundle\Entity\StakeholderRepository;
use MauticPlugin\ProgramBundle\Entity\TaskRepository;
/**
* Refuses to remove item types that items or tasks still use: a stored item references its type
* by key (never by name), so removing a type in use would orphan it ("Unknown type"). Used by the
* Item types page (ItemTypesController) before saving the lists.
*/
class ItemTypeInUseGuard
{
public function __construct(
private InitiativeDescriptionItemRepository $descriptionItemRepository,
private InitiativeAllocationItemRepository $allocationItemRepository,
private InitiativeObjectiveRepository $objectiveRepository,
private TaskRepository $taskRepository,
private StakeholderRepository $stakeholderRepository,
private ItemTypeProvider $typeProvider,
) {
}
/**
* The types that would be removed while items still use them, keyed by the kind's local.php
* parameter, each entry "Type name (number of items that use it)". Empty when the submitted
* lists may be saved.
*
* @param array<string, mixed> $typesByParameter parameter => the submitted list of types
*
* @return array<string, list<string>> parameter => "Name (count)" per removed type in use
*/
public function getRemovedInUseTypes(array $typesByParameter): array
{
// Kinds whose items store a type key. The decision roles and tones have no guard: they are
// plain value lists, and an audience keeps its values as raw strings.
$usage = [
ItemTypeProvider::KIND_DESCRIPTION => $this->descriptionItemRepository->countByType(),
ItemTypeProvider::KIND_ALLOCATION => $this->allocationItemRepository->countByType(),
ItemTypeProvider::KIND_OBJECTIVE => $this->objectiveRepository->countByType(),
ItemTypeProvider::KIND_TASK => $this->taskRepository->countByType(),
ItemTypeProvider::KIND_STAKEHOLDER => $this->stakeholderRepository->countByType(),
];
$removedInUse = [];
foreach ($usage as $kind => $counts) {
$parameter = ItemTypeProvider::getParameter($kind);
if (!array_key_exists($parameter, $typesByParameter)) {
continue;
}
$submitted = [];
foreach (ItemTypeProvider::normalize((array) $typesByParameter[$parameter]) as $type) {
$submitted[$type['key']] = true;
}
$names = [];
foreach ($counts as $key => $count) {
if (!isset($submitted[$key])) {
$names[] = sprintf('%s (%d)', $this->typeProvider->getName($kind, $key) ?? $key, $count);
}
}
if ([] !== $names) {
$removedInUse[$parameter] = $names;
}
}
return $removedInUse;
}
}
+4 -3
View File
@@ -9,17 +9,18 @@ use Mautic\CoreBundle\Helper\LanguageHelper;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Reads the item types set up in Settings > Configuration > Program Settings. There is one list of types per kind:
* Reads the item types set up on the Item types page (Programs > Item types). There is one list of types per kind:
* - KIND_DESCRIPTION: types of description items (the Insights tab), parameter program_description_item_types;
* - KIND_ALLOCATION: types of allocation items (Allocation tab), parameter program_allocation_item_types;
* - KIND_OBJECTIVE: types of objectives (Objectives tab), parameter program_objective_types;
* - KIND_TASK: types of tasks (Programs > Tasks and the initiative's Tasks tab), parameter program_task_types;
* - KIND_STAKEHOLDER: types of stakeholders (Programs > Stakeholders), parameter program_stakeholder_types;
* - KIND_AUDIENCE_DECISION_ROLE: values of an audience's "Decision-making role" attribute, parameter
* program_audience_decision_roles (Settings > Configuration > Program Settings);
* program_audience_decision_roles (Item types page);
* - KIND_AUDIENCE_TONE: values of an audience's "Preferred tone" attribute, parameter program_audience_tones.
*
* Each list is stored in local.php, in display order:
* Each list is stored in local.php, in display order, and edited on the Item types page
* (Programs > Item types; ItemTypesController):
*
* [
* ['key' => 'type_1a2b3c4d', 'names' => ['en_US' => 'Context', 'fr' => 'Contexte'],