*/ class GrapesJsBuilderModel extends AbstractCommonModel { public function __construct( private RequestStack $requestStack, private EmailModel $emailModel, EntityManager $em, CorePermissions $security, EventDispatcherInterface $dispatcher, UrlGeneratorInterface $router, Translator $translator, UserHelper $userHelper, LoggerInterface $mauticLogger, CoreParametersHelper $coreParametersHelper ) { parent::__construct($em, $security, $dispatcher, $router, $translator, $userHelper, $mauticLogger, $coreParametersHelper); } /** * @return GrapesJsBuilderRepository */ public function getRepository() { /** @var GrapesJsBuilderRepository $repository */ $repository = $this->em->getRepository(GrapesJsBuilder::class); $repository->setTranslator($this->translator); return $repository; } /** * Add or edit email settings entity based on request. */ public function addOrEditEntity(Email $email): void { if ($this->emailModel->isUpdatingTranslationChildren()) { return; } $grapesJsBuilder = $this->getRepository()->findOneBy(['email' => $email]); if (!$grapesJsBuilder) { $grapesJsBuilder = new GrapesJsBuilder(); $grapesJsBuilder->setEmail($email); } if ($this->requestStack->getCurrentRequest()->request->has('grapesjsbuilder')) { $data = $this->requestStack->getCurrentRequest()->get('grapesjsbuilder', ''); if (isset($data['customMjml'])) { $grapesJsBuilder->setCustomMjml($data['customMjml']); } $this->getRepository()->saveEntity($grapesJsBuilder); $customHtml = $this->requestStack->getCurrentRequest()->get('emailform')['customHtml'] ?? null; $email->setCustomHtml($customHtml); $this->emailModel->getRepository()->saveEntity($email); } } public function getGrapesJsFromEmailId(?int $emailId) { if ($email = $this->emailModel->getEntity($emailId)) { return $this->getRepository()->findOneBy(['email' => $email]); } } }