diff --git a/demos/init-db.php b/demos/init-db.php index ba2e6ec078..5280f87717 100644 --- a/demos/init-db.php +++ b/demos/init-db.php @@ -9,6 +9,7 @@ use Atk4\Data\Model; use Atk4\Ui\Exception; use Atk4\Ui\Form; +use Atk4\Ui\Table; use Mvorisek\Atk4\Hintable\Data\HintablePropertyDef; try { @@ -269,6 +270,7 @@ protected function init(): void 'type' => 'string', 'ui' => [ 'form' => [Form\Control\Line::class], + 'table' => [Table\Column\CountryFlag::class], ], ]) ->addField($this->fieldName()->client_country, Country::hinting()->fieldName()->name); diff --git a/src/HtmlTemplate.php b/src/HtmlTemplate.php index 9a20ea7396..5d51e42d39 100644 --- a/src/HtmlTemplate.php +++ b/src/HtmlTemplate.php @@ -456,7 +456,13 @@ protected function parseTemplate(string $str): void $this->tagTrees = []; try { $this->tagTrees[self::TOP_TAG] = $this->parseTemplateTree($inputReversed); - self::$_parseCache[$cKey] = $this->tagTrees; + $tagTrees = $this->tagTrees; + \Closure::bind(function () use ($tagTrees) { + foreach ($tagTrees as $tagTree) { + $tagTree->parentTemplate = null; // @phpstan-ignore-line + } + }, null, TagTree::class)(); + self::$_parseCache[$cKey] = $tagTrees; } finally { $this->tagTrees = null; // @phpstan-ignore-line } diff --git a/src/Table/Column/CountryFlag.php b/src/Table/Column/CountryFlag.php index 18b9803b77..0926d95ad7 100644 --- a/src/Table/Column/CountryFlag.php +++ b/src/Table/Column/CountryFlag.php @@ -11,14 +11,14 @@ class CountryFlag extends Table\Column { /** Name of country code model field (in ISO 3166-1 alpha-2 format) */ - public string $codeField; + 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); + $countryCode = $row->get($this->codeField ?? $field->shortName); $countryName = $this->nameField ? $row->get($this->nameField) : null; return [