Skip to content

Commit

Permalink
Added custom control alias for country list
Browse files Browse the repository at this point in the history
  • Loading branch information
juniwalk authored Feb 20, 2024
1 parent 471258b commit 39b5ac3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/DI/ControlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -17,6 +19,7 @@ public static function registerControls(): void
static $methods = [
'addDateTime',
'addPhoneNumber',
'addSelectCountry',
'addSelectEnum',
'addRadioEnum',
'addCheckboxEnum',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 39b5ac3

Please sign in to comment.