diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhoneNumberHelperInterface.php b/src/Bundle/ChillMainBundle/Phonenumber/PhoneNumberHelperInterface.php
index 38aef39ac..dbf78003c 100644
--- a/src/Bundle/ChillMainBundle/Phonenumber/PhoneNumberHelperInterface.php
+++ b/src/Bundle/ChillMainBundle/Phonenumber/PhoneNumberHelperInterface.php
@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Phonenumber;
+use libphonenumber\PhoneNumber;
+
/**
* Helper to some task linked to phonenumber.
*
@@ -20,9 +22,9 @@ namespace Chill\MainBundle\Phonenumber;
*/
interface PhoneNumberHelperInterface
{
- public function denormalize(string $phoneNumber): string;
+ public function denormalize(PhoneNumber $phoneNumber): string;
- public function format(string $phonenumber): string;
+ public function format(PhoneNumber $phonenumber): string;
/**
* Get type (mobile, landline, ...) for phone number.
diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php
index 8edad2cc6..0473fe195 100644
--- a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php
+++ b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php
@@ -45,6 +45,8 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
private Client $twilioClient;
+ private PhonenumberUtil $phoneNumberUtil;
+
public function __construct(
CacheItemPoolInterface $cacheUserData,
ParameterBagInterface $parameterBag,
@@ -67,17 +69,13 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
]);
$this->isConfigured = true;
}
+
+ $this->phoneNumberUtil = PhoneNumberUtil::getInstance();
}
- public function denormalize(string $phoneNumber): string
+ public function denormalize(PhoneNumber $phoneNumber): string
{
- $phoneUtil = PhoneNumberUtil::getInstance();
-
- return $phoneUtil
- ->format(
- $phoneUtil->parse($phoneNumber),
- PhoneNumberFormat::E164
- );
+ return $this->format($phoneNumber);
}
/**
@@ -85,15 +83,10 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
* @return string
* @throws NumberParseException
*/
- public function format(string $phoneNumber): string
+ public function format(PhoneNumber $phoneNumber): string
{
- $phoneUtil = PhoneNumberUtil::getInstance();
-
- return $phoneUtil
- ->format(
- $phoneUtil->parse($phoneNumber, $this->config['default_carrier_code']),
- PhoneNumberFormat::NATIONAL
- );
+ return $this->phoneNumberUtil
+ ->formatOutOfCountryCallingNumber($phoneNumber, $this->config['default_carrier_code']);
}
/**
diff --git a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml
index f12cc47a3..df5ea3182 100644
--- a/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml
+++ b/src/Bundle/ChillMainBundle/config/services/phonenumber.yaml
@@ -7,6 +7,8 @@ services:
Chill\MainBundle\Phonenumber\PhonenumberHelper: ~
+ Chill\MainBundle\Phonenumber\Templating: ~
+
Chill\MainBundle\Validation\Validator\ValidPhonenumber:
tags:
- { name: validator.constraint_validator }
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig
index e21716d8e..e3280d755 100644
--- a/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig
+++ b/src/Bundle/ChillPersonBundle/Resources/views/Entity/person.html.twig
@@ -148,14 +148,14 @@
{% endif %}
{% if person.mobilenumber %}
-
- {{ person.mobilenumber|phone_number_format('NATIONAL') }}
+
+ {{ person.mobilenumber|chill_format_phonenumber }}
{% else %}
{% if person.phonenumber %}
-
- {{ person.phonenumber|phone_number_format('NATIONAL') }}
+
+ {{ person.phonenumber|chill_format_phonenumber }}
{% else %}
{{ 'No data given'|trans }}
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig
index e7fbc0228..b603dd70c 100644
--- a/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig
+++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/banner.html.twig
@@ -25,15 +25,15 @@
{% if person.phonenumber %}
-
- {{ person.phonenumber|phone_number_format('NATIONAL') }}
+
+ {{ person.phonenumber|chill_format_phonenumber }}
{% endif %}
{% if person.mobilenumber %}
-
- {{ person.mobilenumber|phone_number_format('NATIONAL') }}
+
+ {{ person.mobilenumber|chill_format_phonenumber }}
{% endif %}
{% if person.email %}
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_by_phonenumber.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_by_phonenumber.html.twig
index 83ee9fff9..642225571 100644
--- a/src/Bundle/ChillPersonBundle/Resources/views/Person/list_by_phonenumber.html.twig
+++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/list_by_phonenumber.html.twig
@@ -62,12 +62,12 @@
diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig
index 945984380..920705035 100644
--- a/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig
+++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/view.html.twig
@@ -232,14 +232,14 @@ This view should receive those arguments:
{%- if chill_person.fields.phonenumber == 'visible' -%}
- {{ 'Phonenumber'|trans }} :
- - {% if person.phonenumber is not empty %}
{{ person.phonenumber|phone_number_format('NATIONAL') }}
{% else %}{{ 'No data given'|trans }}{% endif %}
+ - {% if person.phonenumber is not empty %}{{ person.phonenumber|chill_format_phonenumber }}{% else %}{{ 'No data given'|trans }}{% endif %}
{% endif %}
{%- if chill_person.fields.mobilenumber == 'visible' -%}
- {{ 'Mobilenumber'|trans }} :
- - {% if person.mobilenumber is not empty %}{{ person.mobilenumber|phone_number_format('NATIONAL') }}{% else %}{{ 'No data given'|trans }}{% endif %}
+ - {% if person.mobilenumber is not empty %}{{ person.mobilenumber|chill_format_phonenumber }}{% else %}{{ 'No data given'|trans }}{% endif %}
{% if person.acceptSMS %}{{ 'Accept short text message'|trans }}{% endif %}
{% endif %}
@@ -250,7 +250,7 @@ This view should receive those arguments:
{{ 'Others phone numbers'|trans }} :
{% for el in person.otherPhoneNumbers %}
{% if el.phonenumber is not empty %}
- {% if el.description is not empty %}{{ el.description }} : {% endif %}{{ el.phonenumber|phone_number_format('NATIONAL') }}
+ {% if el.description is not empty %}{{ el.description }} : {% endif %}{{ el.phonenumber|chill_format_phonenumber }}
{% endif %}
{% endfor %}
@@ -317,4 +317,4 @@ This view should receive those arguments:
{% endif %}
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/src/Bundle/ChillPersonBundle/migrations/Version20220215135509.php b/src/Bundle/ChillPersonBundle/migrations/Version20220215135509.php
index cfcf3b78b..3c2a45e6c 100644
--- a/src/Bundle/ChillPersonBundle/migrations/Version20220215135509.php
+++ b/src/Bundle/ChillPersonBundle/migrations/Version20220215135509.php
@@ -23,10 +23,10 @@ final class Version20220215135509 extends AbstractMigration implements Container
$countryCode = $util->getCountryCodeForRegion($defaultCarriercode);
- return sprintf('%s=CASE WHEN
- LEFT(%s, 1) = \'0\'
- THEN
- \'%s\' || replace(replace(substr(%s, 2), \'(0)\', \'\'), \' \', \'\')
+ return sprintf('%s=CASE
+ WHEN %s = \'\' THEN NULL
+ WHEN LEFT(%s, 1) = \'0\'
+ THEN \'%s\' || replace(replace(substr(%s, 2), \'(0)\', \'\'), \' \', \'\')
ELSE replace(replace(%s, \'(0)\', \'\'),\' \', \'\')
END', $field, $field, $countryCode, $field, $field);
}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig
index 9fb55f71e..79aa7be6c 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/Entity/thirdparty.html.twig
@@ -111,7 +111,7 @@
{% if thirdparty.telephone %}
- {{ thirdparty.telephone|phone_number_format('NATIONAL') }}
+ {{ thirdparty.telephone|chill_format_phonenumber }}
{% else %}
{{ 'thirdparty.No_phonenumber'|trans }}
{% endif %}
@@ -136,7 +136,7 @@
{% if thirdparty.telephone %}
- {{ thirdparty.telephone|phone_number_format('NATIONAL') }}
+ {{ thirdparty.telephone|chill_format_phonenumber }}
{% else %}
{{ 'thirdparty.No_phonenumber'|trans }}
{% endif %}
diff --git a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/view.html.twig b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/view.html.twig
index 9157ff575..824438fa3 100644
--- a/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/view.html.twig
+++ b/src/Bundle/ChillThirdPartyBundle/Resources/views/ThirdParty/view.html.twig
@@ -69,8 +69,8 @@
{% if thirdParty.telephone == null %}
{{ 'No phone given'|trans }}
{% else %}
-
- {{ thirdParty.telephone|phone_number_format('NATIONAL') }}
+
+ {{ thirdParty.telephone|chill_print_or_message("thirdparty.No_phonenumber") }}
{% endif %}