Skip to content

Commit

Permalink
Merge branch 'develop-minor' into v5/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Nov 12, 2024
2 parents 043681b + 66d07f3 commit ee93089
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Cms/System/UpdateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/Option/OptionsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

Expand All @@ -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
);
}

Expand Down Expand Up @@ -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
];
}

Expand Down
16 changes: 12 additions & 4 deletions src/Option/OptionsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

Expand All @@ -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
);
}

Expand Down Expand Up @@ -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);
Expand Down
71 changes: 71 additions & 0 deletions tests/Form/Fields/SelectFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down

0 comments on commit ee93089

Please sign in to comment.