Files
mautic-marketing-program-bu…/Model/InitiativeModel.php
T
Alexandre Gain 71ff11390b refactor(plugin): rename Plan to Program and add audience/UTM routes
Rename the Plan bundle to Program across config, routes, menus, and
controllers (Plan -> Initiative), bump version to 0.16.0, and introduce
new audience and UTM taxonomy routes and permissions to support the
expanded Programs feature set.
2026-11-13 22:01:32 +01:00

78 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace MauticPlugin\ProgramBundle\Model;
use Mautic\CoreBundle\Model\FormModel;
use MauticPlugin\ProgramBundle\Entity\Initiative;
use MauticPlugin\ProgramBundle\Entity\InitiativeRepository;
use MauticPlugin\ProgramBundle\Form\Type\InitiativeType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
/**
* @extends FormModel<Initiative>
*/
class InitiativeModel extends FormModel
{
public function getRepository(): InitiativeRepository
{
$repository = $this->em->getRepository(Initiative::class);
\assert($repository instanceof InitiativeRepository);
return $repository;
}
public function getPermissionBase(): string
{
return 'program:initiatives';
}
/**
* With no ID, returns a new initiative with the current user as owner.
*/
public function getEntity($id = null): ?Initiative
{
if (null === $id) {
$initiative = new Initiative();
$initiative->setOwner($this->userHelper->getUser(true));
return $initiative;
}
$initiative = parent::getEntity($id);
return $initiative instanceof Initiative ? $initiative : null;
}
/**
* Keeps objective and description item positions contiguous (0..n-1) before saving.
*/
public function saveEntity($entity, $unlock = true): void
{
if ($entity instanceof Initiative) {
$entity->normalizePositions();
}
parent::saveEntity($entity, $unlock);
}
/**
* @param array<string, mixed> $options
*/
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface
{
if (!$entity instanceof Initiative) {
throw new MethodNotAllowedHttpException(['Initiative']);
}
if (!empty($action)) {
$options['action'] = $action;
}
return $formFactory->create(InitiativeType::class, $entity, $options);
}
}