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

+16 -1
View File
@@ -4,19 +4,23 @@ declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Model\StakeholderModel;
use MauticPlugin\PlanBundle\Service\CurrencyProvider;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
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 Symfony\Component\Form\FormBuilderInterface;
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, allocation items), each with a pictogram.
* - plan_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), each with
* a pictogram.
*
* @extends AbstractType<array<string, mixed>>
*/
@@ -42,6 +46,17 @@ class ConfigType extends AbstractType
'empty_data' => CurrencyProvider::DEFAULT_CURRENCY,
]);
// Default region for stakeholder phone numbers typed without a country prefix (ISO 3166-1
// alpha-2, e.g. FR). Read by StakeholderModel on save.
$builder->add(StakeholderModel::PHONE_REGION_PARAMETER, TextType::class, [
'label' => 'mautic.plan.config.stakeholder_phone_region',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.plan.config.stakeholder_phone_region.tooltip', 'maxlength' => 2],
'required' => true,
'constraints' => [new NotBlank()],
'empty_data' => StakeholderModel::DEFAULT_PHONE_REGION,
]);
foreach (ItemTypeProvider::PARAMETERS as $kind => $parameter) {
$builder->add($parameter, CollectionType::class, [
'label' => false,
+39 -2
View File
@@ -5,30 +5,67 @@ declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Entity\PlanObjective;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* One row of the objectives collection in PlanType. The position field is hidden and kept in
* display order by Assets/js/plan.js.
* One row of the objectives collection in PlanType: type, title, priority, description and the achieved
* flag. 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<PlanObjective>
*/
class PlanObjectiveType extends AbstractType
{
public function __construct(
private ItemTypeProvider $typeProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$kind = ItemTypeProvider::KIND_OBJECTIVE;
$builder->add('type', ChoiceType::class, [
'label' => 'mautic.plan.objective.field.type',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control plan-item-type'],
'choices' => $this->typeProvider->getChoices($kind),
// 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,
]);
$builder->add('title', TextType::class, [
'label' => 'mautic.plan.objective.field.title',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 255],
]);
$builder->add('priority', IntegerType::class, [
'label' => 'mautic.plan.objective.field.priority',
'label_attr' => ['class' => 'control-label'],
'invalid_message' => 'mautic.plan.objective.priority.range',
'attr' => [
'class' => 'form-control',
'min' => PlanObjective::PRIORITY_MIN,
'max' => PlanObjective::PRIORITY_MAX,
'step' => 1,
],
]);
$builder->add('description', TextareaType::class, [
'label' => 'mautic.plan.objective.field.description',
'label_attr' => ['class' => 'control-label'],
+65
View File
@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use MauticPlugin\PlanBundle\Entity\PlanStakeholder;
use MauticPlugin\PlanBundle\Entity\Stakeholder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* One row of the stakeholders collection in PlanType: a stakeholder of the global directory (only the
* active ones are offered) and the stakeholder's role in this plan. The position field is hidden and
* kept in display order by Assets/js/plan.js.
*
* @extends AbstractType<PlanStakeholder>
*/
class PlanStakeholderType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('stakeholder', EntityType::class, [
'label' => 'mautic.plan.stakeholder.field.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Stakeholder::class,
'choice_label' => 'name',
'query_builder' => fn (EntityRepository $er) => $er->createQueryBuilder('s')
->orderBy('s.name', 'ASC')
->andWhere('s.isPublished = :published')
->setParameter('published', true),
'placeholder' => 'mautic.core.form.chooseone',
'required' => true,
]);
$builder->add('roleInPlan', TextType::class, [
'label' => 'mautic.plan.stakeholder.field.role_in_plan',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 191],
'required' => false,
]);
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => PlanStakeholder::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_plan_stakeholder';
}
}
+30 -1
View File
@@ -16,6 +16,8 @@ use Mautic\UserBundle\Form\Type\UserListType;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\PlanStatus;
use MauticPlugin\PlanBundle\Service\CurrencyProvider;
use MauticPlugin\PlanBundle\Form\Type\TargetType as PlanTargetType;
use MauticPlugin\PlanBundle\Form\Type\PlanStakeholderType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
@@ -63,7 +65,7 @@ class PlanType extends AbstractType
'required' => false,
]);
// The Allocation tab's cost lines, in the general currency.
// The Allocations tab's cost lines, in the general currency.
$builder->add('allocationItems', CollectionType::class, [
'label' => 'mautic.plan.field.allocation_items',
'entry_type' => PlanAllocationItemType::class,
@@ -76,6 +78,33 @@ class PlanType extends AbstractType
'required' => false,
]);
// The Targets tab's audiences. by_reference false: Symfony calls Plan::addTarget()/removeTarget().
$builder->add('targets', CollectionType::class, [
'label' => 'mautic.plan.field.targets',
'entry_type' => PlanTargetType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__target__',
'required' => false,
]);
// The Stakeholders tab's links to the global directory. by_reference false: Symfony calls
// Plan::addStakeholder()/removeStakeholder().
$builder->add('stakeholders', CollectionType::class, [
'label' => 'mautic.plan.field.stakeholders',
'entry_type' => PlanStakeholderType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__stakeholder__',
'required' => false,
]);
$builder->add('version', IntegerType::class, [
'label' => 'mautic.plan.field.version',
'label_attr' => ['class' => 'control-label'],
+98
View File
@@ -0,0 +1,98 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Entity\Stakeholder;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use Mautic\CoreBundle\Form\Type\FormButtonsType;
use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\TelType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* The create and edit form of a stakeholder of the global directory (Planning > Stakeholders).
*
* @extends AbstractType<Stakeholder>
*/
class StakeholderType extends AbstractType
{
public function __construct(
private ItemTypeProvider $typeProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$kind = ItemTypeProvider::KIND_STAKEHOLDER;
$builder->add('name', TextType::class, [
'label' => 'mautic.plan.stakeholder.field.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 191],
]);
$builder->add('email', EmailType::class, [
'label' => 'mautic.plan.stakeholder.field.email',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 191],
'required' => false,
]);
$builder->add('phone', TelType::class, [
'label' => 'mautic.plan.stakeholder.field.phone',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 50],
'required' => false,
]);
$builder->add('role', TextType::class, [
'label' => 'mautic.plan.stakeholder.field.role',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 191],
'required' => false,
]);
$builder->add('type', ChoiceType::class, [
'label' => 'mautic.plan.stakeholder.field.type',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control plan-item-type'],
'choices' => $this->typeProvider->getChoices($kind),
// 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' => false,
]);
$builder->add('isPublished', YesNoButtonGroupType::class, [
'label' => 'mautic.plan.stakeholder.field.active',
]);
$builder->add('buttons', FormButtonsType::class);
if (!empty($options['action'])) {
$builder->setAction($options['action']);
}
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Stakeholder::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_stakeholder';
}
}
+126
View File
@@ -0,0 +1,126 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Mautic\StageBundle\Entity\Stage;
use MauticPlugin\PlanBundle\Entity\Target;
use MauticPlugin\PlanBundle\Entity\TargetPriority;
use MauticPlugin\PlanBundle\Entity\TargetType as TargetTypeEnum;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* One row of the targets collection in PlanType: name, type, priority, stages, estimated size, the
* three texts, the preferred channels, and the hidden position kept in display order by
* Assets/js/plan.js.
*
* @extends AbstractType<Target>
*/
class TargetType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('name', TextType::class, [
'label' => 'mautic.plan.target.field.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 191],
]);
// Dropdown in the order of the TargetType cases.
$builder->add('targetType', EnumType::class, [
'label' => 'mautic.plan.target.field.type',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => TargetTypeEnum::class,
'choice_label' => fn (TargetTypeEnum $type): string => $type->getLabelKey(),
]);
// Dropdown in the order of the TargetPriority cases.
$builder->add('priority', EnumType::class, [
'label' => 'mautic.plan.target.field.priority',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => TargetPriority::class,
'choice_label' => fn (TargetPriority $priority): string => $priority->getLabelKey(),
]);
// The Mautic stages this target maps to; any number, or none.
$builder->add('stages', EntityType::class, [
'label' => 'mautic.plan.target.field.stages',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Stage::class,
'choice_label' => 'name',
'query_builder' => fn (EntityRepository $er) => $er->createQueryBuilder('s')->orderBy('s.name', 'ASC'),
'multiple' => true,
'expanded' => false,
'required' => false,
]);
$builder->add('estimatedSize', IntegerType::class, [
'label' => 'mautic.plan.target.field.estimated_size',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'min' => 0, 'step' => 1],
'required' => false,
]);
$builder->add('profileCriteria', TextareaType::class, [
'label' => 'mautic.plan.target.field.profile_criteria',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 2],
'required' => false,
]);
$builder->add('painPoints', TextareaType::class, [
'label' => 'mautic.plan.target.field.pain_points',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 2],
'required' => false,
]);
$builder->add('valueProposition', TextareaType::class, [
'label' => 'mautic.plan.target.field.value_proposition',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 2],
'required' => false,
]);
// One checkbox per channel, in the order of Target::CHANNELS. The choice values are the channel
// keys; the labels are translated by the trans_choices mechanism of the choice_label.
$builder->add('preferredChannels', ChoiceType::class, [
'label' => 'mautic.plan.target.field.preferred_channels',
'label_attr' => ['class' => 'control-label'],
'choices' => array_flip(Target::CHANNELS),
'expanded' => true,
'multiple' => true,
'required' => false,
]);
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Target::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_target';
}
}
+23
View File
@@ -11,8 +11,10 @@ use Mautic\CoreBundle\Form\Type\FormButtonsType;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskStatus;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -24,6 +26,11 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/
class TaskType extends AbstractType
{
public function __construct(
private ItemTypeProvider $typeProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventSubscriber(new CleanFormSubscriber(['description' => 'strict_html']));
@@ -32,6 +39,22 @@ class TaskType extends AbstractType
$task = $options['data'];
$plan = $task->getPlan();
$kind = ItemTypeProvider::KIND_TASK;
$builder->add('type', ChoiceType::class, [
'label' => 'mautic.plan.task.field.type',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control plan-item-type'],
'choices' => $this->typeProvider->getChoices($kind),
// 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,
]);
$builder->add('name', TextType::class, [
'label' => 'mautic.plan.task.field.name',
'label_attr' => ['class' => 'control-label'],