Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Dec 29, 2022
2 parents e474216 + e244add commit 24603b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion demos/collection/grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// add country flag column
$grid->addColumn('flag', [
Table\Column\Flag::class,
Table\Column\CountryFlag::class,
'codeField' => $model->fieldName()->iso,
'nameField' => $model->fieldName()->name,
]);
Expand Down
33 changes: 33 additions & 0 deletions src/Table/Column/CountryFlag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;

/** 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);
$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),
]),
];
}
}

0 comments on commit 24603b9

Please sign in to comment.