From bd708636d2efcba85e1354e50e78243f4b07d887 Mon Sep 17 00:00:00 2001 From: Ahmet Bora Date: Tue, 5 Nov 2024 23:35:37 +0300 Subject: [PATCH 1/3] Support `icon` and `info` for query and api options #6780 --- src/Option/OptionsApi.php | 17 ++++++++++++----- src/Option/OptionsQuery.php | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Option/OptionsApi.php b/src/Option/OptionsApi.php index a3b7ae8809..3d357e2892 100644 --- a/src/Option/OptionsApi.php +++ b/src/Option/OptionsApi.php @@ -28,7 +28,9 @@ public function __construct( public string $url, public string|null $query = null, public string|null $text = null, - public string|null $value = null + public string|null $value = null, + public string|null $icon = null, + public string|null $info = null ) { } @@ -46,10 +48,12 @@ public static function factory(string|array $props): static } return new static( - url: $props['url'], + url : $props['url'], query: $props['query'] ?? $props['fetch'] ?? null, - text: $props['text'] ?? null, - value: $props['value'] ?? null + text : $props['text'] ?? null, + value: $props['value'] ?? null, + icon : $props['icon'] ?? null, + info : $props['info'] ?? null ); } @@ -138,7 +142,10 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options 'value' => $model->toString($this->value, ['item' => $item]), // text is only a raw string when using {< >} // or when the safe mode is explicitly disabled (select field) - 'text' => $model->$safeMethod($this->text, ['item' => $item]) + 'text' => $model->$safeMethod($this->text, ['item' => $item]), + // additional data + 'icon' => $model->toString($this->icon, ['item' => $item]), + 'info' => $model->$safeMethod($this->info, ['item' => $item]) ]; } diff --git a/src/Option/OptionsQuery.php b/src/Option/OptionsQuery.php index 77312c4ce5..2d36145c14 100644 --- a/src/Option/OptionsQuery.php +++ b/src/Option/OptionsQuery.php @@ -30,7 +30,9 @@ class OptionsQuery extends OptionsProvider public function __construct( public string $query, public string|null $text = null, - public string|null $value = null + public string|null $value = null, + public string|null $icon = null, + public string|null $info = null ) { } @@ -56,8 +58,10 @@ public static function factory(string|array $props): static return new static( query: $props['query'] ?? $props['fetch'], - text: $props['text'] ?? null, - value: $props['value'] ?? null + text : $props['text'] ?? null, + value: $props['value'] ?? null, + icon : $props['icon'] ?? null, + info : $props['info'] ?? null ); } @@ -178,7 +182,11 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options $safeMethod = $safeMode === true ? 'toSafeString' : 'toString'; $text = $model->$safeMethod($this->text ?? $text, $data); - return compact('text', 'value'); + // additional data + $icon = $model->toString($this->icon, $data); + $info = $model->$safeMethod($this->info, $data); + + return compact('text', 'value', 'icon', 'info'); }); return $this->options = Options::factory($options); From d3dba8277ce40dcfd23040bc6e98fb369adbaf3b Mon Sep 17 00:00:00 2001 From: Ahmet Bora Date: Mon, 11 Nov 2024 15:39:03 +0300 Subject: [PATCH 2/3] Add unit test for additional options data --- src/Option/OptionsApi.php | 4 +- src/Option/OptionsQuery.php | 4 +- tests/Form/Fields/SelectFieldTest.php | 71 +++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/Option/OptionsApi.php b/src/Option/OptionsApi.php index 3d357e2892..3c8353853a 100644 --- a/src/Option/OptionsApi.php +++ b/src/Option/OptionsApi.php @@ -144,8 +144,8 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options // or when the safe mode is explicitly disabled (select field) 'text' => $model->$safeMethod($this->text, ['item' => $item]), // additional data - 'icon' => $model->toString($this->icon, ['item' => $item]), - 'info' => $model->$safeMethod($this->info, ['item' => $item]) + 'icon' => $this->icon !== null ? $model->toString($this->icon, ['item' => $item]) : null, + 'info' => $this->info !== null ? $model->$safeMethod($this->info, ['item' => $item]) : null ]; } diff --git a/src/Option/OptionsQuery.php b/src/Option/OptionsQuery.php index 2d36145c14..9ffdbaaf15 100644 --- a/src/Option/OptionsQuery.php +++ b/src/Option/OptionsQuery.php @@ -183,8 +183,8 @@ public function resolve(ModelWithContent $model, bool $safeMode = true): Options $text = $model->$safeMethod($this->text ?? $text, $data); // additional data - $icon = $model->toString($this->icon, $data); - $info = $model->$safeMethod($this->info, $data); + $icon = $this->icon !== null ? $model->toString($this->icon, $data) : null; + $info = $this->info !== null ? $model->$safeMethod($this->info, $data) : null; return compact('text', 'value', 'icon', 'info'); }); diff --git a/tests/Form/Fields/SelectFieldTest.php b/tests/Form/Fields/SelectFieldTest.php index ecb56ad784..a55d5fffbc 100644 --- a/tests/Form/Fields/SelectFieldTest.php +++ b/tests/Form/Fields/SelectFieldTest.php @@ -112,6 +112,77 @@ public function testOptionsQuery() $this->assertSame($expected, $field->options()); } + public function testOptionsQueryAdditionalData() + { + $this->app()->clone([ + 'site' => [ + 'children' => [ + [ + 'slug' => 'a', + 'content' => [ + 'title' => 'Title A', + 'icon' => 'page', + 'headline' => 'some a headline' + ] + ], + [ + 'slug' => 'b', + 'content' => [ + 'title' => 'Title B', + 'icon' => 'user', + 'headline' => 'some b headline' + ], + ], + [ + 'slug' => 'c', + 'content' => [ + 'title' => 'Title C', + 'icon' => 'file', + 'headline' => 'some c headline' + ], + ] + ] + ] + ]); + + $expected = [ + [ + 'disabled' => false, + 'icon' => 'page', + 'info' => 'some a headline', + 'text' => 'Title A', + 'value' => 'a' + ], + [ + 'disabled' => false, + 'icon' => 'user', + 'info' => 'some b headline', + 'text' => 'Title B', + 'value' => 'b' + ], + [ + 'disabled' => false, + 'icon' => 'file', + 'info' => 'some c headline', + 'text' => 'Title C', + 'value' => 'c' + ] + ]; + + $field = $this->field('select', [ + 'options' => [ + 'type' => 'query', + 'query' => 'site.children', + 'info' => '{{ item.headline }}', + 'icon' => '{{ item.icon }}', + 'text' => '{{ item.title }}', + 'value' => '{{ item.slug }}', + ] + ]); + + $this->assertSame($expected, $field->options()); + } + public static function valueInputProvider(): array { return [ From 9a9445033200a1537d1436c5c3c36d7ebf47de2b Mon Sep 17 00:00:00 2001 From: Bastian Allgeier Date: Tue, 12 Nov 2024 09:44:14 +0100 Subject: [PATCH 3/3] Change the update status host to getkirby.com --- src/Cms/System/UpdateStatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cms/System/UpdateStatus.php b/src/Cms/System/UpdateStatus.php index 8adf65df0b..0579f68aef 100644 --- a/src/Cms/System/UpdateStatus.php +++ b/src/Cms/System/UpdateStatus.php @@ -26,7 +26,7 @@ class UpdateStatus /** * Host to request the update data from */ - public static string $host = 'https://assets.getkirby.com'; + public static string $host = 'https://getkirby.com'; /** * Marker that stores whether a previous remote