Skip to content

Commit

Permalink
M3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmany committed Apr 13, 2021
1 parent 1bcbcd9 commit 4640878
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 16 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 20 additions & 1 deletion Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
],
'mautic.form.validation.inttel.subscriber' => [
'class' => \MauticPlugin\MauticInternationalPhoneInputBundle\EventListener\FormValidationSubscriber::class,
'arguments' => []
'arguments' => [
'translator',
'request_stack'
]
],
],
'forms' => [
Expand All @@ -41,6 +44,22 @@
'mautic.integration.internationalphoneinput' => [
'class' => \MauticPlugin\MauticInternationalPhoneInputBundle\Integration\InternationalPhoneInputIntegration::class,
'arguments' => [
'event_dispatcher',
'mautic.helper.cache_storage',
'doctrine.orm.entity_manager',
'session',
'request_stack',
'router',
'translator',
'monolog.logger.mautic',
'mautic.helper.encryption',
'mautic.lead.model.lead',
'mautic.lead.model.company',
'mautic.helper.paths',
'mautic.core.model.notification',
'mautic.lead.model.field',
'mautic.plugin.model.integration_entity',
'mautic.lead.model.dnc',
],
],
],
Expand Down
6 changes: 3 additions & 3 deletions Controller/JsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function generateCountryCodeAction($formName)
{
$ip = $this->ipLookupHelper->getIpAddress();
include_once __DIR__.'/../countries.php';
$country = ArrayHelper::getValue('country', $ip->getIpDetails());
$country = ArrayHelper::getValue('country', $ip->getIpDetails() ?? []);
$countryCode = array_search(strtolower($country), array_map('strtolower', $countries)); ## easy version
$realFormName = ltrim($formName, '_');
$utilsUrl = $this->assetsHelper->getUrl('plugins/MauticInternationalPhoneInputBundle/Assets/js/utils.js', null, null, true
$utilsUrl = $this->assetsHelper->getUrl('plugins/MauticInternationalPhoneInputBundle/Assets/lib/js/utils.js', null, null, true
);
$js = <<<JS
if(!window.{$formName}){
Expand All @@ -63,7 +63,7 @@ public function generateCountryCodeAction($formName)
var elem = elems[i];
window.intlTelInput(elem , {
hiddenInput: elem.getAttribute('data-field-alias')+'_full',
hiddenInput: elem.getAttribute('data-field-alias'),
separateDialCode: true,
initialCountry: "{$countryCode}",
utilsScript: "{$utilsUrl}"
Expand Down
11 changes: 4 additions & 7 deletions EventListener/FormSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@
use Mautic\FormBundle\FormEvents;
use Mautic\PluginBundle\Helper\IntegrationHelper;
use Mautic\PluginBundle\Integration\AbstractIntegration;
use MauticPlugin\MauticInternationalPhoneInputBundle\Form\Type\InternationalPhoneInputType;
use MauticPlugin\MauticInternationalPhoneInputBundle\Integration\InternationalPhoneInputIntegration;
use MauticPlugin\MauticInternationalPhoneInputBundle\InternationalPhoneInputEvents;
use MauticPlugin\MauticInternationalPhoneInputBundle\Service\InternationalPhoneInputClient;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class FormSubscriber extends CommonSubscriber
class FormSubscriber implements EventSubscriberInterface
{
const FIELD_NAME = 'plugin.internationalphoneinput';

/**
* @var InternationalPhoneInputClient
*/
protected $internationalphoneinputClient;

/**
* @var string
*/
Expand Down Expand Up @@ -74,7 +71,7 @@ public function onFormBuild(FormBuilderEvent $event)
}
$event->addFormField(self::FIELD_NAME, [
'label' => 'mautic.plugin.actions.internationalphoneinput',
'formType' => 'internationalphoneinput',
'formType' => InternationalPhoneInputType::class,
'template' => 'MauticInternationalPhoneInputBundle:Integration:internationalphoneinput.html.php',
'builderOptions' => [
],
Expand Down
24 changes: 22 additions & 2 deletions EventListener/FormValidationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,30 @@
use Mautic\CoreBundle\Helper\ArrayHelper;
use Mautic\FormBundle\Event as Events;
use Mautic\FormBundle\FormEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Translation\TranslatorInterface;

class FormValidationSubscriber extends CommonSubscriber
class FormValidationSubscriber implements EventSubscriberInterface
{

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var \Symfony\Component\HttpFoundation\Request|null
*/
private $request;

public function __construct(TranslatorInterface $translator, RequestStack $requestStack)
{
$this->translator = $translator;
$this->request = $requestStack->getCurrentRequest();
}


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -58,7 +78,7 @@ public function onFormValidate(Events\ValidationEvent $event)
{
$field = $event->getField();
$phoneNumber = $event->getValue();
$fullPhoneNumber = ArrayHelper::getValue($field->getAlias().'_full', $this->request->request->get('mauticform'));
$fullPhoneNumber = ArrayHelper::getValue($field->getAlias(), $this->request ? $this->request->request->get('mauticform') : []);
if (!empty($phoneNumber) && $field->getType() === FormSubscriber::FIELD_NAME && !empty($field->getValidation()['international'])) {
$phoneUtil = PhoneNumberUtil::getInstance();
try {
Expand Down
6 changes: 3 additions & 3 deletions Views/Integration/internationalphoneinput.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@
if(!$inBuilder) {
echo <<<HTML
<link rel="stylesheet" href="{$view['assets']->getUrl(
'plugins/MauticInternationalPhoneInputBundle/Assets/css/intlTelInput.min.css',
'plugins/MauticInternationalPhoneInputBundle/Assets/lib/css/intlTelInput.min.css',
null,
null,
true
)}">
<script src="{$view['assets']->getUrl(
'plugins/MauticInternationalPhoneInputBundle/Assets/js/intlTelInput.min.js',
'plugins/MauticInternationalPhoneInputBundle/Assets/lib/js/intlTelInput.min.js',
null,
null,
true
)}"></script>
<script async defer src="{$view['router']->generate(
<script async defer src="{$view['router']->url(
'mautic_country_code_generate',
['formName' => $formName],
true
Expand Down

0 comments on commit 4640878

Please sign in to comment.