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.
63 lines
1.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\ProgramBundle\Model;
|
|
|
|
use Mautic\CoreBundle\Model\FormModel;
|
|
use MauticPlugin\ProgramBundle\Entity\Audience;
|
|
use MauticPlugin\ProgramBundle\Entity\AudienceRepository;
|
|
use MauticPlugin\ProgramBundle\Form\Type\AudienceType;
|
|
use Symfony\Component\Form\FormFactoryInterface;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
|
/**
|
|
* Available as mautic.program.model.audience, or getModel('program.audience').
|
|
*
|
|
* Audiences are a global directory (Programs > Audiences), independent of plans; plans link to
|
|
* them from their Audiences tab through InitiativeAudience (which carries the audience's priority in
|
|
* that initiative).
|
|
*/
|
|
class AudienceModel extends FormModel
|
|
{
|
|
public function getRepository(): AudienceRepository
|
|
{
|
|
$repository = $this->em->getRepository(Audience::class);
|
|
\assert($repository instanceof AudienceRepository);
|
|
|
|
return $repository;
|
|
}
|
|
|
|
public function getPermissionBase(): string
|
|
{
|
|
return 'program:audiences';
|
|
}
|
|
|
|
public function getEntity($id = null): ?Audience
|
|
{
|
|
if (null === $id) {
|
|
return new Audience();
|
|
}
|
|
|
|
$audience = parent::getEntity($id);
|
|
|
|
return $audience instanceof Audience ? $audience : null;
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $options
|
|
*/
|
|
public function createForm($entity, FormFactoryInterface $formFactory, $action = null, $options = []): FormInterface
|
|
{
|
|
if (!$entity instanceof Audience) {
|
|
throw new MethodNotAllowedHttpException(['Audience']);
|
|
}
|
|
|
|
if (!empty($action)) {
|
|
$options['action'] = $action;
|
|
}
|
|
|
|
return $formFactory->create(AudienceType::class, $entity, $options);
|
|
}
|
|
} |