Skip to content

Commit 7a37375

Browse files
committed
Add CountryOptions ViewModel for usage in filters
1 parent 87ee89e commit 7a37375

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Loki\AdminComponents\ViewModel\Options;
4+
5+
use Magento\Directory\Helper\Data as DirectoryHelper;
6+
use Magento\Framework\Data\OptionSourceInterface;
7+
use Magento\Framework\View\Element\Block\ArgumentInterface;
8+
9+
class CountryOptions implements ArgumentInterface, OptionSourceInterface
10+
{
11+
public function __construct(
12+
private readonly DirectoryHelper $directoryHelper,
13+
) {
14+
}
15+
16+
public function toOptionArray()
17+
{
18+
$options = [];
19+
$options[] = [
20+
'value' => '',
21+
'label' => '',
22+
];
23+
24+
foreach ($this->directoryHelper->getCountryCollection() as $country) {
25+
$options[] = [
26+
'value' => $country->getCountryId(),
27+
'label' => $country->getName(),
28+
];
29+
30+
}
31+
32+
asort($options);
33+
34+
return $options;
35+
}
36+
}

0 commit comments

Comments
 (0)