Upgrade to 3.9.0

This commit is contained in:
Bastian Allgeier
2023-01-17 14:50:16 +01:00
parent 0ebe0c7b16
commit 6e5c9d1f48
132 changed files with 1664 additions and 1254 deletions

View File

@@ -6,6 +6,7 @@ use Kirby\Blueprint\Node;
use Kirby\Cms\ModelWithContent;
use Kirby\Option\Options;
use Kirby\Option\OptionsApi;
use Kirby\Option\OptionsProvider;
use Kirby\Option\OptionsQuery;
/**
@@ -20,7 +21,18 @@ use Kirby\Option\OptionsQuery;
class FieldOptions extends Node
{
public function __construct(
public Options|OptionsApi|OptionsQuery|null $options = null
/**
* The option source, either a fixed collection or
* a dynamic provider
*/
public Options|OptionsProvider|null $options = null,
/**
* Whether to escape special HTML characters in
* the option text for safe output in the Panel;
* only set to `false` if the text is later escaped!
*/
public bool $safeMode = true
) {
}
@@ -31,7 +43,7 @@ class FieldOptions extends Node
return parent::defaults();
}
public static function factory(array $props): static
public static function factory(array $props, bool $safeMode = true): static
{
$options = match ($props['type']) {
'api' => OptionsApi::factory($props),
@@ -39,20 +51,23 @@ class FieldOptions extends Node
default => Options::factory($props['options'] ?? [])
};
return new static($options);
return new static($options, $safeMode);
}
public static function polyfill(array $props = []): array
{
if (is_string($props['options'] ?? null) === true) {
$props['options'] = match ($props['options']) {
'api' => ['type' => 'api'] +
OptionsApi::polyfill($props['api'] ?? null),
'api' =>
['type' => 'api'] +
OptionsApi::polyfill($props['api'] ?? null),
'query' => ['type' => 'query'] +
OptionsQuery::polyfill($props['query'] ?? null),
'query' =>
['type' => 'query'] +
OptionsQuery::polyfill($props['query'] ?? null),
default => [ 'type' => 'query', 'query' => $props['options']]
default =>
[ 'type' => 'query', 'query' => $props['options']]
};
}
@@ -82,8 +97,8 @@ class FieldOptions extends Node
return $this->options;
}
// resolve OptionsApi or OptionsQuery to Options
return $this->options = $this->options->resolve($model);
// resolve OptionsProvider (OptionsApi or OptionsQuery) to Options
return $this->options = $this->options->resolve($model, $this->safeMode);
}
public function render(ModelWithContent $model): array