diff --git a/app/composer.json b/app/composer.json index fe9de1b..6407d99 100644 --- a/app/composer.json +++ b/app/composer.json @@ -25,6 +25,7 @@ "symfony/webpack-encore-bundle": "^1.11", "symfony/yaml": "5.2.*", "twig/extra-bundle": "^2.12|^3.0", + "twig/intl-extra": "^3.3", "twig/twig": "^2.12|^3.0" }, "config": { diff --git a/app/composer.lock b/app/composer.lock index 402259f..5b874a6 100644 --- a/app/composer.lock +++ b/app/composer.lock @@ -5942,6 +5942,75 @@ ], "time": "2021-02-06T21:13:17+00:00" }, + { + "name": "twig/intl-extra", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/intl-extra.git", + "reference": "919e8f945c30bd3efeb6a4d79722cda538116658" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/intl-extra/zipball/919e8f945c30bd3efeb6a4d79722cda538116658", + "reference": "919e8f945c30bd3efeb6a4d79722cda538116658", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "symfony/intl": "^4.3|^5.0", + "twig/twig": "^2.4|^3.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4.9|^5.0.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Twig\\Extra\\Intl\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + } + ], + "description": "A Twig extension for Intl", + "homepage": "https://twig.symfony.com", + "keywords": [ + "intl", + "twig" + ], + "support": { + "source": "https://github.com/twigphp/intl-extra/tree/v3.3.0" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2021-01-01T14:58:18+00:00" + }, { "name": "twig/twig", "version": "v3.3.0", diff --git a/app/src/Form/BeerType.php b/app/src/Form/BeerType.php index b6b8d5b..447dbe2 100644 --- a/app/src/Form/BeerType.php +++ b/app/src/Form/BeerType.php @@ -4,6 +4,8 @@ namespace App\Form; use App\Entity\Beer; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\PercentType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -12,8 +14,11 @@ class BeerType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name') - ->add('alcool') + ->add('name', TextType::class) + ->add('alcool', PercentType::class, [ + 'scale' => 1, + 'type' => 'fractional', + ]) ; } diff --git a/app/symfony.lock b/app/symfony.lock index bd86f8e..7fc80d3 100644 --- a/app/symfony.lock +++ b/app/symfony.lock @@ -385,6 +385,9 @@ "twig/extra-bundle": { "version": "v3.3.0" }, + "twig/intl-extra": { + "version": "v3.3.0" + }, "twig/twig": { "version": "v3.3.0" } diff --git a/app/templates/beer/index.html.twig b/app/templates/beer/index.html.twig index af0fc7b..e94cab7 100644 --- a/app/templates/beer/index.html.twig +++ b/app/templates/beer/index.html.twig @@ -22,7 +22,7 @@ {{ beer.id }} {{ beer.name }} - {{ beer.alcool }} + {{ beer.alcool|format_percent_number({rounding_mode: 'floor', fraction_digit: 1}) }} diff --git a/app/templates/beer/show.html.twig b/app/templates/beer/show.html.twig index 51b0593..fd315fd 100644 --- a/app/templates/beer/show.html.twig +++ b/app/templates/beer/show.html.twig @@ -19,7 +19,7 @@ {{'Alcool'}} - {{ beer.alcool }} + {{ beer.alcool|format_percent_number({rounding_mode: 'floor', fraction_digit: 1}) }}