Skip to content

Commit 9e5f515

Browse files
committed
Merge branch 'develop'
2 parents e474216 + e244add commit 9e5f515

File tree

4 files changed

+35
-36
lines changed

4 files changed

+35
-36
lines changed

demos/collection/grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
// add country flag column
3131
$grid->addColumn('flag', [
32-
Table\Column\Flag::class,
32+
Table\Column\CountryFlag::class,
3333
'codeField' => $model->fieldName()->iso,
3434
'nameField' => $model->fieldName()->name,
3535
]);

demos/collection/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'neverPersist' => true, // no need for actual value in this field
1616
'ui' => [
1717
'table' => [
18-
Table\Column\Flag::class,
18+
Table\Column\CountryFlag::class,
1919
[
2020
'codeField' => $m->fieldName()->iso,
2121
'nameField' => $m->fieldName()->name,

src/Table/Column/CountryFlag.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Atk4\Ui\Table\Column;
6+
7+
use Atk4\Data\Field;
8+
use Atk4\Data\Model;
9+
use Atk4\Ui\Table;
10+
11+
class CountryFlag extends Table\Column
12+
{
13+
/** Name of country code model field (in ISO 3166-1 alpha-2 format) */
14+
public string $codeField;
15+
16+
/** Optional name of model field which contains full country name. */
17+
public ?string $nameField = null;
18+
19+
public function getHtmlTags(Model $row, ?Field $field): array
20+
{
21+
$countryCode = $row->get($this->codeField);
22+
$countryName = $this->nameField ? $row->get($this->nameField) : null;
23+
24+
return [
25+
$field->shortName => $countryCode === null
26+
? ''
27+
: $this->getApp()->getTag('i', [
28+
'class' => strtolower($countryCode) . ' flag',
29+
'title' => strtoupper($countryCode) . ($countryName === null ? '' : ' - ' . $countryName),
30+
]),
31+
];
32+
}
33+
}

src/Table/Column/Flag.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)