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

+15 -3
View File
@@ -51,6 +51,12 @@ return [
'path' => '/program-utm-taxonomies/{page}',
'controller' => 'MauticPlugin\ProgramBundle\Controller\UtmTaxonomyController::indexAction',
],
// The type lists of the plugin's items (Insights, allocations, objectives, tasks,
// stakeholders, audience values), moved out of Settings > Configuration.
'program_item_types_index' => [
'path' => '/program-item-types',
'controller' => 'MauticPlugin\ProgramBundle\Controller\ItemTypesController::indexAction',
],
],
],
@@ -60,7 +66,7 @@ return [
'mautic.program.menu.root' => [
'id' => 'program_root',
'iconClass' => 'ri-calendar-line',
'access' => ['program:initiatives:viewown', 'program:initiatives:viewother', 'program:tasks:viewown', 'program:tasks:viewother', 'program:stakeholders:viewown', 'program:stakeholders:viewother', 'program:audiences:viewown', 'program:audiences:viewother'],
'access' => ['program:initiatives:viewown', 'program:initiatives:viewother', 'program:tasks:viewown', 'program:tasks:viewother', 'program:stakeholders:viewown', 'program:stakeholders:viewother', 'program:audiences:viewown', 'program:audiences:viewother', 'program:itemtypes:view'],
'priority' => 5,
'children' => [
'mautic.program.menu.index' => [
@@ -93,6 +99,12 @@ return [
'access' => ['program:initiatives:viewown', 'program:initiatives:viewother'],
'priority' => 60,
],
'mautic.program.menu.item_types' => [
'id' => 'program_item_types_index',
'route' => 'program_item_types_index',
'access' => ['program:itemtypes:view'],
'priority' => 55,
],
],
],
],
@@ -129,8 +141,8 @@ return [
// Program Settings. Read it through CurrencyProvider.
'program_currency' => 'EUR',
// Item types, edited in Settings > Configuration > Program Settings. Read them through ItemTypeProvider.
// Each is a list of ['key' => …, 'names' => [locale => …], 'descriptions' => [locale => …]],
// Item types, edited on the Item types page (Programs > Item types). Read them through
// ItemTypeProvider. Each is a list of ['key' => …, 'names' => [locale => …], 'descriptions' => [locale => …]],
// plus 'icon' => a Remix Icon class for description, allocation, objective, task and stakeholder types.
'program_description_item_types' => [],
'program_allocation_item_types' => [],
+118
View File
@@ -0,0 +1,118 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Controller;
use Mautic\CoreBundle\Configurator\Configurator;
use Mautic\CoreBundle\Controller\AbstractFormController;
use Mautic\CoreBundle\Helper\CacheHelper;
use MauticPlugin\ProgramBundle\Form\Type\ItemTypesType;
use MauticPlugin\ProgramBundle\Service\ItemTypeInUseGuard;
use MauticPlugin\ProgramBundle\Service\ItemTypeProvider;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* The Item types page (Programs > Item types): the type lists of the plugin's items — insights
* (description items), allocations, objectives, tasks, stakeholders, and the values offered for
* an audience's decision roles and tones. Formerly part of Settings > Configuration > Program
* Settings; now on its own page under Programs, so a user with the program:itemtypes permissions
* manages the types without being an administrator.
*
* Each list is a local.php parameter (ItemTypeProvider::PARAMETERS), saved through core's
* Configurator exactly like Settings > Configuration saves its own forms: merge, write, refresh
* the config. A type that items still use cannot be removed (ItemTypeInUseGuard).
*
* Permissions: program:itemtypes:view shows the page, program:itemtypes:edit saves it.
*/
class ItemTypesController extends AbstractFormController
{
public const ROUTE_INDEX = 'program_item_types_index';
/**
* Shows the lists, and saves them on POST.
*/
public function indexAction(
Request $request,
FormFactoryInterface $formFactory,
ItemTypeProvider $typeProvider,
ItemTypeInUseGuard $inUseGuard,
Configurator $configurator,
CacheHelper $cacheHelper,
): Response {
if (!$this->security->isGranted('program:itemtypes:view')) {
$this->throwAccessDenied();
}
$action = $this->generateUrl(self::ROUTE_INDEX);
// The current lists, each keyed by the local.php parameter that stores it.
$data = [];
foreach (ItemTypeProvider::PARAMETERS as $kind => $parameter) {
$data[$parameter] = $typeProvider->getTypes($kind);
}
$form = $formFactory->create(ItemTypesType::class, $data, ['action' => $action]);
$isWritable = $configurator->isFileWritable();
if ('POST' === $request->getMethod()) {
if (!$this->security->isGranted('program:itemtypes:edit')) {
$this->throwAccessDenied();
}
// Cancel: back to a fresh form, nothing saved.
if ($this->isFormCancelled($form)) {
return new RedirectResponse($action);
}
if ($isWritable && $this->isFormValid($form)) {
/** @var array<string, mixed> $formData local.php parameter => its types */
$formData = $form->getData();
$removedInUse = $inUseGuard->getRemovedInUseTypes($formData);
if ([] !== $removedInUse) {
foreach ($removedInUse as $names) {
$form->addError(new FormError(
$this->translator->trans('mautic.program.config.type.in_use', ['%types%' => implode(', ', $names)], 'validators')
));
}
} else {
// Merge each list into the local configuration, then write — the same thing
// Settings > Configuration does with its own forms.
foreach (ItemTypeProvider::PARAMETERS as $kind => $parameter) {
if (array_key_exists($parameter, $formData)) {
$configurator->mergeParameters([$parameter => $formData[$parameter]]);
}
}
$configurator->write();
$this->addFlashMessage('mautic.program.item_type.saved');
// local.php changed: the cached container is stale until refreshed.
$cacheHelper->refreshConfig();
return new RedirectResponse($action);
}
}
}
return $this->delegateView([
'viewParameters' => [
'form' => $form->createView(),
'isWritable' => $isWritable,
],
'contentTemplate' => '@Program/ItemTypes/form.html.twig',
'passthroughVars' => [
'activeLink' => '#'.self::ROUTE_INDEX,
'mauticContent' => 'programItemTypes',
'route' => $action,
],
]);
}
}
+4 -66
View File
@@ -6,37 +6,21 @@ namespace MauticPlugin\ProgramBundle\EventListener;
use Mautic\ConfigBundle\ConfigEvents;
use Mautic\ConfigBundle\Event\ConfigBuilderEvent;
use Mautic\ConfigBundle\Event\ConfigEvent;
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;
use MauticPlugin\ProgramBundle\Form\Type\ConfigType;
use MauticPlugin\ProgramBundle\Service\ItemTypeProvider;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Adds the "Program" tab to Settings > Configuration (description, allocation, objective and task item
* types), and refuses to save it when a type that items still use has been removed.
* Adds the "Program Settings" tab to Settings > Configuration: the plugin's general settings
* (the currency, the stakeholder phone region, the audience attribute toggles). The item type
* lists used to live here too; they moved to their own page under Programs (ItemTypesController,
* Programs > Item types), guarded by ItemTypeInUseGuard.
*/
class ConfigSubscriber implements EventSubscriberInterface
{
public function __construct(
private InitiativeDescriptionItemRepository $descriptionItemRepository,
private InitiativeAllocationItemRepository $allocationItemRepository,
private InitiativeObjectiveRepository $objectiveRepository,
private TaskRepository $taskRepository,
private StakeholderRepository $stakeholderRepository,
private ItemTypeProvider $typeProvider,
) {
}
public static function getSubscribedEvents(): array
{
return [
ConfigEvents::CONFIG_ON_GENERATE => ['onConfigGenerate', 0],
ConfigEvents::CONFIG_PRE_SAVE => ['onConfigPreSave', 0],
];
}
@@ -50,50 +34,4 @@ class ConfigSubscriber implements EventSubscriberInterface
'parameters' => $event->getParametersFromConfig('ProgramBundle'),
]);
}
public function onConfigPreSave(ConfigEvent $event): void
{
$config = $event->getConfig(ConfigType::FORM_ALIAS);
if (!is_array($config)) {
return;
}
$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(),
];
foreach ($usage as $kind => $counts) {
$parameter = ItemTypeProvider::getParameter($kind);
if (!array_key_exists($parameter, $config)) {
continue;
}
$submitted = [];
foreach (ItemTypeProvider::normalize((array) $config[$parameter]) as $type) {
$submitted[$type['key']] = true;
}
$removedInUse = [];
foreach ($counts as $key => $count) {
if (!isset($submitted[$key])) {
$removedInUse[] = sprintf('%s (%d)', $this->typeProvider->getName($kind, $key) ?? $key, $count);
}
}
if ([] !== $removedInUse) {
$event->setError(
'mautic.program.config.type.in_use',
['%types%' => implode(', ', $removedInUse)],
ConfigType::FORM_ALIAS,
$parameter
);
}
}
}
}
+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';
}
}
@@ -1,84 +1,10 @@
{#
# Settings > Configuration > Program Settings: the general currency, then one section per kind of initiative
# item (insights, allocation, objectives, tasks), each with a pictogram. Adding and removing
# types, and the pictogram preview, are handled by Assets/js/program.js (delegated handlers on
# .program-config-types).
# Settings > Configuration > Program Settings: the plugin's general settings only — the currency,
# the stakeholder phone region, and the audience attribute toggles. The item type lists moved to
# their own page under Programs (ItemTypesController, Resources/views/ItemTypes/form.html.twig).
#}
{% macro type_row(type) %}
<div class="panel panel-default program-config-type">
<div class="panel-body">
{{ form_widget(type.children.key) }}
{{ form_errors(type) }}
{% if type.children.icon is defined %}
{% set icon = type.children.icon.vars.value %}
<div class="row mb-sm">
<div class="col-xs-1 text-center pt-lg">
<i class="initiative-type-icon-preview {{ icon }}" style="font-size: 28px;" aria-hidden="true"></i>
</div>
<div class="col-xs-5">{{ form_row(type.children.icon) }}</div>
</div>
{% endif %}
<table class="table table-condensed mb-0">
<thead>
<tr>
<th class="col-xs-2">{{ 'mautic.program.config.type.language'|trans }}</th>
<th class="col-xs-4">{{ 'mautic.program.config.type.name'|trans }}</th>
<th class="col-xs-6">{{ 'mautic.program.config.type.description'|trans }}</th>
</tr>
</thead>
<tbody>
{% for locale, name in type.children.names.children %}
<tr>
<td class="text-muted" title="{{ name.vars.attr['data-locale'] }}">
{{ name.vars.attr['data-language'] }}
{% if name.vars.required %}<span class="required">*</span>{% endif %}
</td>
<td>
{{ form_widget(name) }}
{{ form_errors(name) }}
</td>
<td>
{{ form_widget(type.children.descriptions.children[locale]) }}
{{ form_errors(type.children.descriptions.children[locale]) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="text-right mt-xs">
<button type="button" class="btn btn-ghost btn-sm program-config-type-remove">
<i class="ri-delete-bin-line"></i> {{ 'mautic.program.config.type.remove'|trans }}
</button>
</div>
</div>
</div>
{% endmacro %}
{# One editable list of types (one per kind of initiative item). #}
{% macro type_section(types, titleKey, helpKey) %}
{% import _self as cfg %}
<h4 class="fw-sb mt-lg mb-xs">{{ titleKey|trans }}</h4>
<p class="text-muted small">{{ helpKey|trans }}</p>
{{ form_errors(types) }}
<div class="program-config-types" data-prototype="{{ cfg.type_row(types.vars.prototype)|e('html_attr') }}">
<p class="text-muted program-config-types-empty{% if types|length > 0 %} hide{% endif %}">
{{ 'mautic.program.config.types.empty'|trans }}
</p>
<div class="program-config-types-list">
{% for type in types %}
{{ cfg.type_row(type) }}
{% endfor %}
</div>
<button type="button" class="btn btn-ghost program-config-type-add">
<i class="ri-add-line"></i> {{ 'mautic.program.config.type.add'|trans }}
</button>
</div>
{% do types.setRendered %}
{% endmacro %}
{% block _config_programconfig_widget %}
{% import _self as cfg %}
<div class="text-muted small pb-md">{{ 'mautic.program.config.description'|trans }}</div>
<h4 class="fw-sb mb-xs">{{ 'mautic.program.config.section.general'|trans }}</h4>
@@ -88,36 +14,6 @@
</div>
<p class="text-muted small">{{ 'mautic.program.config.currency.help'|trans }}</p>
{{ cfg.type_section(form.children.program_description_item_types,
'mautic.program.config.section.description_item_types',
'mautic.program.config.section.description_item_types.help') }}
{{ cfg.type_section(form.children.program_allocation_item_types,
'mautic.program.config.section.allocation_item_types',
'mautic.program.config.section.allocation_item_types.help') }}
{{ cfg.type_section(form.children.program_objective_types,
'mautic.program.config.section.objective_types',
'mautic.program.config.section.objective_types.help') }}
{{ cfg.type_section(form.children.program_task_types,
'mautic.program.config.section.task_types',
'mautic.program.config.section.task_types.help') }}
{{ cfg.type_section(form.children.program_stakeholder_types,
'mautic.program.config.section.stakeholder_types',
'mautic.program.config.section.stakeholder_types.help') }}
<h4 class="fw-sb mt-lg mb-xs">{{ 'mautic.program.config.section.audience_values'|trans }}</h4>
<p class="text-muted small">{{ 'mautic.program.config.section.audience_values.help'|trans }}</p>
{{ cfg.type_section(form.children.program_audience_decision_roles,
'mautic.program.config.section.audience_decision_roles',
'mautic.program.config.section.audience_decision_roles.help') }}
{{ cfg.type_section(form.children.program_audience_tones,
'mautic.program.config.section.audience_tones',
'mautic.program.config.section.audience_tones.help') }}
<h4 class="fw-sb mt-lg mb-xs">{{ 'mautic.program.config.section.audience_attributes'|trans }}</h4>
<p class="text-muted small">{{ 'mautic.program.config.section.audience_attributes.help'|trans }}</p>
<div class="program-config-audience-attributes">
+134
View File
@@ -0,0 +1,134 @@
{% extends '@MauticCore/Default/content.html.twig' %}
{% block mauticContent %}programItemTypes{% endblock %}
{% block headerTitle %}{{ 'mautic.program.item_type.header.index'|trans }}{% endblock %}
{#
# The type lists of the plugin's items, formerly the type sections of Settings > Configuration >
# Program Settings (see ItemTypesController): one section per kind — insights (description
# items), allocations, objectives, tasks, stakeholders, then the values offered for an
# audience's decision roles and tones.
#
# Adding and removing types, and the pictogram preview, are handled by Assets/js/program.js
# (delegated handlers on .program-config-types).
#}
{% macro type_row(type) %}
<div class="panel panel-default program-config-type">
<div class="panel-body">
{{ form_widget(type.children.key) }}
{{ form_errors(type) }}
{% if type.children.icon is defined %}
{% set icon = type.children.icon.vars.value %}
<div class="row mb-sm">
<div class="col-xs-1 text-center pt-lg">
<i class="initiative-type-icon-preview {{ icon }}" style="font-size: 28px;" aria-hidden="true"></i>
</div>
<div class="col-xs-5">{{ form_row(type.children.icon) }}</div>
</div>
{% endif %}
<table class="table table-condensed mb-0">
<thead>
<tr>
<th class="col-xs-2">{{ 'mautic.program.config.type.language'|trans }}</th>
<th class="col-xs-4">{{ 'mautic.program.config.type.name'|trans }}</th>
<th class="col-xs-6">{{ 'mautic.program.config.type.description'|trans }}</th>
</tr>
</thead>
<tbody>
{% for locale, name in type.children.names.children %}
<tr>
<td class="text-muted" title="{{ name.vars.attr['data-locale'] }}">
{{ name.vars.attr['data-language'] }}
{% if name.vars.required %}<span class="required">*</span>{% endif %}
</td>
<td>
{{ form_widget(name) }}
{{ form_errors(name) }}
</td>
<td>
{{ form_widget(type.children.descriptions.children[locale]) }}
{{ form_errors(type.children.descriptions.children[locale]) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="text-right mt-xs">
<button type="button" class="btn btn-ghost btn-sm program-config-type-remove">
<i class="ri-delete-bin-line"></i> {{ 'mautic.program.config.type.remove'|trans }}
</button>
</div>
</div>
</div>
{% endmacro %}
{% macro type_section(types, titleKey, helpKey) %}
{% import _self as cfg %}
<h4 class="fw-sb mt-lg mb-xs">{{ titleKey|trans }}</h4>
<p class="text-muted small">{{ helpKey|trans }}</p>
{{ form_errors(types) }}
<div class="program-config-types" data-prototype="{{ cfg.type_row(types.vars.prototype)|e('html_attr') }}">
<p class="text-muted program-config-types-empty{% if types|length > 0 %} hide{% endif %}">
{{ 'mautic.program.config.types.empty'|trans }}
</p>
<div class="program-config-types-list">
{% for type in types %}
{{ cfg.type_row(type) }}
{% endfor %}
</div>
<button type="button" class="btn btn-ghost program-config-type-add">
<i class="ri-add-line"></i> {{ 'mautic.program.config.type.add'|trans }}
</button>
</div>
{% do types.setRendered %}
{% endmacro %}
{% block content %}
{% import _self as cfg %}
{{ form_start(form) }}
{# The root form's errors: the in-use guard adds its message here. #}
{{ form_errors(form) }}
<div class="text-muted small pb-md">{{ 'mautic.program.item_type.page.description'|trans }}</div>
{% if not isWritable %}
<div class="alert alert-warning">{{ 'mautic.program.item_type.not_writable'|trans }}</div>
{% endif %}
{{ cfg.type_section(form.children.program_description_item_types,
'mautic.program.config.section.description_item_types',
'mautic.program.config.section.description_item_types.help') }}
{{ cfg.type_section(form.children.program_allocation_item_types,
'mautic.program.config.section.allocation_item_types',
'mautic.program.config.section.allocation_item_types.help') }}
{{ cfg.type_section(form.children.program_objective_types,
'mautic.program.config.section.objective_types',
'mautic.program.config.section.objective_types.help') }}
{{ cfg.type_section(form.children.program_task_types,
'mautic.program.config.section.task_types',
'mautic.program.config.section.task_types.help') }}
{{ cfg.type_section(form.children.program_stakeholder_types,
'mautic.program.config.section.stakeholder_types',
'mautic.program.config.section.stakeholder_types.help') }}
<h4 class="fw-sb mt-lg mb-xs">{{ 'mautic.program.config.section.audience_values'|trans }}</h4>
<p class="text-muted small">{{ 'mautic.program.config.section.audience_values.help'|trans }}</p>
{{ cfg.type_section(form.children.program_audience_decision_roles,
'mautic.program.config.section.audience_decision_roles',
'mautic.program.config.section.audience_decision_roles.help') }}
{{ cfg.type_section(form.children.program_audience_tones,
'mautic.program.config.section.audience_tones',
'mautic.program.config.section.audience_tones.help') }}
{{ form_row(form.children.buttons) }}
{# render_rest is false, so the hidden CSRF token must be rendered explicitly. #}
{{ form_widget(form.children._token) }}
{{ form_end(form, {'render_rest': false}) }}
{% endblock %}
+6 -2
View File
@@ -8,8 +8,10 @@ use Mautic\CoreBundle\Security\Permissions\AbstractPermissions;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Permission keys: program:initiatives:*, program:tasks:* and program:stakeholders:* (view/edit/delete/publish own and
* other, create, full), and program:categories:* (managing the "initiative" category type).
* Permission keys: program:initiatives:*, program:tasks:*, program:stakeholders:* and
* program:audiences:* (view/edit/delete/publish own and other, create, full), program:itemtypes:*
* (the Item types page, Programs > Item types), and program:categories:* (managing the
* "initiative" category type).
*
* Shown under Settings > Roles. Core discovers this class from Security/Permissions/.
*/
@@ -27,6 +29,7 @@ class ProgramPermissions extends AbstractPermissions
$this->addExtendedPermissions('tasks');
$this->addExtendedPermissions('stakeholders');
$this->addExtendedPermissions('audiences');
$this->addStandardPermissions('itemtypes');
}
public function getName(): string
@@ -45,5 +48,6 @@ class ProgramPermissions extends AbstractPermissions
$this->addExtendedFormFields('program', 'tasks', $builder, $data);
$this->addExtendedFormFields('program', 'stakeholders', $builder, $data);
$this->addExtendedFormFields('program', 'audiences', $builder, $data);
$this->addStandardFormFields('program', 'itemtypes', $builder, $data);
}
}
+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'],
+1
View File
@@ -0,0 +1 @@
mautic.program.item_type.saved="Item types saved."
+10 -3
View File
@@ -1,6 +1,7 @@
mautic.plugin.program.name="Program"
mautic.program.menu.root="Programs"
mautic.program.menu.index="Initiatives"
mautic.program.menu.item_types="Item types"
mautic.program.tab.details="Details"
mautic.program.tab.description="Insights"
@@ -169,6 +170,12 @@ mautic.program.permissions.initiatives="Initiatives - User has access to"
mautic.program.permissions.tasks="Tasks - User has access to"
mautic.program.permissions.stakeholders="Stakeholders - User has access to"
mautic.program.permissions.audiences="Audiences - User has access to"
mautic.program.permissions.itemtypes="Item types - User has access to"
; The Item types page (Programs > Item types).
mautic.program.item_type.header.index="Item types"
mautic.program.item_type.page.description="The types of the plugin's items: insights, allocations, objectives, tasks, stakeholders, and the values offered for an audience's decision roles and tones. Give each type a name and a description in each language, and a pictogram; the default language is required. Users see their own language, or the default language when it's empty."
mautic.program.item_type.not_writable="The configuration file (config/local.php) is not writable: the type lists can be changed, but not saved."
; Tasks (Programs > Tasks). Translation base mautic.program.task.
mautic.program.task.menu.index="Tasks"
@@ -253,7 +260,7 @@ mautic.program.objective.add="Add objective"
mautic.program.objective.remove="Remove objective"
mautic.program.objective.drag="Drag to reorder"
mautic.program.objective.empty="No objectives yet."
mautic.program.objective.no_types="No objective types are set up yet. An administrator can add them in Settings > Configuration > Program Settings."
mautic.program.objective.no_types="No objective types are set up yet. They can be added in Programs > Item types."
mautic.program.objective.progress="%achieved% of %total% achieved"
mautic.program.objective.achieved="Achieved"
mautic.program.objective.not_achieved="Not achieved"
@@ -274,7 +281,7 @@ mautic.program.description_item.add="Add description item"
mautic.program.description_item.remove="Remove description item"
mautic.program.description_item.drag="Drag to reorder"
mautic.program.description_item.empty="No description items yet."
mautic.program.description_item.no_types="No insights types are set up yet. An administrator can add them in Settings > Configuration > Program Settings."
mautic.program.description_item.no_types="No insights types are set up yet. They can be added in Programs > Item types."
mautic.program.description_item.type.unknown="Unknown type (%key%)"
; Settings > Configuration > Plan. Core builds the tab title key from the form alias.
@@ -300,7 +307,7 @@ mautic.program.allocation_item.add="Add allocation item"
mautic.program.allocation_item.remove="Remove allocation item"
mautic.program.allocation_item.drag="Drag to reorder"
mautic.program.allocation_item.empty="No allocation items yet."
mautic.program.allocation_item.no_types="No allocation item types are set up yet. An administrator can add them in Settings > Configuration > Program Settings."
mautic.program.allocation_item.no_types="No allocation item types are set up yet. They can be added in Programs > Item types."
mautic.program.allocation.total="Total"
; Plan page header: total costs of the allocation items, in the general currency.
+6 -5
View File
@@ -16,9 +16,9 @@ This repository holds only the plugin source. The bundle files are at the reposi
3. In Mautic, go to **Settings > Plugins**, open **Program** and publish it.
Initiatives are listed under **Programs > Initiatives** in the main menu (URL `/s/programs`), tasks under **Programs > Tasks** (URL `/s/program-tasks`), the stakeholder directory under **Programs > Stakeholders** (URL `/s/program-stakeholders`), and the audience directory under **Programs > Audiences** (URL `/s/program-audiences`). **Programs > UTM Taxonomies** (URL `/s/program-utm-taxonomies`) is a placeholder for a coming feature. Users who aren't administrators need a role with the **Program Permissions** set in **Settings > Roles**.
Initiatives are listed under **Programs > Initiatives** in the main menu (URL `/s/programs`), tasks under **Programs > Tasks** (URL `/s/program-tasks`), the stakeholder directory under **Programs > Stakeholders** (URL `/s/program-stakeholders`), and the audience directory under **Programs > Audiences** (URL `/s/program-audiences`). The item type lists are edited under **Programs > Item types** (URL `/s/program-item-types`), below **UTM Taxonomies** (URL `/s/program-utm-taxonomies`, a placeholder for a coming feature). Users who aren't administrators need a role with the **Program Permissions** set in **Settings > Roles**.
Before using the items of an initiative's **Insights**, **Objectives**, **Allocations** and **Tasks** tabs, an administrator sets up their types in **Settings > Configuration > Program Settings**.
Before using the items of an initiative's **Insights**, **Objectives**, **Allocations** and **Tasks** tabs, set up their types under **Programs > Item types** (`program:itemtypes:view` to see the page, `program:itemtypes:edit` to save it).
## Development
@@ -68,6 +68,7 @@ The plugin uses the IntegrationsBundle conventions:
- `Resources/views/Initiative/_task_table.html.twig`: the initiative's tasks in the Tasks tab. It has the harmonized tab columns (pictogram, Type, Name with kind badge for milestones and phases, Description, Start date, End date, Status — no ID), one row per task, no tree: a phase's or milestone's badge marks it in the name column. On the detail page it has an **Add task** button, links to each task and the filter/sort of the other tabs. On the initiative 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 (**Programs > Tasks**). `new?initiative=ID` preselects the initiative. After Save or Cancel, the user goes back to where the form was opened from. Opened from **Programs > Tasks**, that's the task list. Opened from an initiative's Tasks tab, whose links carry `returnTo=initiative`, that's the initiative (its new initiative, 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.
- `Controller/UtmTaxonomyController.php` and `Resources/views/UtmTaxonomy/`: the placeholder page for the coming UTM Taxonomies feature.
- `Controller/ItemTypesController.php` and `Resources/views/ItemTypes/form.html.twig`: the Item types page (**Programs > Item types**), below UTM Taxonomies in the menu. The type lists that used to be sections of **Settings > Configuration > Program Settings** (insights, allocation, objective, task, stakeholder types and the audience decision roles and tones) are edited here. `Form/Type/ItemTypesType.php` builds the lists, `Service/ItemTypeInUseGuard.php` refuses to remove a type that items still use, and the page saves through core's `Configurator` exactly like the Settings pages do: merge into `config/local.php`, write, refresh the config cache. **Settings > Configuration > Program Settings** keeps only the plugin's general settings: the currency, the stakeholder phone region and the audience attribute toggles.
- `Assets/js/program.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.programOnLoad()`.
The initiative's tab panes deliberately have no Bootstrap `fade` class. Core reopens the last tab used on a page (`12.tabs.js`), and the plugin opens the tab with an error after a failed save. With `fade`, those two `tab('show')` calls overlapped within the 150 ms transition and left two panes visible at once, so the Tasks tab also showed the objectives.
@@ -137,15 +138,15 @@ Behaviour to know about:
- An **objective** (`Entity/InitiativeObjective.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 initiative'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* below.
- Description items, allocation items and objectives are edited inside the initiative form, like objectives: add, remove, drag to reorder. They're saved and deleted with the initiative. 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 > Program Settings**, in several 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.
- Each kind's types are set up on the **Item types** page (**Programs > Item types**), in several 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 (none for the audience decision roles and tones). 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 `program_description_item_types`, `program_allocation_item_types`, `program_objective_types`, `program_task_types` and `program_stakeholder_types` parameters. Read them with `Service/ItemTypeProvider.php`, passing the kind (`description`, `allocation`, `objective`, `task` or `stakeholder`). In templates, use the Twig functions `program_item_type_name(kind, key)`, `program_item_type_description(kind, key)` and `program_item_type_icon(kind, key)`, plus `program_currency()` and `program_money(amount)` (`Twig/ProgramExtension.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 initiative form and the task form it appears next to the type dropdown when a type is chosen.
- **The four item tabs of an initiative's detail page are harmonized** (`Resources/views/Initiative/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 initiative'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.programInitTabTable` in `Assets/js/program.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 Insights tab, with a *Read more* / *Show less* toggle (`_description_read_more.html.twig`, `Mautic.programInitReadMore`). 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`).
- A type that items use can't be removed: the lists aren't saved, and the error lists the types and how many items use them (`Service/ItemTypeInUseGuard.php`, called by `ItemTypesController` before saving the page).
- On the initiative 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.
- Files: `Form/Type/ConfigType.php`, `ItemTypeConfigType.php`, `InitiativeDescriptionItemType.php`, `InitiativeAllocationItemType.php` and `Resources/views/FormTheme/Config/_config_programconfig_widget.html.twig`. Adding and removing types is handled in `Assets/js/program.js`.
- Files: `Form/Type/ItemTypesType.php`, `ItemTypeConfigType.php`, `InitiativeDescriptionItemType.php`, `InitiativeAllocationItemType.php`, `Controller/ItemTypesController.php` and `Resources/views/ItemTypes/form.html.twig` (the page), and `Form/Type/ConfigType.php` with `Resources/views/FormTheme/Config/_config_programconfig_widget.html.twig` (the general settings that stayed in **Settings > Configuration**). Adding and removing types is handled in `Assets/js/program.js`.
### Cost totals