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..8acc51c50d5 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' => [ @@ -121,12 +113,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 +127,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/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 df9232ec60f..db9c0f34a76 100644 --- a/app/bundles/NotificationBundle/Controller/NotificationController.php +++ b/app/bundles/NotificationBundle/Controller/NotificationController.php @@ -11,7 +11,7 @@ namespace Mautic\NotificationBundle\Controller; -use Mautic\CoreBundle\Controller\FormController; +use Mautic\CoreBundle\Controller\AbstractFormController; use Mautic\CoreBundle\Form\Type\DateRangeType; use Mautic\CoreBundle\Helper\InputHelper; use Mautic\LeadBundle\Controller\EntityContactsTrait; @@ -19,7 +19,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Response; -class NotificationController extends FormController +class NotificationController extends AbstractFormController { use EntityContactsTrait; @@ -587,7 +587,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() { 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 873b5d1b610..33e204be1a3 100644 --- a/app/bundles/NotificationBundle/Form/Type/ConfigType.php +++ b/app/bundles/NotificationBundle/Form/Type/ConfigType.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; /** @@ -66,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'], @@ -80,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'], @@ -94,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'], @@ -107,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'], @@ -121,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'], @@ -150,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 2b4dc1a19bd..66e56290f3c 100644 --- a/app/bundles/NotificationBundle/Form/Type/MobileNotificationType.php +++ b/app/bundles/NotificationBundle/Form/Type/MobileNotificationType.php @@ -18,9 +18,14 @@ 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. @@ -38,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'], @@ -48,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'], @@ -59,7 +64,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'], @@ -69,7 +74,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'message', - 'textarea', + TextareaType::class, [ 'label' => 'mautic.notification.form.message', 'label_attr' => ['class' => 'control-label'], @@ -82,7 +87,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'], @@ -112,7 +117,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishUp', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishup', @@ -128,7 +133,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishDown', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishdown', @@ -153,7 +158,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'language', - 'locale', + LocaleType::class, [ 'label' => 'mautic.core.language', 'label_attr' => ['class' => 'control-label'], @@ -176,7 +181,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); $builder->add( 'updateSelect', - 'hidden', + HiddenType::class, [ 'data' => $options['update_select'], 'mapped' => false, @@ -208,9 +213,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( [ @@ -218,13 +223,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 cdcd8069f8d..97420903668 100644 --- a/app/bundles/NotificationBundle/Form/Type/NotificationType.php +++ b/app/bundles/NotificationBundle/Form/Type/NotificationType.php @@ -18,8 +18,14 @@ 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. @@ -37,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'], @@ -47,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'], @@ -72,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'], @@ -83,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'], @@ -97,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'], @@ -111,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'], @@ -127,7 +133,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishUp', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishup', @@ -143,7 +149,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $builder->add( 'publishDown', - 'datetime', + DateTimeType::class, [ 'widget' => 'single_text', 'label' => 'mautic.core.form.publishdown', @@ -168,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'], @@ -191,7 +197,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); $builder->add( 'updateSelect', - 'hidden', + HiddenType::class, [ 'data' => $options['update_select'], 'mapped' => false, @@ -210,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( [ @@ -220,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/Helper/NotificationHelper.php b/app/bundles/NotificationBundle/Helper/NotificationHelper.php index 9481b4687a3..b04b317676c 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 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(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() 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); }