Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix template caching, allow app to be released #1961

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/HtmlTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/Table/Column/CountryFlag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down