powderblue/sf-continent-country-type

There is no license information available for the latest version (v3.0.0) of this package.

v3.0.0 2024-04-02 15:27 UTC

This package is auto-updated.

Last update: 2024-04-02 15:29:06 UTC


README

Introduction

This is a Symfony 4/5 bundle that provides a new form-type called "ContinentCountryType". This type is like Symfony's CountryType but allows developers to group countries by continent. The list of countries and continents that are displayed can be easily customised.

Screenshots

Example of a dropdown with countries grouped by continent: dropdown with countries grouped by continent

Example of a 'simple' country dropdown: simple country dropdown

Note: In the examples, above, Select2 has been used to render the dropdown lists

Installation

  • Run composer require powderblue/sf-continent-country-type
  • Update your project app/AppKernel.php file and add the bundle to the $bundles array:
$bundles = [
    // ...
    new PowderBlue\SfContinentCountryTypeBundle\PowderBlueSfContinentCountryTypeBundle(),
];

How to Use

In the buildForm method of a form-type class, specify ContinentCountryType::class as the type.

use PowderBlue\SfContinentCountryTypeBundle\Form\Type\ContinentCountryType;

// ...

$builder
    // ...
    ->add('country', ContinentCountryType::class, [
        'label' => 'Country',
        'attr' => [
            'placeholder' => 'Country',
        ],
    ])
;

Configuration

Below you can find a reference of all configuration options with their default values:

# config.yml

powder_blue_sf_continent_country_type:
    # The path of the file containing the countries (and continents) that should appear in the dropdown
    file: "%bundle_root_dir%/Resources/data/continent_country.csv"

    # Group the countries by continent in the dropdown?
    group_by_continent: true

    # The ID of the service used to parse the countries file.  It should implement `...\Provider\ContinentCountryProviderInterface`.
    provider: powder_blue_sf_continent_country_type.provider.continent_country_csv_file