fulgens-sprl / input-phone-by-country-bundle
This helps your user to enter a phone number with the correct pre-fix
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1.3
- symfony/config: ^3.4 || ^4.0
- symfony/dependency-injection: ^3.4 || ^4.0
- symfony/form: ^3.4 || ^4.0
- symfony/http-kernel: ^3.4 || ^4.0
Requires (Dev)
- symfony/phpunit-bridge: ^3.4 || ^4.0
This package is auto-updated.
Last update: 2024-04-28 04:46:14 UTC
README
This small bundle adds a new input type for your Symfony 3 or 4 application. The input contains the country code of the phone number in a select/option and the rest of the number in an input text.
Installing
To add the bundle, use composer
composer require fulgens-sprl/input-phone-by-country-bundle
And that's it! If you're not ysubg Symfony Flex, you'll also need to enable the Fulgens\InputPhoneByCountryBundle
in your AppKernel.php
file.
Usage
Just as a common FormType element :
// src/Form/Type use Fulgens\InputPhoneByCountryBundle\Form\PhoneByCountryType; // ... class MyFormType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { ... $builder->add("phoneByCountry", PhoneByCountryType::class); ... } }
If you want to use the bundle as provided, you have nothing to do more.
How can I use my own CountryProvider ?
If you want to use another CountryProvider, first, create your own Provider and implement the CountryProviderInterface
// src/Form/TypeMyOwnCountryProvider use Fulgens\InputPhoneByCountryBundle\Entity\Country; // ... class MyOwnCountryProvider implements CountryProviderInterface { //This method must return an array of CountryInterface public function getCountries(): array { // ... return [...]; } }
Note that you MUST return an array of CountryInterface entities.
Then, in the config/packages/fulgens_input_phone_by_country.yaml
, specify your new service (create a new file if it isn't already there):
fulgens_input_phone_by_country: country_provider: Namespace\To\MyOwnCountryProvider
Running the tests
To run the tests, use
./vendor/bin/simple-phpunit
Authors
- Alexandre Castelain - Author - For Fulgens
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Acknowledgments
- This bundle is my first Bundle, so it might have problems, don't hesitate to contact me if you notice any wrong information.