From 89a18ccc5dfb4af03360a698334bc86afc354123 Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Fri, 1 Nov 2019 17:41:32 +0100 Subject: [PATCH 1/4] Remove MauticFactory --- .../Api/AbstractNotificationApi.php | 15 +--------- .../NotificationBundle/Config/config.php | 4 +-- .../Helper/NotificationHelper.php | 28 +++++++++++-------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/app/bundles/NotificationBundle/Api/AbstractNotificationApi.php b/app/bundles/NotificationBundle/Api/AbstractNotificationApi.php index 6b21c74527f..5b1811b63c3 100644 --- a/app/bundles/NotificationBundle/Api/AbstractNotificationApi.php +++ b/app/bundles/NotificationBundle/Api/AbstractNotificationApi.php @@ -13,23 +13,12 @@ use Joomla\Http\Http; use Joomla\Http\Response; -use Mautic\CoreBundle\Factory\MauticFactory; use Mautic\NotificationBundle\Entity\Notification; use Mautic\PageBundle\Model\TrackableModel; use Mautic\PluginBundle\Helper\IntegrationHelper; abstract class AbstractNotificationApi { - /** - * @var string - */ - protected $apiUrl; - - /** - * @var MauticFactory - */ - protected $factory; - /** * @var Http */ @@ -48,14 +37,12 @@ abstract class AbstractNotificationApi /** * AbstractNotificationApi constructor. * - * @param MauticFactory $factory * @param Http $http * @param TrackableModel $trackableModel * @param IntegrationHelper $integrationHelper */ - public function __construct(MauticFactory $factory, Http $http, TrackableModel $trackableModel, IntegrationHelper $integrationHelper) + public function __construct(Http $http, TrackableModel $trackableModel, IntegrationHelper $integrationHelper) { - $this->factory = $factory; $this->http = $http; $this->trackableModel = $trackableModel; $this->integrationHelper = $integrationHelper; diff --git a/app/bundles/NotificationBundle/Config/config.php b/app/bundles/NotificationBundle/Config/config.php index 06ec4ca71b6..12ccc617f3e 100644 --- a/app/bundles/NotificationBundle/Config/config.php +++ b/app/bundles/NotificationBundle/Config/config.php @@ -121,12 +121,13 @@ 'class' => 'Mautic\NotificationBundle\Helper\NotificationHelper', 'alias' => 'notification_helper', 'arguments' => [ - 'mautic.factory', + 'doctrine.orm.entity_manager', 'templating.helper.assets', 'mautic.helper.core_parameters', 'mautic.helper.integration', 'router', 'request_stack', + 'mautic.lead.model.dnc' ], ], ], @@ -134,7 +135,6 @@ 'mautic.notification.api' => [ 'class' => 'Mautic\NotificationBundle\Api\OneSignalApi', 'arguments' => [ - 'mautic.factory', 'mautic.http.connector', 'mautic.page.model.trackable', 'mautic.helper.integration', diff --git a/app/bundles/NotificationBundle/Helper/NotificationHelper.php b/app/bundles/NotificationBundle/Helper/NotificationHelper.php index 9481b4687a3..acb1d69869e 100644 --- a/app/bundles/NotificationBundle/Helper/NotificationHelper.php +++ b/app/bundles/NotificationBundle/Helper/NotificationHelper.php @@ -11,22 +11,22 @@ namespace Mautic\NotificationBundle\Helper; -use Mautic\CoreBundle\Factory\MauticFactory; +use Doctrine\ORM\EntityManager; use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Templating\Helper\AssetsHelper; use Mautic\LeadBundle\Entity\DoNotContact; -use Mautic\LeadBundle\Entity\Lead; use Mautic\PluginBundle\Helper\IntegrationHelper; use Symfony\Bundle\FrameworkBundle\Routing\Router; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class NotificationHelper { /** - * @var MauticFactory + * @var EntityManager */ - protected $factory; + protected $em; /** * @var IntegrationHelper @@ -53,24 +53,31 @@ class NotificationHelper */ protected $request; + /** + * @var \Mautic\LeadBundle\Model\DoNotContact + */ + private $doNotContact; + /** * NotificationHelper constructor. * - * @param MauticFactory $factory + * @param EntityManager $em * @param AssetsHelper $assetsHelper * @param CoreParametersHelper $coreParametersHelper * @param IntegrationHelper $integrationHelper * @param Router $router * @param RequestStack $requestStack + * @param \Mautic\LeadBundle\Model\DoNotContact $doNotContact */ - public function __construct(MauticFactory $factory, AssetsHelper $assetsHelper, CoreParametersHelper $coreParametersHelper, IntegrationHelper $integrationHelper, Router $router, RequestStack $requestStack) + public function __construct(EntityManager $em, AssetsHelper $assetsHelper, CoreParametersHelper $coreParametersHelper, IntegrationHelper $integrationHelper, Router $router, RequestStack $requestStack, \Mautic\LeadBundle\Model\DoNotContact $doNotContact) { - $this->factory = $factory; + $this->em = $em; $this->assetsHelper = $assetsHelper; $this->coreParametersHelper = $coreParametersHelper; $this->integrationHelper = $integrationHelper; $this->router = $router; $this->request = $requestStack; + $this->doNotContact = $doNotContact; } /** @@ -81,14 +88,11 @@ public function __construct(MauticFactory $factory, AssetsHelper $assetsHelper, public function unsubscribe($notification) { /** @var \Mautic\LeadBundle\Entity\LeadRepository $repo */ - $repo = $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead'); + $repo = $this->em->getRepository('MauticLeadBundle:Lead'); $lead = $repo->getLeadByEmail($notification); - /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */ - $leadModel = $this->factory->getModel('lead.lead'); - - return $leadModel->addDncForLead($lead, 'notification', null, DoNotContact::UNSUBSCRIBED); + return $this->doNotContact->addDncForContact($lead->getId(), 'notification', DoNotContact::UNSUBSCRIBED); } public function getHeaderScript() From 53c7a7b135dd4641dfd81f97a58a1cb6e6d1887c Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Mon, 4 Nov 2019 10:43:41 +0100 Subject: [PATCH 2/4] Remove deprecated --- .../Controller/Api/NotificationApiController.php | 9 ++++++++- .../Controller/NotificationController.php | 6 +++--- .../NotificationBundle/Controller/PopupController.php | 2 +- .../NotificationBundle/Event/NotificationSendEvent.php | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/bundles/NotificationBundle/Controller/Api/NotificationApiController.php b/app/bundles/NotificationBundle/Controller/Api/NotificationApiController.php index 3e2dfc38e49..87666d2f22c 100644 --- a/app/bundles/NotificationBundle/Controller/Api/NotificationApiController.php +++ b/app/bundles/NotificationBundle/Controller/Api/NotificationApiController.php @@ -12,6 +12,7 @@ namespace Mautic\NotificationBundle\Controller\Api; use Mautic\ApiBundle\Controller\CommonApiController; +use Mautic\LeadBundle\Tracker\ContactTracker; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpKernel\Event\FilterControllerEvent; @@ -20,11 +21,17 @@ */ class NotificationApiController extends CommonApiController { + /** + * @var ContactTracker + */ + protected $contactTracker; + /** * {@inheritdoc} */ public function initialize(FilterControllerEvent $event) { + $this->contactTracker = $this->container->get('mautic.tracker.contact'); $this->model = $this->getModel('notification'); $this->entityClass = 'Mautic\NotificationBundle\Entity\Notification'; $this->entityNameOne = 'notification'; @@ -45,7 +52,7 @@ public function subscribeAction() /** @var \Mautic\LeadBundle\Model\LeadModel $leadModel */ $leadModel = $this->getModel('lead'); - if ($currentLead = $leadModel->getCurrentLead()) { + if ($currentLead = $this->contactTracker->getContact()) { $currentLead->addPushIDEntry($osid); $leadModel->saveEntity($currentLead); } diff --git a/app/bundles/NotificationBundle/Controller/NotificationController.php b/app/bundles/NotificationBundle/Controller/NotificationController.php index 2990e525351..ce3c62c5c96 100644 --- a/app/bundles/NotificationBundle/Controller/NotificationController.php +++ b/app/bundles/NotificationBundle/Controller/NotificationController.php @@ -11,14 +11,14 @@ namespace Mautic\NotificationBundle\Controller; -use Mautic\CoreBundle\Controller\FormController; +use Mautic\CoreBundle\Controller\AbstractFormController; use Mautic\CoreBundle\Helper\InputHelper; use Mautic\LeadBundle\Controller\EntityContactsTrait; use Mautic\NotificationBundle\Entity\Notification; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; -class NotificationController extends FormController +class NotificationController extends AbstractFormController { use EntityContactsTrait; @@ -585,7 +585,7 @@ public function cloneAction($objectId) /** * Deletes the entity. * - * @param $objectId + * @param $objectId * * @return \Symfony\Component\HttpFoundation\JsonResponse|\Symfony\Component\HttpFoundation\RedirectResponse */ diff --git a/app/bundles/NotificationBundle/Controller/PopupController.php b/app/bundles/NotificationBundle/Controller/PopupController.php index 37762544bbb..fc5d599be66 100644 --- a/app/bundles/NotificationBundle/Controller/PopupController.php +++ b/app/bundles/NotificationBundle/Controller/PopupController.php @@ -21,7 +21,7 @@ class PopupController extends CommonController public function indexAction() { /** @var \Mautic\CoreBundle\Templating\Helper\AssetsHelper $assetsHelper */ - $assetsHelper = $this->factory->getHelper('template.assets'); + $assetsHelper = $this->container->get('templating.helper.assets'); $assetsHelper->addStylesheet('/app/bundles/NotificationBundle/Assets/css/popup/popup.css'); $response = $this->render( diff --git a/app/bundles/NotificationBundle/Event/NotificationSendEvent.php b/app/bundles/NotificationBundle/Event/NotificationSendEvent.php index 2ed9545ab1d..c0b20461501 100644 --- a/app/bundles/NotificationBundle/Event/NotificationSendEvent.php +++ b/app/bundles/NotificationBundle/Event/NotificationSendEvent.php @@ -77,10 +77,12 @@ public function getHeading() public function setHeading($heading) { $this->heading = $heading; + + return $this; } /** - * @return array + * @return Lead */ public function getLead() { From b7a499539840235960c91bb85e9956346d04a780 Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Mon, 4 Nov 2019 14:25:09 +0100 Subject: [PATCH 3/4] Update NotificationBundle code --- .../NotificationBundle/Config/config.php | 8 -- .../EventListener/ChannelSubscriber.php | 5 +- .../EventListener/FormSubscriber.php | 3 +- .../Form/Type/ConfigType.php | 22 ++--- .../Type/MobileNotificationDetailsType.php | 2 +- .../Form/Type/MobileNotificationListType.php | 2 +- .../Form/Type/MobileNotificationSendType.php | 89 +++++++++++-------- .../Form/Type/MobileNotificationType.php | 46 ++++++---- .../Form/Type/NotificationListType.php | 2 +- .../Form/Type/NotificationSendType.php | 89 +++++++++++-------- .../Form/Type/NotificationType.php | 50 ++++++----- .../Model/NotificationModel.php | 4 +- 12 files changed, 182 insertions(+), 140 deletions(-) diff --git a/app/bundles/NotificationBundle/Config/config.php b/app/bundles/NotificationBundle/Config/config.php index 12ccc617f3e..928855419f6 100644 --- a/app/bundles/NotificationBundle/Config/config.php +++ b/app/bundles/NotificationBundle/Config/config.php @@ -80,40 +80,32 @@ 'forms' => [ 'mautic.form.type.notification' => [ 'class' => 'Mautic\NotificationBundle\Form\Type\NotificationType', - 'alias' => 'notification', ], 'mautic.form.type.mobile.notification' => [ 'class' => \Mautic\NotificationBundle\Form\Type\MobileNotificationType::class, - 'alias' => 'mobile_notification', ], 'mautic.form.type.mobile.notification_details' => [ 'class' => \Mautic\NotificationBundle\Form\Type\MobileNotificationDetailsType::class, 'arguments' => [ 'mautic.helper.integration', ], - 'alias' => 'mobile_notification_details', ], 'mautic.form.type.notificationconfig' => [ 'class' => 'Mautic\NotificationBundle\Form\Type\ConfigType', - 'alias' => 'notificationconfig', ], 'mautic.form.type.notificationsend_list' => [ 'class' => 'Mautic\NotificationBundle\Form\Type\NotificationSendType', 'arguments' => 'router', - 'alias' => 'notificationsend_list', ], 'mautic.form.type.notification_list' => [ 'class' => 'Mautic\NotificationBundle\Form\Type\NotificationListType', - 'alias' => 'notification_list', ], 'mautic.form.type.mobilenotificationsend_list' => [ 'class' => \Mautic\NotificationBundle\Form\Type\MobileNotificationSendType::class, 'arguments' => 'router', - 'alias' => 'mobilenotificationsend_list', ], 'mautic.form.type.mobilenotification_list' => [ 'class' => \Mautic\NotificationBundle\Form\Type\MobileNotificationListType::class, - 'alias' => 'mobilenotification_list', ], ], 'helpers' => [ diff --git a/app/bundles/NotificationBundle/EventListener/ChannelSubscriber.php b/app/bundles/NotificationBundle/EventListener/ChannelSubscriber.php index 22d0d7e462f..4ec9292b702 100644 --- a/app/bundles/NotificationBundle/EventListener/ChannelSubscriber.php +++ b/app/bundles/NotificationBundle/EventListener/ChannelSubscriber.php @@ -15,6 +15,7 @@ use Mautic\ChannelBundle\Event\ChannelEvent; use Mautic\ChannelBundle\Model\MessageModel; use Mautic\CoreBundle\EventListener\CommonSubscriber; +use Mautic\NotificationBundle\Form\Type\NotificationListType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\ReportBundle\Model\ReportModel; @@ -66,7 +67,7 @@ public function onAddChannel(ChannelEvent $event) 'asset.download', 'form.submit', ], - 'lookupFormType' => 'notification_list', + 'lookupFormType' => NotificationListType::class, 'repository' => 'MauticNotificationBundle:Notification', 'lookupOptions' => [ 'mobile' => false, @@ -93,7 +94,7 @@ public function onAddChannel(ChannelEvent $event) 'asset.download', 'form.submit', ], - 'lookupFormType' => 'notification_list', + 'lookupFormType' => NotificationListType::class, 'repository' => 'MauticNotificationBundle:Notification', 'lookupOptions' => [ 'mobile' => true, diff --git a/app/bundles/NotificationBundle/EventListener/FormSubscriber.php b/app/bundles/NotificationBundle/EventListener/FormSubscriber.php index 90311fe6be6..76b8ca51ce3 100644 --- a/app/bundles/NotificationBundle/EventListener/FormSubscriber.php +++ b/app/bundles/NotificationBundle/EventListener/FormSubscriber.php @@ -20,6 +20,7 @@ use Mautic\LeadBundle\Model\LeadModel; use Mautic\NotificationBundle\Api\AbstractNotificationApi; use Mautic\NotificationBundle\Event\NotificationSendEvent; +use Mautic\NotificationBundle\Form\Type\NotificationListType; use Mautic\NotificationBundle\Model\NotificationModel; use Mautic\NotificationBundle\NotificationEvents; use Mautic\PluginBundle\Helper\IntegrationHelper; @@ -89,7 +90,7 @@ public function onFormBuild(FormBuilderEvent $event) 'group' => 'mautic.notification.actions', 'description' => 'mautic.notification.actions.mobile_tooltip', 'label' => 'mautic.notification.actions.send_mobile_notification', - 'formType' => 'notification_list', + 'formType' => NotificationListType::class, 'formTheme' => 'MauticNotificationBundle:FormTheme\NotificationSendList', 'eventName' => NotificationEvents::NOTIFICATION_ON_FORM_ACTION_SEND, ]; diff --git a/app/bundles/NotificationBundle/Form/Type/ConfigType.php b/app/bundles/NotificationBundle/Form/Type/ConfigType.php index 17372842901..33e204be1a3 100644 --- a/app/bundles/NotificationBundle/Form/Type/ConfigType.php +++ b/app/bundles/NotificationBundle/Form/Type/ConfigType.php @@ -11,7 +11,9 @@ namespace Mautic\NotificationBundle\Form\Type; +use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; /** @@ -27,7 +29,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add( 'notification_enabled', - 'yesno_button_group', + YesNoButtonGroupType::class, [ 'label' => 'mautic.notification.config.form.notification.enabled', 'data' => (bool) $options['data']['notification_enabled'], @@ -39,7 +41,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'notification_landing_page_enabled', - 'yesno_button_group', + YesNoButtonGroupType::class, [ 'label' => 'mautic.notification.config.form.notification.landingpage.enabled', 'data' => (bool) $options['data']['notification_landing_page_enabled'], @@ -52,7 +54,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'notification_tracking_page_enabled', - 'yesno_button_group', + YesNoButtonGroupType::class, [ 'label' => 'mautic.notification.config.form.notification.trackingpage.enabled', 'data' => (bool) $options['data']['notification_tracking_page_enabled'], @@ -65,7 +67,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'notification_app_id', - 'text', + TextType::class, [ 'label' => 'mautic.notification.config.form.notification.app_id', 'data' => $options['data']['notification_app_id'], @@ -79,7 +81,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'notification_safari_web_id', - 'text', + TextType::class, [ 'label' => 'mautic.notification.config.form.notification.safari_web_id', 'data' => $options['data']['notification_safari_web_id'], @@ -93,7 +95,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'notification_rest_api_key', - 'text', + TextType::class, [ 'label' => 'mautic.notification.config.form.notification.rest_api_key', 'data' => $options['data']['notification_rest_api_key'], @@ -106,7 +108,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); $builder->add( 'gcm_sender_id', - 'text', + TextType::class, [ 'label' => 'mautic.notification.config.form.notification.gcm_sender_id', 'data' => $options['data']['gcm_sender_id'], @@ -120,7 +122,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'notification_subdomain_name', - 'text', + TextType::class, [ 'label' => 'mautic.notification.config.form.notification.subdomain_name', 'data' => $options['data']['notification_subdomain_name'], @@ -134,7 +136,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'welcomenotification_enabled', - 'yesno_button_group', + YesNoButtonGroupType::class, [ 'label' => 'mautic.notification.config.form.notification.welcome.enabled', 'data' => (bool) $options['data']['welcomenotification_enabled'], @@ -149,7 +151,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'notificationconfig'; } diff --git a/app/bundles/NotificationBundle/Form/Type/MobileNotificationDetailsType.php b/app/bundles/NotificationBundle/Form/Type/MobileNotificationDetailsType.php index 19ce202ab4e..65c6ae8f5b7 100644 --- a/app/bundles/NotificationBundle/Form/Type/MobileNotificationDetailsType.php +++ b/app/bundles/NotificationBundle/Form/Type/MobileNotificationDetailsType.php @@ -274,7 +274,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'mobile_notification_details'; } diff --git a/app/bundles/NotificationBundle/Form/Type/MobileNotificationListType.php b/app/bundles/NotificationBundle/Form/Type/MobileNotificationListType.php index ebeaf8d0220..3e43124dadd 100644 --- a/app/bundles/NotificationBundle/Form/Type/MobileNotificationListType.php +++ b/app/bundles/NotificationBundle/Form/Type/MobileNotificationListType.php @@ -61,7 +61,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'mobilenotification_list'; } diff --git a/app/bundles/NotificationBundle/Form/Type/MobileNotificationSendType.php b/app/bundles/NotificationBundle/Form/Type/MobileNotificationSendType.php index 09e152107ff..eaa4628b6b3 100644 --- a/app/bundles/NotificationBundle/Form/Type/MobileNotificationSendType.php +++ b/app/bundles/NotificationBundle/Form/Type/MobileNotificationSendType.php @@ -12,8 +12,9 @@ namespace Mautic\NotificationBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ButtonType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Validator\Constraints\NotBlank; @@ -41,21 +42,25 @@ public function __construct(RouterInterface $router) */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('notification', 'mobilenotification_list', [ - 'label' => 'mautic.notification.send.selectnotifications', - 'label_attr' => ['class' => 'control-label'], - 'attr' => [ - 'class' => 'form-control', - 'tooltip' => 'mautic.notification.choose.notifications', - 'onchange' => 'Mautic.disabledNotificationAction()', - ], - 'multiple' => false, - 'constraints' => [ - new NotBlank( - ['message' => 'mautic.notification.choosenotification.notblank'] - ), - ], - ]); + $builder->add( + 'notification', + MobileNotificationListType::class, + [ + 'label' => 'mautic.notification.send.selectnotifications', + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => 'mautic.notification.choose.notifications', + 'onchange' => 'Mautic.disabledNotificationAction()', + ], + 'multiple' => false, + 'constraints' => [ + new NotBlank( + ['message' => 'mautic.notification.choosenotification.notblank'] + ), + ], + ] + ); if (!empty($options['update_select'])) { $windowUrl = $this->router->generate('mautic_mobile_notification_action', [ @@ -64,16 +69,20 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'updateSelect' => $options['update_select'], ]); - $builder->add('newNotificationButton', 'button', [ - 'attr' => [ - 'class' => 'btn btn-primary btn-nospin', - 'onclick' => 'Mautic.loadNewWindow({ - "windowUrl": "'.$windowUrl.'" - })', - 'icon' => 'fa fa-plus', - ], - 'label' => 'mautic.notification.send.new.notification', - ]); + $builder->add( + 'newNotificationButton', + ButtonType::class, + [ + 'attr' => [ + 'class' => 'btn btn-primary btn-nospin', + 'onclick' => 'Mautic.loadNewWindow({ + "windowUrl": "'.$windowUrl.'" + })', + 'icon' => 'fa fa-plus', + ], + 'label' => 'mautic.notification.send.new.notification', + ] + ); $notification = $options['data']['notification']; @@ -85,27 +94,31 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'updateSelect' => $options['update_select'], ]); - $builder->add('editNotificationButton', 'button', [ - 'attr' => [ - 'class' => 'btn btn-primary btn-nospin', - 'onclick' => 'Mautic.loadNewWindow(Mautic.standardNotificationUrl({"windowUrl": "'.$windowUrlEdit.'"}))', - 'disabled' => !isset($notification), - 'icon' => 'fa fa-edit', - ], - 'label' => 'mautic.notification.send.edit.notification', - ]); + $builder->add( + 'editNotificationButton', + ButtonType::class, + [ + 'attr' => [ + 'class' => 'btn btn-primary btn-nospin', + 'onclick' => 'Mautic.loadNewWindow(Mautic.standardNotificationUrl({"windowUrl": "'.$windowUrlEdit.'"}))', + 'disabled' => !isset($notification), + 'icon' => 'fa fa-edit', + ], + 'label' => 'mautic.notification.send.edit.notification', + ] + ); } } - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - $resolver->setOptional(['update_select']); + $resolver->setDefined(['update_select']); } /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'mobilenotificationsend_list'; } diff --git a/app/bundles/NotificationBundle/Form/Type/MobileNotificationType.php b/app/bundles/NotificationBundle/Form/Type/MobileNotificationType.php index cc2d4e63875..a2cfb4f2141 100644 --- a/app/bundles/NotificationBundle/Form/Type/MobileNotificationType.php +++ b/app/bundles/NotificationBundle/Form/Type/MobileNotificationType.php @@ -11,12 +11,20 @@ namespace Mautic\NotificationBundle\Form\Type; +use Mautic\CategoryBundle\Form\Type\CategoryListType; use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber; use Mautic\CoreBundle\Form\EventListener\FormExitSubscriber; +use Mautic\CoreBundle\Form\Type\FormButtonsType; +use Mautic\EmailBundle\Form\Type\EmailUtmTagsType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\DateTimeType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Form\Extension\Core\Type\LocaleType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class NotificationType. @@ -34,7 +42,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'name', - 'text', + TextType::class, [ 'label' => 'mautic.notification.form.internal.name', 'label_attr' => ['class' => 'control-label'], @@ -44,7 +52,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'description', - 'textarea', + TextareaType::class, [ 'label' => 'mautic.notification.form.internal.description', 'label_attr' => ['class' => 'control-label'], @@ -55,7 +63,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'heading', - 'text', + TextType::class, [ 'label' => 'mautic.notification.form.mobile.heading', 'label_attr' => ['class' => 'control-label'], @@ -65,7 +73,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'message', - 'textarea', + TextareaType::class, [ 'label' => 'mautic.notification.form.message', 'label_attr' => ['class' => 'control-label'], @@ -78,7 +86,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'url', - 'url', + UrlType::class, [ 'label' => 'mautic.notification.form.mobile.url', 'label_attr' => ['class' => 'control-label'], @@ -92,7 +100,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'utmTags', - 'utm_tags', + EmailUtmTagsType::class, [ 'label' => 'mautic.email.utm_tags', 'label_attr' => ['class' => 'control-label'], @@ -108,7 +116,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishUp', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishup', @@ -124,7 +132,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishDown', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishdown', @@ -141,7 +149,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) //add category $builder->add( 'category', - 'category', + CategoryListType::class, [ 'bundle' => 'notification', ] @@ -149,7 +157,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'language', - 'locale', + LocaleType::class, [ 'label' => 'mautic.core.language', 'label_attr' => ['class' => 'control-label'], @@ -160,19 +168,19 @@ public function buildForm(FormBuilderInterface $builder, array $options) ] ); - $builder->add('buttons', 'form_buttons'); + $builder->add('buttons', FormButtonsType::class); if (!empty($options['update_select'])) { $builder->add( 'buttons', - 'form_buttons', + FormButtonsType::class, [ 'apply_text' => false, ] ); $builder->add( 'updateSelect', - 'hidden', + HiddenType::class, [ 'data' => $options['update_select'], 'mapped' => false, @@ -181,7 +189,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } else { $builder->add( 'buttons', - 'form_buttons' + FormButtonsType::class ); } @@ -204,9 +212,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) } /** - * @param OptionsResolverInterface $resolver + * @param OptionsResolver $resolver */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( [ @@ -214,13 +222,13 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) ] ); - $resolver->setOptional(['update_select']); + $resolver->setDefined(['update_select']); } /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'mobile_notification'; } diff --git a/app/bundles/NotificationBundle/Form/Type/NotificationListType.php b/app/bundles/NotificationBundle/Form/Type/NotificationListType.php index ec3d9d69207..96444ba00c9 100644 --- a/app/bundles/NotificationBundle/Form/Type/NotificationListType.php +++ b/app/bundles/NotificationBundle/Form/Type/NotificationListType.php @@ -61,7 +61,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'notification_list'; } diff --git a/app/bundles/NotificationBundle/Form/Type/NotificationSendType.php b/app/bundles/NotificationBundle/Form/Type/NotificationSendType.php index bd2a087681f..439799157e6 100644 --- a/app/bundles/NotificationBundle/Form/Type/NotificationSendType.php +++ b/app/bundles/NotificationBundle/Form/Type/NotificationSendType.php @@ -12,8 +12,9 @@ namespace Mautic\NotificationBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ButtonType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Validator\Constraints\NotBlank; @@ -41,21 +42,25 @@ public function __construct(RouterInterface $router) */ public function buildForm(FormBuilderInterface $builder, array $options) { - $builder->add('notification', 'notification_list', [ - 'label' => 'mautic.notification.send.selectnotifications', - 'label_attr' => ['class' => 'control-label'], - 'attr' => [ - 'class' => 'form-control', - 'tooltip' => 'mautic.notification.choose.notifications', - 'onchange' => 'Mautic.disabledNotificationAction()', - ], - 'multiple' => false, - 'constraints' => [ - new NotBlank( - ['message' => 'mautic.notification.choosenotification.notblank'] - ), - ], - ]); + $builder->add( + 'notification', + NotificationListType::class, + [ + 'label' => 'mautic.notification.send.selectnotifications', + 'label_attr' => ['class' => 'control-label'], + 'attr' => [ + 'class' => 'form-control', + 'tooltip' => 'mautic.notification.choose.notifications', + 'onchange' => 'Mautic.disabledNotificationAction()', + ], + 'multiple' => false, + 'constraints' => [ + new NotBlank( + ['message' => 'mautic.notification.choosenotification.notblank'] + ), + ], + ] + ); if (!empty($options['update_select'])) { $windowUrl = $this->router->generate('mautic_notification_action', [ @@ -64,16 +69,20 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'updateSelect' => $options['update_select'], ]); - $builder->add('newNotificationButton', 'button', [ - 'attr' => [ - 'class' => 'btn btn-primary btn-nospin', - 'onclick' => 'Mautic.loadNewWindow({ - "windowUrl": "'.$windowUrl.'" - })', - 'icon' => 'fa fa-plus', - ], - 'label' => 'mautic.notification.send.new.notification', - ]); + $builder->add( + 'newNotificationButton', + ButtonType::class, + [ + 'attr' => [ + 'class' => 'btn btn-primary btn-nospin', + 'onclick' => 'Mautic.loadNewWindow({ + "windowUrl": "'.$windowUrl.'" + })', + 'icon' => 'fa fa-plus', + ], + 'label' => 'mautic.notification.send.new.notification', + ] + ); $notification = $options['data']['notification']; @@ -85,27 +94,31 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'updateSelect' => $options['update_select'], ]); - $builder->add('editNotificationButton', 'button', [ - 'attr' => [ - 'class' => 'btn btn-primary btn-nospin', - 'onclick' => 'Mautic.loadNewWindow(Mautic.standardNotificationUrl({"windowUrl": "'.$windowUrlEdit.'"}))', - 'disabled' => !isset($notification), - 'icon' => 'fa fa-edit', - ], - 'label' => 'mautic.notification.send.edit.notification', - ]); + $builder->add( + 'editNotificationButton', + ButtonType::class, + [ + 'attr' => [ + 'class' => 'btn btn-primary btn-nospin', + 'onclick' => 'Mautic.loadNewWindow(Mautic.standardNotificationUrl({"windowUrl": "'.$windowUrlEdit.'"}))', + 'disabled' => !isset($notification), + 'icon' => 'fa fa-edit', + ], + 'label' => 'mautic.notification.send.edit.notification', + ] + ); } } - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - $resolver->setOptional(['update_select']); + $resolver->setDefined(['update_select']); } /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'notificationsend_list'; } diff --git a/app/bundles/NotificationBundle/Form/Type/NotificationType.php b/app/bundles/NotificationBundle/Form/Type/NotificationType.php index 8a18c618ab0..6d6377d1bd3 100644 --- a/app/bundles/NotificationBundle/Form/Type/NotificationType.php +++ b/app/bundles/NotificationBundle/Form/Type/NotificationType.php @@ -11,11 +11,21 @@ namespace Mautic\NotificationBundle\Form\Type; +use Mautic\CategoryBundle\Form\Type\CategoryListType; use Mautic\CoreBundle\Form\EventListener\CleanFormSubscriber; use Mautic\CoreBundle\Form\EventListener\FormExitSubscriber; +use Mautic\CoreBundle\Form\Type\FormButtonsType; +use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; +use Mautic\EmailBundle\Form\Type\EmailUtmTagsType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\DateTimeType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Form\Extension\Core\Type\LocaleType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Symfony\Component\Form\Extension\Core\Type\UrlType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class NotificationType. @@ -33,7 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'name', - 'text', + TextType::class, [ 'label' => 'mautic.notification.form.internal.name', 'label_attr' => ['class' => 'control-label'], @@ -43,7 +53,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'description', - 'textarea', + TextareaType::class, [ 'label' => 'mautic.notification.form.internal.description', 'label_attr' => ['class' => 'control-label'], @@ -54,7 +64,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'utmTags', - 'utm_tags', + EmailUtmTagsType::class, [ 'label' => 'mautic.email.utm_tags', 'label_attr' => ['class' => 'control-label'], @@ -68,7 +78,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'heading', - 'text', + TextType::class, [ 'label' => 'mautic.notification.form.heading', 'label_attr' => ['class' => 'control-label'], @@ -79,7 +89,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'message', - 'textarea', + TextareaType::class, [ 'label' => 'mautic.notification.form.message', 'label_attr' => ['class' => 'control-label'], @@ -93,7 +103,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'url', - 'url', + UrlType::class, [ 'label' => 'mautic.notification.form.url', 'label_attr' => ['class' => 'control-label'], @@ -107,7 +117,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'button', - 'text', + TextType::class, [ 'label' => 'mautic.notification.form.button', 'label_attr' => ['class' => 'control-label'], @@ -119,11 +129,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) ] ); - $builder->add('isPublished', 'yesno_button_group'); + $builder->add('isPublished', YesNoButtonGroupType::class); $builder->add( 'publishUp', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishup', @@ -139,7 +149,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishDown', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishdown', @@ -156,7 +166,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) //add category $builder->add( 'category', - 'category', + CategoryListType::class, [ 'bundle' => 'notification', ] @@ -164,7 +174,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'language', - 'locale', + LocaleType::class, [ 'label' => 'mautic.core.language', 'label_attr' => ['class' => 'control-label'], @@ -180,14 +190,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!empty($options['update_select'])) { $builder->add( 'buttons', - 'form_buttons', + FormButtonsType::class, [ 'apply_text' => false, ] ); $builder->add( 'updateSelect', - 'hidden', + HiddenType::class, [ 'data' => $options['update_select'], 'mapped' => false, @@ -196,7 +206,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } else { $builder->add( 'buttons', - 'form_buttons' + FormButtonsType::class ); } @@ -206,9 +216,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) } /** - * @param OptionsResolverInterface $resolver + * @param OptionsResolver $resolver */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( [ @@ -216,13 +226,13 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) ] ); - $resolver->setOptional(['update_select']); + $resolver->setDefined(['update_select']); } /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'notification'; } diff --git a/app/bundles/NotificationBundle/Model/NotificationModel.php b/app/bundles/NotificationBundle/Model/NotificationModel.php index 5baee0180b9..1ff63128d35 100644 --- a/app/bundles/NotificationBundle/Model/NotificationModel.php +++ b/app/bundles/NotificationBundle/Model/NotificationModel.php @@ -20,6 +20,8 @@ use Mautic\NotificationBundle\Entity\Notification; use Mautic\NotificationBundle\Entity\Stat; use Mautic\NotificationBundle\Event\NotificationEvent; +use Mautic\NotificationBundle\Form\Type\MobileNotificationType; +use Mautic\NotificationBundle\Form\Type\NotificationType; use Mautic\NotificationBundle\NotificationEvents; use Mautic\PageBundle\Model\TrackableModel; use Symfony\Component\EventDispatcher\Event; @@ -130,7 +132,7 @@ public function createForm($entity, $formFactory, $action = null, $options = []) $options['action'] = $action; } - $type = strpos($action, 'mobile_') !== false ? 'mobile_notification' : 'notification'; + $type = strpos($action, 'mobile_') !== false ? MobileNotificationType::class : NotificationType::class; return $formFactory->create($type, $entity, $options); } From c40b8cb969d08c3bbb85c0ef6af1ffdf2365e6bd Mon Sep 17 00:00:00 2001 From: Enc3phale Date: Tue, 5 Nov 2019 16:37:49 +0100 Subject: [PATCH 4/4] Ps Fixer --- app/bundles/NotificationBundle/Config/config.php | 2 +- .../NotificationBundle/Helper/NotificationHelper.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/bundles/NotificationBundle/Config/config.php b/app/bundles/NotificationBundle/Config/config.php index 928855419f6..8acc51c50d5 100644 --- a/app/bundles/NotificationBundle/Config/config.php +++ b/app/bundles/NotificationBundle/Config/config.php @@ -119,7 +119,7 @@ 'mautic.helper.integration', 'router', 'request_stack', - 'mautic.lead.model.dnc' + 'mautic.lead.model.dnc', ], ], ], diff --git a/app/bundles/NotificationBundle/Helper/NotificationHelper.php b/app/bundles/NotificationBundle/Helper/NotificationHelper.php index acb1d69869e..b04b317676c 100644 --- a/app/bundles/NotificationBundle/Helper/NotificationHelper.php +++ b/app/bundles/NotificationBundle/Helper/NotificationHelper.php @@ -61,12 +61,12 @@ class NotificationHelper /** * NotificationHelper constructor. * - * @param EntityManager $em - * @param AssetsHelper $assetsHelper - * @param CoreParametersHelper $coreParametersHelper - * @param IntegrationHelper $integrationHelper - * @param Router $router - * @param RequestStack $requestStack + * @param EntityManager $em + * @param AssetsHelper $assetsHelper + * @param CoreParametersHelper $coreParametersHelper + * @param IntegrationHelper $integrationHelper + * @param Router $router + * @param RequestStack $requestStack * @param \Mautic\LeadBundle\Model\DoNotContact $doNotContact */ public function __construct(EntityManager $em, AssetsHelper $assetsHelper, CoreParametersHelper $coreParametersHelper, IntegrationHelper $integrationHelper, Router $router, RequestStack $requestStack, \Mautic\LeadBundle\Model\DoNotContact $doNotContact)