From 39b5ac311972246431b7ec1339f98eef0fa9a902 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Proch=C3=A1zka?= Date: Tue, 20 Feb 2024 15:07:37 +0100 Subject: [PATCH] Added custom control alias for country list --- src/DI/ControlFactory.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/DI/ControlFactory.php b/src/DI/ControlFactory.php index c7d2879..46776db 100644 --- a/src/DI/ControlFactory.php +++ b/src/DI/ControlFactory.php @@ -8,7 +8,9 @@ namespace JuniWalk\Form\DI; use JuniWalk\Form\Controls; +use JuniWalk\Utils\Country; use Nette\Forms\Container as Form; +use Nette\Forms\Controls\SelectBox; final class ControlFactory { @@ -17,6 +19,7 @@ public static function registerControls(): void static $methods = [ 'addDateTime', 'addPhoneNumber', + 'addSelectCountry', 'addSelectEnum', 'addRadioEnum', 'addCheckboxEnum', @@ -53,6 +56,22 @@ public static function addPhoneNumber( } + public static function addSelectCountry( + Form $form, + string $name, + ?array $items = null, + ?string $lang = null, + ) { + $lang ??= $form->getTranslator()?->getLocale(); + + if (!$items && class_exists(Country::class)) { + $items = Country::getList($lang); + } + + return $form->addSelect($name)->setItems($items); + } + + public static function addSelectEnum( Form $form, string $name,