update kirby to v5 and add refresh cache panel view button
This commit is contained in:
commit
9a86d41254
466 changed files with 19960 additions and 10497 deletions
|
|
@ -2,10 +2,8 @@
|
|||
|
||||
namespace Kirby\Option;
|
||||
|
||||
use Kirby\Blueprint\Factory;
|
||||
use Kirby\Blueprint\NodeIcon;
|
||||
use Kirby\Blueprint\NodeText;
|
||||
use Kirby\Cms\ModelWithContent;
|
||||
use Kirby\Toolkit\I18n;
|
||||
|
||||
/**
|
||||
* Option for select fields, radio fields, etc.
|
||||
|
|
@ -18,14 +16,16 @@ use Kirby\Cms\ModelWithContent;
|
|||
*/
|
||||
class Option
|
||||
{
|
||||
public string|array $text;
|
||||
|
||||
public function __construct(
|
||||
public string|int|float|null $value,
|
||||
public bool $disabled = false,
|
||||
public NodeIcon|null $icon = null,
|
||||
public NodeText|null $info = null,
|
||||
public NodeText|null $text = null
|
||||
public string|null $icon = null,
|
||||
public string|array|null $info = null,
|
||||
string|array|null $text = null
|
||||
) {
|
||||
$this->text ??= new NodeText(['en' => $this->value]);
|
||||
$this->text = $text ?? ['en' => $this->value];
|
||||
}
|
||||
|
||||
public static function factory(string|int|float|array|null $props): static
|
||||
|
|
@ -34,11 +34,25 @@ class Option
|
|||
$props = ['value' => $props];
|
||||
}
|
||||
|
||||
$props = Factory::apply($props, [
|
||||
'icon' => NodeIcon::class,
|
||||
'info' => NodeText::class,
|
||||
'text' => NodeText::class
|
||||
]);
|
||||
// Normalize info to be an array
|
||||
if (isset($props['info']) === true) {
|
||||
$props['info'] = match (true) {
|
||||
is_array($props['info']) => $props['info'],
|
||||
$props['info'] === null,
|
||||
$props['info'] === false => null,
|
||||
default => ['en' => $props['info']]
|
||||
};
|
||||
}
|
||||
|
||||
// Normalize text to be an array
|
||||
if (isset($props['text']) === true) {
|
||||
$props['text'] = match (true) {
|
||||
is_array($props['text']) => $props['text'],
|
||||
$props['text'] === null,
|
||||
$props['text'] === false => null,
|
||||
default => ['en' => $props['text']]
|
||||
};
|
||||
}
|
||||
|
||||
return new static(...$props);
|
||||
}
|
||||
|
|
@ -53,11 +67,14 @@ class Option
|
|||
*/
|
||||
public function render(ModelWithContent $model): array
|
||||
{
|
||||
$info = I18n::translate($this->info, $this->info);
|
||||
$text = I18n::translate($this->text, $this->text);
|
||||
|
||||
return [
|
||||
'disabled' => $this->disabled,
|
||||
'icon' => $this->icon?->render($model),
|
||||
'info' => $this->info?->render($model),
|
||||
'text' => $this->text?->render($model),
|
||||
'icon' => $this->icon,
|
||||
'info' => $info ? $model->toSafeString($info) : $info,
|
||||
'text' => $text ? $model->toSafeString($text) : $text,
|
||||
'value' => $this->value
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
namespace Kirby\Option;
|
||||
|
||||
use Kirby\Blueprint\Collection;
|
||||
use Kirby\Cms\Collection;
|
||||
use Kirby\Cms\ModelWithContent;
|
||||
use Kirby\Toolkit\A;
|
||||
|
||||
/**
|
||||
* Collection of possible options for
|
||||
|
|
@ -14,11 +15,11 @@ use Kirby\Cms\ModelWithContent;
|
|||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*
|
||||
* @extends \Kirby\Cms\Collection<\Kirby\Option\Option>
|
||||
*/
|
||||
class Options extends Collection
|
||||
{
|
||||
public const TYPE = Option::class;
|
||||
|
||||
public function __construct(array $objects = [])
|
||||
{
|
||||
foreach ($objects as $object) {
|
||||
|
|
@ -26,6 +27,18 @@ class Options extends Collection
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The Kirby Collection class only shows the key to
|
||||
* avoid huge trees when dumping, but for the options
|
||||
* collections this is really not useful
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __debugInfo(): array
|
||||
{
|
||||
return A::map($this->data, fn ($item) => (array)$item);
|
||||
}
|
||||
|
||||
public static function factory(array $items = []): static
|
||||
{
|
||||
$collection = new static();
|
||||
|
|
@ -52,6 +65,12 @@ class Options extends Collection
|
|||
|
||||
public function render(ModelWithContent $model): array
|
||||
{
|
||||
return array_values(parent::render($model));
|
||||
$options = [];
|
||||
|
||||
foreach ($this->data as $key => $option) {
|
||||
$options[$key] = $option->render($model);
|
||||
}
|
||||
|
||||
return array_values($options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,9 @@ class OptionsApi extends OptionsProvider
|
|||
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($data === null) {
|
||||
throw new NotFoundException('Options could not be loaded from API: ' . $model->toSafeString($this->url));
|
||||
throw new NotFoundException(
|
||||
message: 'Options could not be loaded from API: ' . $model->toSafeString($this->url)
|
||||
);
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
|
|
|
|||
|
|
@ -163,9 +163,11 @@ class OptionsQuery extends OptionsProvider
|
|||
}
|
||||
|
||||
if ($result instanceof Collection === false) {
|
||||
$type = is_object($result) === true ? get_class($result) : gettype($result);
|
||||
$type = is_object($result) === true ? $result::class : gettype($result);
|
||||
|
||||
throw new InvalidArgumentException('Invalid query result data: ' . $type);
|
||||
throw new InvalidArgumentException(
|
||||
message: 'Invalid query result data: ' . $type
|
||||
);
|
||||
}
|
||||
|
||||
// create options array
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue