first delivery

This commit is contained in:
Alexandre Gain committed 2026-11-07 19:31:49 +01:00
1 parent 793fbc0c91
commit f6684f3b2e
65 files changed
+5828

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
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\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, with a pictogram; allocation items).
*
* @extends AbstractType<array<string, mixed>>
*/
class ConfigType extends AbstractType
{
public const FORM_ALIAS = 'planconfig';
public function __construct(
private CurrencyProvider $currencyProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add(CurrencyProvider::CONFIG_PARAMETER, ChoiceType::class, [
'label' => 'mautic.plan.config.currency',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'tooltip' => 'mautic.plan.config.currency.tooltip'],
'choices' => $this->currencyProvider->getChoices(),
'placeholder' => false,
'required' => true,
'constraints' => [new NotBlank()],
'empty_data' => CurrencyProvider::DEFAULT_CURRENCY,
]);
foreach (ItemTypeProvider::PARAMETERS as $kind => $parameter) {
$builder->add($parameter, CollectionType::class, [
'label' => false,
'entry_type' => ItemTypeConfigType::class,
'entry_options' => ['label' => false, 'with_icon' => ItemTypeProvider::KIND_DESCRIPTION === $kind],
'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 : []),
));
}
}
public function getBlockPrefix(): string
{
return self::FORM_ALIAS;
}
}
+109
View File
@@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use MauticPlugin\PlanBundle\Service\Pictograms;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
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.
*
* 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.
*
* @extends AbstractType<array<string, mixed>>
*/
class ItemTypeConfigType extends AbstractType
{
public function __construct(
private ItemTypeProvider $typeProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$default = $this->typeProvider->getDefaultLocale();
$builder->add('key', HiddenType::class, [
'attr' => ['class' => 'plan-type-key'],
]);
$names = $builder->create('names', FormType::class, ['label' => false]);
$descriptions = $builder->create('descriptions', FormType::class, ['label' => false]);
foreach ($this->typeProvider->getLanguages() as $locale => $language) {
$isDefault = $locale === $default;
$names->add($locale, TextType::class, [
'label' => 'mautic.plan.config.type.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 191, 'data-locale' => $locale, 'data-language' => $language],
'required' => $isDefault,
'constraints' => $isDefault
? [new NotBlank(message: 'mautic.plan.config.type.name.required'), new Length(max: 191)]
: [new Length(max: 191)],
]);
$descriptions->add($locale, TextareaType::class, [
'label' => 'mautic.plan.config.type.description',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 2, 'data-locale' => $locale],
'required' => false,
]);
}
$builder->add($names);
$builder->add($descriptions);
// Description item types have a 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',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control plan-type-icon-select'],
'choices' => Pictograms::getChoices(),
'choice_attr' => fn (?string $icon): array => ['data-icon' => (string) $icon],
'placeholder' => 'mautic.plan.config.type.icon.none',
'required' => false,
]);
}
// New types get a key once, here; existing types keep theirs.
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event): void {
$data = $event->getData();
if (is_array($data) && (!isset($data['key']) || '' === trim((string) $data['key']))) {
$data['key'] = 'type_'.bin2hex(random_bytes(4));
$event->setData($data);
}
});
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
// True for description item types: adds the pictogram field.
'with_icon' => false,
]);
$resolver->setAllowedTypes('with_icon', 'bool');
}
public function getBlockPrefix(): string
{
return 'plan_item_type_config';
}
}
+90
View File
@@ -0,0 +1,90 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Entity\PlanAllocationItem;
use MauticPlugin\PlanBundle\Service\CurrencyProvider;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
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 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).
*
* @extends AbstractType<PlanAllocationItem>
*/
class PlanAllocationItemType extends AbstractType
{
public function __construct(
private ItemTypeProvider $typeProvider,
private CurrencyProvider $currencyProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$kind = ItemTypeProvider::KIND_ALLOCATION;
$builder->add('type', ChoiceType::class, [
'label' => 'mautic.plan.allocation_item.field.type',
'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)],
'placeholder' => 'mautic.core.form.chooseone',
'required' => true,
]);
$builder->add('name', TextType::class, [
'label' => 'mautic.plan.allocation_item.field.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 255],
'required' => false,
]);
$builder->add('description', TextareaType::class, [
'label' => 'mautic.plan.allocation_item.field.description',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 3],
'required' => false,
]);
// Costs are in the general currency (Settings > Configuration > Plan Settings), shown next to the field.
foreach (['planned', 'real'] as $cost) {
$builder->add($cost.'Cost', NumberType::class, [
'label' => 'mautic.plan.allocation_item.field.'.$cost.'_cost',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'postaddon_text' => $this->currencyProvider->getCurrency()],
'input' => 'string',
'scale' => 2,
'required' => false,
]);
}
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => PlanAllocationItem::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_allocation_item';
}
}
+72
View File
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Entity\PlanDescriptionItem;
use MauticPlugin\PlanBundle\Service\ItemTypeProvider;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* One row of the description items collection in PlanType. The type dropdown lists the description item
* types set up in Settings > Configuration > Plan; each option carries the type's description, which
* Assets/js/plan.js shows under the dropdown. The position field is hidden and kept in display order by
* plan.js.
*
* @extends AbstractType<PlanDescriptionItem>
*/
class PlanDescriptionItemType extends AbstractType
{
public function __construct(
private ItemTypeProvider $typeProvider,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$kind = ItemTypeProvider::KIND_DESCRIPTION;
$builder->add('type', ChoiceType::class, [
'label' => 'mautic.plan.description_item.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('description', TextareaType::class, [
'label' => 'mautic.plan.description_item.field.description',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 5],
'required' => false,
]);
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => PlanDescriptionItem::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_description_item';
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use MauticPlugin\PlanBundle\Entity\PlanObjective;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
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.
*
* @extends AbstractType<PlanObjective>
*/
class PlanObjectiveType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('title', TextType::class, [
'label' => 'mautic.plan.objective.field.title',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 255],
]);
$builder->add('description', TextareaType::class, [
'label' => 'mautic.plan.objective.field.description',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 2],
'required' => false,
]);
$builder->add('position', HiddenType::class, [
'attr' => ['class' => 'plan-row-position'],
]);
$builder->add('isAchieved', CheckboxType::class, [
'label' => 'mautic.plan.objective.field.is_achieved',
'required' => false,
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => PlanObjective::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_objective';
}
}
+167
View File
@@ -0,0 +1,167 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityManagerInterface;
use Mautic\CategoryBundle\Form\Type\CategoryListType;
use Mautic\CoreBundle\Form\DataTransformer\IdToEntityModelTransformer;
use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber;
use Mautic\CoreBundle\Form\Type\DatePickerType;
use Mautic\CoreBundle\Form\Type\FormButtonsType;
use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType;
use Mautic\UserBundle\Entity\User;
use Mautic\UserBundle\Form\Type\UserListType;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\PlanStatus;
use MauticPlugin\PlanBundle\Service\CurrencyProvider;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @extends AbstractType<Plan>
*/
class PlanType extends AbstractType
{
public function __construct(
private CurrencyProvider $currencyProvider,
private EntityManagerInterface $em,
) {
}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
// Pass a mask array, never nothing: without one, core applies its "clean" mask (HTML-encodes &, <, >,
// quotes and line breaks, again on every save). With an array, every field not listed, nested
// objectives and description items included, goes through core's "filter": plain text is kept as
// typed (line breaks, &, quotes) and HTML tags are removed.
$builder->addEventSubscriber(new CleanFormSubscriber(['name' => 'filter']));
$builder->add('name', TextType::class, [
'label' => 'mautic.plan.field.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
]);
// The Description tab. by_reference false: Symfony calls Plan::addDescriptionItem()/removeDescriptionItem().
$builder->add('descriptionItems', CollectionType::class, [
'label' => 'mautic.plan.field.description_items',
'entry_type' => PlanDescriptionItemType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__descitem__',
'required' => false,
]);
// The Allocation tab's cost lines, in the general currency.
$builder->add('allocationItems', CollectionType::class, [
'label' => 'mautic.plan.field.allocation_items',
'entry_type' => PlanAllocationItemType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__allocitem__',
'required' => false,
]);
$builder->add('version', IntegerType::class, [
'label' => 'mautic.plan.field.version',
'label_attr' => ['class' => 'control-label'],
'invalid_message' => 'mautic.plan.version.range',
'attr' => [
'class' => 'form-control',
'min' => Plan::VERSION_MIN,
'max' => Plan::VERSION_MAX,
'step' => 1,
],
]);
// by_reference false: Symfony calls Plan::addObjective()/removeObjective(), which keep both sides in sync.
$builder->add('objectives', CollectionType::class, [
'label' => 'mautic.plan.field.objectives',
'entry_type' => PlanObjectiveType::class,
'entry_options' => ['label' => false],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'prototype' => true,
'prototype_name' => '__objective__',
'required' => false,
]);
$builder->add('status', EnumType::class, [
'class' => PlanStatus::class,
'choice_label' => fn (PlanStatus $status): string => $status->getLabelKey(),
'label' => 'mautic.plan.field.status',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
]);
// Required here; the column is nullable only because of onDelete SET NULL.
$builder->add(
$builder->create('owner', UserListType::class, [
'label' => 'mautic.plan.field.owner',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'required' => true,
'multiple' => false,
])->addModelTransformer(new IdToEntityModelTransformer($this->em, User::class))
);
$builder->add('startDate', DatePickerType::class, [
'label' => 'mautic.plan.field.start_date',
]);
$builder->add('endDate', DatePickerType::class, [
'label' => 'mautic.plan.field.end_date',
]);
// In the general currency (Settings > Configuration > Plan Settings), shown next to the field.
$builder->add('budgetPlanned', NumberType::class, [
'label' => 'mautic.plan.field.budget_planned',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'postaddon_text' => $this->currencyProvider->getCurrency()],
'input' => 'string',
'scale' => 2,
'required' => false,
]);
$builder->add('category', CategoryListType::class, [
'bundle' => 'plan',
]);
$builder->add('isPublished', YesNoButtonGroupType::class, [
'label' => 'mautic.core.form.available',
]);
$builder->add('buttons', FormButtonsType::class);
if (!empty($options['action'])) {
$builder->setAction($options['action']);
}
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Plan::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan';
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
declare(strict_types=1);
namespace MauticPlugin\PlanBundle\Form\Type;
use Doctrine\ORM\EntityRepository;
use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber;
use Mautic\CoreBundle\Form\Type\DatePickerType;
use Mautic\CoreBundle\Form\Type\FormButtonsType;
use MauticPlugin\PlanBundle\Entity\Plan;
use MauticPlugin\PlanBundle\Entity\Task;
use MauticPlugin\PlanBundle\Entity\TaskStatus;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EnumType;
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;
/**
* @extends AbstractType<Task>
*/
class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->addEventSubscriber(new CleanFormSubscriber(['description' => 'strict_html']));
/** @var Task $task */
$task = $options['data'];
$plan = $task->getPlan();
$builder->add('name', TextType::class, [
'label' => 'mautic.plan.task.field.name',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'maxlength' => 255],
]);
$builder->add('description', TextareaType::class, [
'label' => 'mautic.plan.task.field.description',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control', 'rows' => 6],
'required' => false,
]);
$builder->add('plan', EntityType::class, [
'label' => 'mautic.plan.task.field.plan',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Plan::class,
'choice_label' => 'name',
'query_builder' => fn (EntityRepository $er) => $er->createQueryBuilder('p')->orderBy('p.name', 'ASC'),
'placeholder' => 'mautic.core.form.chooseone',
'required' => true,
]);
// Offers the tasks of the task's plan when it is known, otherwise all tasks grouped by plan.
// ValidTaskParent rejects a parent from another plan, and loops.
$builder->add('parent', EntityType::class, [
'label' => 'mautic.plan.task.field.parent',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => Task::class,
'choice_label' => 'name',
'group_by' => null === $plan ? fn (Task $t): string => (string) $t->getPlan()?->getName() : null,
'query_builder' => function (EntityRepository $er) use ($task, $plan) {
$qb = $er->createQueryBuilder('t')
->leftJoin('t.plan', 'p')
->addSelect('p')
->orderBy('p.name', 'ASC')
->addOrderBy('t.name', 'ASC');
if (null !== $plan) {
$qb->andWhere('t.plan = :plan')->setParameter('plan', $plan);
}
if (null !== $task->getId()) {
$qb->andWhere('t.id != :self')->setParameter('self', $task->getId());
}
return $qb;
},
'placeholder' => 'mautic.plan.task.parent.none',
'required' => false,
]);
// Dropdown in the order of the TaskStatus cases: New, To do, In progress, Done.
$builder->add('status', EnumType::class, [
'label' => 'mautic.plan.task.field.status',
'label_attr' => ['class' => 'control-label'],
'attr' => ['class' => 'form-control'],
'class' => TaskStatus::class,
'choice_label' => fn (TaskStatus $status): string => $status->getLabelKey(),
]);
$builder->add('startDate', DatePickerType::class, [
'label' => 'mautic.plan.task.field.start_date',
]);
$builder->add('endDate', DatePickerType::class, [
'label' => 'mautic.plan.task.field.end_date',
]);
$builder->add('buttons', FormButtonsType::class);
if (!empty($options['action'])) {
$builder->setAction($options['action']);
}
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Task::class,
]);
}
public function getBlockPrefix(): string
{
return 'plan_task';
}
}