diff --git a/src/Cms/System/UpdateStatus.php b/src/Cms/System/UpdateStatus.php index 41f784747e..3af55c25ff 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 diff --git a/src/Option/OptionsApi.php b/src/Option/OptionsApi.php index c4f96bf6f9..2470e02b4b 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 ); } @@ -140,7 +144,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' => $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 7d570fecea..85257aaf4f 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 ); } @@ -180,7 +184,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 = $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'); }); return $this->options = Options::factory($options); 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 [