Upgrade to 3.9.0
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user