Rename the plugin's vendor/namespace from experiential/Program to mt3s/MT3SMarketingProgram (composer: mt3s/mautic-marketing-program-bundle): - ProgramBundle -> MT3SMarketingProgramBundle; extension, integration, config support, permissions, events and twig extension renamed likewise - Initiative* -> Program*: controller (InitiativeController -> ProgramController), model, entities, repositories, form types and views (new _tabs/_task_table/_tab_table_filter partials, details page) - Settings config form theme -> _config_mt3smarketingprogramconfig_widget; routes and translations re-prefixed (mt3s_marketing_program_*) - Assets: icon.svg -> mt3s-mp-icon.svg; program.js -> mt3s-mp-program.js (OnLoad hooks renamed mt3sMpProgram*) - Add Command/RefreshStatsCommand; Migrations/Version_0_17_0.php renames the tables to mt3s_mp_program_*
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace MauticPlugin\MT3SMarketingProgramBundle\Model;
|
|
|
|
use Mautic\CoreBundle\Model\FormModel;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\Audience;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Entity\AudienceRepository;
|
|
use MauticPlugin\MT3SMarketingProgramBundle\Form\Type\AudienceType;
|
|
use Symfony\Component\Form\FormFactoryInterface;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
|
|
|
|
/**
|
|
* Available as mt3s.marketing_program.model.audience, or getModel('mt3smp.audience').
|
|
*
|
|
* Audiences are a global directory (Programs > Audiences), independent of plans; plans link to
|
|
* them from their Audiences tab through ProgramAudience (which carries the audience's priority in
|
|
* that program).
|
|
*/
|
|
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 'mt3smarketingprogram: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);
|
|
}
|
|
} |