From 8c8d7a6f95f0b0e1f4c9ad915be1cb64ed79b256 Mon Sep 17 00:00:00 2001 From: Alexandre Gain <270117159+alexandregain-xprl@users.noreply.github.com> Date: Sat, 7 Nov 2026 22:08:06 +0100 Subject: [PATCH] improved Plan / Allocation items --- Assets/js/plan.js | 4 ++-- Config/config.php | 2 +- Form/Type/ConfigType.php | 4 ++-- Form/Type/ItemTypeConfigType.php | 8 ++++---- Form/Type/PlanAllocationItemType.php | 11 ++++++++--- .../Config/_config_planconfig_widget.html.twig | 6 +++--- Resources/views/Plan/details.html.twig | 7 ++++++- Resources/views/Plan/form.html.twig | 18 +++++++++++++----- Service/ItemTypeProvider.php | 4 ++-- Service/Pictograms.php | 6 +++--- Translations/en_US/messages.ini | 3 ++- readme.md | 6 +++--- 12 files changed, 49 insertions(+), 30 deletions(-) diff --git a/Assets/js/plan.js b/Assets/js/plan.js index b0f3db8..4ea7592 100644 --- a/Assets/js/plan.js +++ b/Assets/js/plan.js @@ -160,7 +160,7 @@ Mautic.planInitCollection = function ($editor) { }); // Typed items (description, allocation): show the selected type's description under the dropdown, and - // for description items its pictogram next to it. + // its pictogram next to it. $editor.on('change', 'select.plan-item-type', function () { var $option = mQuery(this).find('option:selected'); var $row = mQuery(this).closest('.plan-collection-row'); @@ -201,7 +201,7 @@ Mautic.planInitCollection = function ($editor) { $row.find('input[type="text"]').first().trigger('focus'); }); - // Pictogram of a description item type: preview the chosen icon. + // Pictogram of an item type (description, allocation): preview the chosen icon. mQuery(document).on('change', '.plan-config-types select.plan-type-icon-select', function () { var icon = mQuery(this).find('option:selected').attr('data-icon') || ''; mQuery(this).closest('.plan-config-type').find('.plan-type-icon-preview').first().attr('class', 'plan-type-icon-preview ' + icon); diff --git a/Config/config.php b/Config/config.php index df7b130..8d07853 100644 --- a/Config/config.php +++ b/Config/config.php @@ -90,7 +90,7 @@ return [ // Item types, edited in Settings > Configuration > Plan Settings. Read them through ItemTypeProvider. // Each is a list of ['key' => …, 'names' => [locale => …], 'descriptions' => [locale => …]], - // plus 'icon' => a Remix Icon class for description item types. + // plus 'icon' => a Remix Icon class for description and allocation item types. 'plan_description_item_types' => [], 'plan_allocation_item_types' => [], ], diff --git a/Form/Type/ConfigType.php b/Form/Type/ConfigType.php index 1664ef6..d5b0a37 100644 --- a/Form/Type/ConfigType.php +++ b/Form/Type/ConfigType.php @@ -16,7 +16,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; /** * The "Plan Settings" tab of Settings > Configuration. Each child is a local.php parameter: * - plan_currency: the currency of every amount in the plugin (general setting); - * - one list of item types per kind (description items, with a pictogram; allocation items). + * - one list of item types per kind (description items, allocation items), each with a pictogram. * * @extends AbstractType> */ @@ -46,7 +46,7 @@ class ConfigType extends AbstractType $builder->add($parameter, CollectionType::class, [ 'label' => false, 'entry_type' => ItemTypeConfigType::class, - 'entry_options' => ['label' => false, 'with_icon' => ItemTypeProvider::KIND_DESCRIPTION === $kind], + 'entry_options' => ['label' => false, 'with_icon' => true], 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, diff --git a/Form/Type/ItemTypeConfigType.php b/Form/Type/ItemTypeConfigType.php index d4d1a0a..3faf6ae 100644 --- a/Form/Type/ItemTypeConfigType.php +++ b/Form/Type/ItemTypeConfigType.php @@ -21,7 +21,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; /** * One item type (description or allocation) in Settings > Configuration > Plan Settings: a name and a - * description per language, and for description item types a pictogram. + * 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 * type doesn't affect the items that use it. @@ -70,7 +70,7 @@ class ItemTypeConfigType extends AbstractType $builder->add($names); $builder->add($descriptions); - // Description item types have a pictogram; the preview next to the dropdown is updated by plan.js. + // Pictogram; the preview next to the dropdown is updated by plan.js. if ($options['with_icon']) { $builder->add('icon', ChoiceType::class, [ 'label' => 'mautic.plan.config.type.icon', @@ -96,8 +96,8 @@ class ItemTypeConfigType extends AbstractType public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefaults([ - // True for description item types: adds the pictogram field. - 'with_icon' => false, + // Adds the pictogram field; both kinds of item types have one. + 'with_icon' => true, ]); $resolver->setAllowedTypes('with_icon', 'bool'); } diff --git a/Form/Type/PlanAllocationItemType.php b/Form/Type/PlanAllocationItemType.php index bcdeb0b..a901bab 100644 --- a/Form/Type/PlanAllocationItemType.php +++ b/Form/Type/PlanAllocationItemType.php @@ -18,8 +18,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver; /** * One row of the allocation items collection in PlanType: type, name, description, planned cost and - * real cost (both in the general currency). Works like PlanDescriptionItemType (type description shown under the - * dropdown, hidden position kept in display order by Assets/js/plan.js). + * real cost (both in the general currency). Works like PlanDescriptionItemType (type description shown + * under the dropdown and its pictogram next to it, hidden position kept in display order by + * Assets/js/plan.js). * * @extends AbstractType */ @@ -40,7 +41,11 @@ class PlanAllocationItemType extends AbstractType 'label_attr' => ['class' => 'control-label'], 'attr' => ['class' => 'form-control plan-item-type'], 'choices' => $this->typeProvider->getChoices($kind), - 'choice_attr' => fn (?string $key): array => ['data-description' => (string) $this->typeProvider->getDescription($kind, $key)], + // The type's description and pictogram, shown next to the dropdown by plan.js. + 'choice_attr' => fn (?string $key): array => [ + 'data-description' => (string) $this->typeProvider->getDescription($kind, $key), + 'data-icon' => (string) $this->typeProvider->getIcon($kind, $key), + ], 'placeholder' => 'mautic.core.form.chooseone', 'required' => true, ]); diff --git a/Resources/views/FormTheme/Config/_config_planconfig_widget.html.twig b/Resources/views/FormTheme/Config/_config_planconfig_widget.html.twig index b92a275..f95f494 100644 --- a/Resources/views/FormTheme/Config/_config_planconfig_widget.html.twig +++ b/Resources/views/FormTheme/Config/_config_planconfig_widget.html.twig @@ -1,7 +1,7 @@ {# - # Settings > Configuration > Plan Settings: the general currency, the description item types (with a - # pictogram) and the allocation item types. Adding and removing types, and the pictogram preview, are - # handled by Assets/js/plan.js (delegated handlers on .plan-config-types). + # Settings > Configuration > Plan Settings: the general currency, the description item types and the + # allocation item types, each with a pictogram. Adding and removing types, and the pictogram preview, + # are handled by Assets/js/plan.js (delegated handlers on .plan-config-types). #} {% macro type_row(type) %} diff --git a/Resources/views/Plan/details.html.twig b/Resources/views/Plan/details.html.twig index 41bbe12..c4447c8 100644 --- a/Resources/views/Plan/details.html.twig +++ b/Resources/views/Plan/details.html.twig @@ -235,6 +235,7 @@ + @@ -246,7 +247,11 @@ {% for allocationItem in allocationItems %} {% set typeName = plan_item_type_name('allocation', allocationItem.type) %} {% set typeDescription = plan_item_type_description('allocation', allocationItem.type) %} + {% set typeIcon = plan_item_type_icon('allocation', allocationItem.type) %} + {{ typeName ?? 'mautic.plan.description_item.type.unknown'|trans({'%key%': allocationItem.type}) }} @@ -263,7 +268,7 @@ - + diff --git a/Resources/views/Plan/form.html.twig b/Resources/views/Plan/form.html.twig index c1de2b7..45446b2 100644 --- a/Resources/views/Plan/form.html.twig +++ b/Resources/views/Plan/form.html.twig @@ -67,12 +67,20 @@ {% macro allocation_item_row(item) %} {{ _self.row_start('mautic.plan.allocation_item.drag') }}
-
- {{ form_row(item.type) }} - {# Filled with the selected type's description by plan.js. #} -

{{ plan_item_type_description('allocation', item.type.vars.value) }}

+ {# The selected type's pictogram; updated by plan.js when the type changes. #} +
+ +
+
+
+
+ {{ form_row(item.type) }} + {# Filled with the selected type's description by plan.js. #} +

{{ plan_item_type_description('allocation', item.type.vars.value) }}

+
+
{{ form_row(item.name) }}
+
-
{{ form_row(item.name) }}
{{ form_row(item.description) }}
diff --git a/Service/ItemTypeProvider.php b/Service/ItemTypeProvider.php index 4e766c3..18435c0 100644 --- a/Service/ItemTypeProvider.php +++ b/Service/ItemTypeProvider.php @@ -104,7 +104,7 @@ class ItemTypeProvider /** * Pictogram of a type (a Remix Icon class such as "ri-lightbulb-line"), or null when it has none or - * the key isn't a configured type. Only description item types have pictograms. + * the key isn't a configured type. */ public function getIcon(string $kind, ?string $key): ?string { @@ -154,7 +154,7 @@ class ItemTypeProvider 'descriptions' => self::texts($type['descriptions'] ?? []), ]; - // Pictogram (description item types only); kept only when it's one of the offered icons. + // Pictogram; kept only when it's one of the offered icons. if (isset($type['icon']) && is_string($type['icon']) && Pictograms::isValid($type['icon'])) { $entry['icon'] = $type['icon']; } diff --git a/Service/Pictograms.php b/Service/Pictograms.php index d38c38d..170f9df 100644 --- a/Service/Pictograms.php +++ b/Service/Pictograms.php @@ -5,9 +5,9 @@ declare(strict_types=1); namespace MauticPlugin\PlanBundle\Service; /** - * Pictograms an administrator can give to a description item type (Settings > Configuration > Plan - * Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*" classes); each one was - * checked against Mautic 7's icon stylesheet. + * Pictograms an administrator can give to an item type — description or allocation (Settings > + * Configuration > Plan Settings). They are icons of the Remix Icon set that Mautic ships ("ri-*" + * classes); each one was checked against Mautic 7's icon stylesheet. */ final class Pictograms { diff --git a/Translations/en_US/messages.ini b/Translations/en_US/messages.ini index fd5d64e..fe8e253 100644 --- a/Translations/en_US/messages.ini +++ b/Translations/en_US/messages.ini @@ -118,6 +118,7 @@ mautic.plan.config.type.description="Description" ; Allocation items (the plan's Allocation tab). mautic.plan.allocation_item.field.type="Type" +mautic.plan.allocation_item.field.pictogram="Pictogram" mautic.plan.allocation_item.field.name="Name" mautic.plan.allocation_item.field.description="Description" mautic.plan.allocation_item.field.planned_cost="Planned cost" @@ -140,7 +141,7 @@ mautic.plan.task.subtask_of="Sub-task of %parent%" mautic.plan.task.subtasks="Number of sub-tasks" mautic.plan.config.section.allocation_item_types="Allocation item types" -mautic.plan.config.section.allocation_item_types.help="The types offered for the cost lines of a plan's Allocation tab, in this order. Give each type a name and a description in each language; the default language is required. Users see their own language, or the default language when it's empty." +mautic.plan.config.section.allocation_item_types.help="The types offered for the cost lines of a plan's Allocation tab, in this order. 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.plan.description_item.field.pictogram="Pictogram" mautic.plan.config.section.general="General" diff --git a/readme.md b/readme.md index b0f0889..443db0a 100644 --- a/readme.md +++ b/readme.md @@ -120,11 +120,11 @@ Behaviour to know about: ### Typed items: description items and allocation items - 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, name (optional), description, planned cost and real cost. Costs are `DECIMAL(12,2)`, in the general currency. +- 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. Users see their own language, or the default language when theirs is empty. The order of the types is the order of the dropdown. +- 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`). -- **Description item types have 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. Allocation item types have no pictogram. +- **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. - 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.
{{ 'mautic.plan.allocation_item.field.pictogram'|trans }} {{ 'mautic.plan.allocation_item.field.type'|trans }} {{ 'mautic.plan.allocation_item.field.name'|trans }} {{ 'mautic.plan.allocation_item.field.description'|trans }}
+ {% if typeIcon %}{% endif %} +
{{ 'mautic.plan.allocation.total'|trans }}{{ 'mautic.plan.allocation.total'|trans }} {% if allocationTotals.planned is not null %}{{ plan_money(allocationTotals.planned) }} {{ plan_currency() }}{% endif %}