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

+5 -29
View File
@@ -6,26 +6,25 @@ namespace MauticPlugin\ProgramBundle\Form\Type;
use MauticPlugin\ProgramBundle\Model\StakeholderModel;
use MauticPlugin\ProgramBundle\Service\CurrencyProvider;
use MauticPlugin\ProgramBundle\Service\ItemTypeProvider;
use MauticPlugin\ProgramBundle\Service\AudienceAttributes;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* The "Initiative Settings" tab of Settings > Configuration. Each child is a local.php parameter:
* The "Program Settings" tab of Settings > Configuration: the plugin's general settings only.
* Each child is a local.php parameter:
* - program_currency: the currency of every amount in the plugin (general setting);
* - program_stakeholder_phone_region: default region for stakeholder phone numbers typed without a prefix;
* - one list of item types per kind (description, allocation, objective, task, stakeholder, and the
* values of an audience's decision roles and tones), each with a pictogram;
* - one toggle per audience persona attribute (AudienceAttributes), so each install defines its
* personas as it needs (b2b, b2c…).
*
* The item type lists moved to their own page under Programs (ItemTypesController, Programs >
* Item types).
*
* @extends AbstractType<array<string, mixed>>
*/
class ConfigType extends AbstractType
@@ -62,29 +61,6 @@ class ConfigType extends AbstractType
'empty_data' => StakeholderModel::DEFAULT_PHONE_REGION,
]);
foreach (ItemTypeProvider::PARAMETERS as $kind => $parameter) {
// The decision roles and the tones are plain value lists: no pictogram.
$withIcon = !in_array($kind, [ItemTypeProvider::KIND_AUDIENCE_DECISION_ROLE, ItemTypeProvider::KIND_AUDIENCE_TONE], true);
$builder->add($parameter, CollectionType::class, [
'label' => false,
'entry_type' => ItemTypeConfigType::class,
'entry_options' => ['label' => false, 'with_icon' => $withIcon],
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_name' => '__type__',
'required' => false,
'error_bubbling' => false,
]);
// Stored as a clean list (0..n-1, empty texts dropped), in the order shown on the page.
$builder->get($parameter)->addModelTransformer(new CallbackTransformer(
fn ($types): array => ItemTypeProvider::normalize(is_array($types) ? $types : []),
fn ($types): array => ItemTypeProvider::normalize(is_array($types) ? $types : []),
));
}
// One toggle per audience persona attribute (AudienceAttributes), defaults to enabled.
foreach (AudienceAttributes::ATTRIBUTES as $attribute => $field) {
$builder->add(AudienceAttributes::toggleParameter($attribute), YesNoButtonGroupType::class, [
+1 -1
View File
@@ -20,7 +20,7 @@ use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
/**
* One item type (description or allocation) in Settings > Configuration > Initiative Settings: a name and a
* One item type in a list of the Item types page (Programs > Item types): a name and a
* description per language, and a pictogram.
*
* The key is hidden. It is generated when the type is created and never changes, so that renaming a
+58
View File
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Form\Type;
use Mautic\CoreBundle\Form\Type\FormButtonsType;
use MauticPlugin\ProgramBundle\Service\ItemTypeProvider;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* The form of the Item types page (Programs > Item types): one list of types per kind — insights
* (description items), allocations, objectives, tasks, stakeholders, and the values offered for
* an audience's decision roles and tones. Each child is one of ItemTypeProvider::PARAMETERS,
* keyed exactly by the local.php parameter that stores the list, so saving is a straight merge
* into the local configuration.
*
* @extends AbstractType<array<string, mixed>>
*/
class ItemTypesType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
foreach (ItemTypeProvider::PARAMETERS as $kind => $parameter) {
// The decision roles and the tones are plain value lists: no pictogram.
$withIcon = !in_array($kind, [ItemTypeProvider::KIND_AUDIENCE_DECISION_ROLE, ItemTypeProvider::KIND_AUDIENCE_TONE], true);
$builder->add($parameter, CollectionType::class, [
'label' => false,
'entry_type' => ItemTypeConfigType::class,
'entry_options' => ['label' => false, 'with_icon' => $withIcon],
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'prototype_name' => '__type__',
'required' => false,
'error_bubbling' => false,
]);
// Stored as a clean list (0..n-1, empty texts dropped), in the order shown on the page.
$builder->get($parameter)->addModelTransformer(new CallbackTransformer(
fn ($types): array => ItemTypeProvider::normalize(is_array($types) ? $types : []),
fn ($types): array => ItemTypeProvider::normalize(is_array($types) ? $types : []),
));
}
$builder->add('buttons', FormButtonsType::class);
}
public function getBlockPrefix(): string
{
// The POST data keys: program_item_types[<parameter>][<index>][…].
return 'program_item_types';
}
}