Emoji flag in the Symfony CountryType

Smaine Milianni
2 min readJan 30, 2022

🔥 Emojis are part of our way of communicating, what about adding them to your Symfony form when a user needs to select a country, something like:

It’s easy to create an emoji from the ISO country code, check this comment.

TL;DR: In PHP the code is

Try it here 👀

Now we know how to output a flag from a country code let’s create a new Symfony form type, the EmojiType ✨

1- Create the FormType 🖊

The EmojiTypeshould extend the AbstractType and define the method getParent that returns CountryType to take benefit of the CountryType configuration (options, select…). We also add our helper that transforms a country code into an emoji.

--

--

Smaine Milianni

Fullstack Developer- certified Symfony 4,5 and certified AWS Solution Architect - Freelancer - Remote Worker