-
Notifications
You must be signed in to change notification settings - Fork 106
/
CountryFlag.php
33 lines (26 loc) · 979 Bytes
/
CountryFlag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
declare(strict_types=1);
namespace Atk4\Ui\Table\Column;
use Atk4\Data\Field;
use Atk4\Data\Model;
use Atk4\Ui\Table;
class CountryFlag extends Table\Column
{
/** Name of country code model field (in ISO 3166-1 alpha-2 format) */
public ?string $codeField = null;
/** Optional name of model field which contains full country name. */
public ?string $nameField = null;
public function getHtmlTags(Model $row, ?Field $field): array
{
$countryCode = $row->get($this->codeField ?? $field->shortName);
$countryName = $this->nameField ? $row->get($this->nameField) : null;
return [
$field->shortName => $countryCode === null
? ''
: $this->getApp()->getTag('i', [
'class' => strtolower($countryCode) . ' flag',
'title' => strtoupper($countryCode) . ($countryName === null ? '' : ' - ' . $countryName),
]),
];
}
}