Skip to content

Commit 5d1bf4c

Browse files
authored
Fix template caching, allow app to be released (#1961)
1 parent 9041368 commit 5d1bf4c

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

demos/init-db.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Atk4\Data\Model;
1010
use Atk4\Ui\Exception;
1111
use Atk4\Ui\Form;
12+
use Atk4\Ui\Table;
1213
use Mvorisek\Atk4\Hintable\Data\HintablePropertyDef;
1314

1415
try {
@@ -269,6 +270,7 @@ protected function init(): void
269270
'type' => 'string',
270271
'ui' => [
271272
'form' => [Form\Control\Line::class],
273+
'table' => [Table\Column\CountryFlag::class],
272274
],
273275
])
274276
->addField($this->fieldName()->client_country, Country::hinting()->fieldName()->name);

src/HtmlTemplate.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,13 @@ protected function parseTemplate(string $str): void
456456
$this->tagTrees = [];
457457
try {
458458
$this->tagTrees[self::TOP_TAG] = $this->parseTemplateTree($inputReversed);
459-
self::$_parseCache[$cKey] = $this->tagTrees;
459+
$tagTrees = $this->tagTrees;
460+
\Closure::bind(function () use ($tagTrees) {
461+
foreach ($tagTrees as $tagTree) {
462+
$tagTree->parentTemplate = null; // @phpstan-ignore-line
463+
}
464+
}, null, TagTree::class)();
465+
self::$_parseCache[$cKey] = $tagTrees;
460466
} finally {
461467
$this->tagTrees = null; // @phpstan-ignore-line
462468
}

src/Table/Column/CountryFlag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
class CountryFlag extends Table\Column
1212
{
1313
/** Name of country code model field (in ISO 3166-1 alpha-2 format) */
14-
public string $codeField;
14+
public ?string $codeField = null;
1515

1616
/** Optional name of model field which contains full country name. */
1717
public ?string $nameField = null;
1818

1919
public function getHtmlTags(Model $row, ?Field $field): array
2020
{
21-
$countryCode = $row->get($this->codeField);
21+
$countryCode = $row->get($this->codeField ?? $field->shortName);
2222
$countryName = $this->nameField ? $row->get($this->nameField) : null;
2323

2424
return [

0 commit comments

Comments
 (0)