composer update
This commit is contained in:
parent
0b3c362c5e
commit
a1f0701630
142 changed files with 4530 additions and 1195 deletions
74
public/kirby/src/Form/Field/StatsField.php
Normal file
74
public/kirby/src/Form/Field/StatsField.php
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Field;
|
||||
|
||||
use Kirby\Form\FieldClass;
|
||||
use Kirby\Panel\Ui\Stats;
|
||||
|
||||
/**
|
||||
* Stats field
|
||||
*
|
||||
* @package Kirby Field
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://getkirby.com/license
|
||||
* @since 5.1.0
|
||||
*/
|
||||
class StatsField extends FieldClass
|
||||
{
|
||||
/**
|
||||
* Array or query string for reports. Each report needs a `label` and `value` and can have additional `info`, `link`, `icon` and `theme` settings.
|
||||
*/
|
||||
protected array|string $reports;
|
||||
|
||||
/**
|
||||
* The size of the report cards. Available sizes: `tiny`, `small`, `medium`, `large`
|
||||
*/
|
||||
protected string $size;
|
||||
|
||||
/**
|
||||
* Cache for the Stats UI component
|
||||
*/
|
||||
protected Stats $stats;
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
$this->reports = $params['reports'] ?? [];
|
||||
$this->size = $params['size'] ?? 'large';
|
||||
}
|
||||
|
||||
public function hasValue(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function reports(): array
|
||||
{
|
||||
return $this->stats()->reports();
|
||||
}
|
||||
|
||||
public function size(): string
|
||||
{
|
||||
return $this->stats()->size();
|
||||
}
|
||||
|
||||
public function stats(): Stats
|
||||
{
|
||||
return $this->stats ??= Stats::from(
|
||||
model: $this->model,
|
||||
reports: $this->reports,
|
||||
size: $this->size
|
||||
);
|
||||
}
|
||||
|
||||
public function props(): array
|
||||
{
|
||||
return [
|
||||
...parent::props(),
|
||||
...$this->stats()->props()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ namespace Kirby\Form;
|
|||
|
||||
use Kirby\Cms\HasSiblings;
|
||||
use Kirby\Toolkit\I18n;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* Abstract field class to be used instead
|
||||
|
|
@ -22,24 +21,24 @@ use Kirby\Toolkit\Str;
|
|||
abstract class FieldClass
|
||||
{
|
||||
use HasSiblings;
|
||||
use Mixin\After;
|
||||
use Mixin\Api;
|
||||
use Mixin\Autofocus;
|
||||
use Mixin\Before;
|
||||
use Mixin\Help;
|
||||
use Mixin\Icon;
|
||||
use Mixin\Label;
|
||||
use Mixin\Model;
|
||||
use Mixin\Placeholder;
|
||||
use Mixin\Translatable;
|
||||
use Mixin\Validation;
|
||||
use Mixin\Value;
|
||||
use Mixin\When;
|
||||
use Mixin\Width;
|
||||
|
||||
protected string|null $after;
|
||||
protected bool $autofocus;
|
||||
protected string|null $before;
|
||||
protected bool $disabled;
|
||||
protected string|null $help;
|
||||
protected string|null $icon;
|
||||
protected string|null $label;
|
||||
protected string|null $name;
|
||||
protected string|null $placeholder;
|
||||
protected Fields $siblings;
|
||||
protected string|null $width;
|
||||
|
||||
public function __construct(
|
||||
protected array $params = []
|
||||
|
|
@ -75,21 +74,6 @@ abstract class FieldClass
|
|||
return $this->params[$param] ?? null;
|
||||
}
|
||||
|
||||
public function after(): string|null
|
||||
{
|
||||
return $this->stringTemplate($this->after);
|
||||
}
|
||||
|
||||
public function autofocus(): bool
|
||||
{
|
||||
return $this->autofocus;
|
||||
}
|
||||
|
||||
public function before(): string|null
|
||||
{
|
||||
return $this->stringTemplate($this->before);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns optional dialog routes for the field
|
||||
*/
|
||||
|
|
@ -114,33 +98,11 @@ abstract class FieldClass
|
|||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional help text below the field
|
||||
*/
|
||||
public function help(): string|null
|
||||
{
|
||||
if (empty($this->help) === false) {
|
||||
$help = $this->stringTemplate($this->help);
|
||||
$help = $this->kirby()->kirbytext($help);
|
||||
return $help;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function i18n(string|array|null $param = null): string|null
|
||||
{
|
||||
return empty($param) === false ? I18n::translate($param, $param) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional icon that will be shown at the end of the field
|
||||
*/
|
||||
public function icon(): string|null
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
public function id(): string
|
||||
{
|
||||
return $this->name();
|
||||
|
|
@ -156,16 +118,6 @@ abstract class FieldClass
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The field label can be set as string or associative array with translations
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return $this->stringTemplate(
|
||||
$this->label ?? Str::ucfirst($this->name())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the field name
|
||||
*/
|
||||
|
|
@ -182,14 +134,6 @@ abstract class FieldClass
|
|||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional placeholder value that will be shown when the field is empty
|
||||
*/
|
||||
public function placeholder(): string|null
|
||||
{
|
||||
return $this->stringTemplate($this->placeholder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the props that will be sent to
|
||||
* the Vue component
|
||||
|
|
@ -217,67 +161,21 @@ abstract class FieldClass
|
|||
];
|
||||
}
|
||||
|
||||
protected function setAfter(array|string|null $after = null): void
|
||||
{
|
||||
$this->after = $this->i18n($after);
|
||||
}
|
||||
|
||||
protected function setAutofocus(bool $autofocus = false): void
|
||||
{
|
||||
$this->autofocus = $autofocus;
|
||||
}
|
||||
|
||||
protected function setBefore(array|string|null $before = null): void
|
||||
{
|
||||
$this->before = $this->i18n($before);
|
||||
}
|
||||
|
||||
protected function setDisabled(bool $disabled = false): void
|
||||
{
|
||||
$this->disabled = $disabled;
|
||||
}
|
||||
|
||||
protected function setHelp(array|string|null $help = null): void
|
||||
{
|
||||
$this->help = $this->i18n($help);
|
||||
}
|
||||
|
||||
protected function setIcon(string|null $icon = null): void
|
||||
{
|
||||
$this->icon = $icon;
|
||||
}
|
||||
|
||||
protected function setLabel(array|string|null $label = null): void
|
||||
{
|
||||
$this->label = $this->i18n($label);
|
||||
}
|
||||
|
||||
protected function setName(string|null $name = null): void
|
||||
{
|
||||
$this->name = strtolower($name ?? $this->type());
|
||||
}
|
||||
|
||||
protected function setPlaceholder(array|string|null $placeholder = null): void
|
||||
{
|
||||
$this->placeholder = $this->i18n($placeholder);
|
||||
}
|
||||
|
||||
protected function setSiblings(Fields|null $siblings = null): void
|
||||
{
|
||||
$this->siblings = $siblings ?? new Fields([$this]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the field width
|
||||
*/
|
||||
protected function setWidth(string|null $width = null): void
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all sibling fields for the HasSiblings trait
|
||||
*/
|
||||
protected function siblingsCollection(): Fields
|
||||
{
|
||||
return $this->siblings;
|
||||
|
|
@ -314,13 +212,4 @@ abstract class FieldClass
|
|||
{
|
||||
return lcfirst(basename(str_replace(['\\', 'Field'], ['/', ''], static::class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the field in
|
||||
* the Panel grid
|
||||
*/
|
||||
public function width(): string
|
||||
{
|
||||
return $this->width ?? '1/1';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
21
public/kirby/src/Form/Mixin/After.php
Normal file
21
public/kirby/src/Form/Mixin/After.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
trait After
|
||||
{
|
||||
/**
|
||||
* Optional text that will be shown after the input
|
||||
*/
|
||||
protected string|null $after;
|
||||
|
||||
public function after(): string|null
|
||||
{
|
||||
return $this->stringTemplate($this->after);
|
||||
}
|
||||
|
||||
protected function setAfter(array|string|null $after = null): void
|
||||
{
|
||||
$this->after = $this->i18n($after);
|
||||
}
|
||||
}
|
||||
21
public/kirby/src/Form/Mixin/Autofocus.php
Normal file
21
public/kirby/src/Form/Mixin/Autofocus.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
trait Autofocus
|
||||
{
|
||||
/**
|
||||
* Sets the focus on this field when the form loads. Only the first field with this label gets
|
||||
*/
|
||||
protected bool $autofocus;
|
||||
|
||||
public function autofocus(): bool
|
||||
{
|
||||
return $this->autofocus;
|
||||
}
|
||||
|
||||
protected function setAutofocus(bool $autofocus = false): void
|
||||
{
|
||||
$this->autofocus = $autofocus;
|
||||
}
|
||||
}
|
||||
21
public/kirby/src/Form/Mixin/Before.php
Normal file
21
public/kirby/src/Form/Mixin/Before.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
trait Before
|
||||
{
|
||||
/**
|
||||
* Optional text that will be shown before the input
|
||||
*/
|
||||
protected string|null $before;
|
||||
|
||||
public function before(): string|null
|
||||
{
|
||||
return $this->stringTemplate($this->before);
|
||||
}
|
||||
|
||||
protected function setBefore(array|string|null $before = null): void
|
||||
{
|
||||
$this->before = $this->i18n($before);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ namespace Kirby\Form\Mixin;
|
|||
|
||||
trait EmptyState
|
||||
{
|
||||
/**
|
||||
* Sets the text for the empty state box
|
||||
*/
|
||||
protected string|null $empty;
|
||||
|
||||
protected function setEmpty(string|array|null $empty = null): void
|
||||
|
|
|
|||
34
public/kirby/src/Form/Mixin/Help.php
Normal file
34
public/kirby/src/Form/Mixin/Help.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
/**
|
||||
* @package Kirby Form
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
trait Help
|
||||
{
|
||||
/**
|
||||
* Optional help text below the field
|
||||
*/
|
||||
protected string|null $help;
|
||||
|
||||
public function help(): string|null
|
||||
{
|
||||
if (empty($this->help) === false) {
|
||||
$help = $this->stringTemplate($this->help);
|
||||
$help = $this->kirby()->kirbytext($help);
|
||||
return $help;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function setHelp(array|string|null $help = null): void
|
||||
{
|
||||
$this->help = $this->i18n($help);
|
||||
}
|
||||
}
|
||||
28
public/kirby/src/Form/Mixin/Icon.php
Normal file
28
public/kirby/src/Form/Mixin/Icon.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
/**
|
||||
* @package Kirby Form
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
trait Icon
|
||||
{
|
||||
/**
|
||||
* Optional icon that will be shown at the end of the field
|
||||
*/
|
||||
protected string|null $icon;
|
||||
|
||||
public function icon(): string|null
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
protected function setIcon(string|null $icon = null): void
|
||||
{
|
||||
$this->icon = $icon;
|
||||
}
|
||||
}
|
||||
32
public/kirby/src/Form/Mixin/Label.php
Normal file
32
public/kirby/src/Form/Mixin/Label.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
* @package Kirby Form
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
trait Label
|
||||
{
|
||||
/**
|
||||
* The field label can be set as string or associative array with translations
|
||||
*/
|
||||
protected string|null $label;
|
||||
|
||||
public function label(): string|null
|
||||
{
|
||||
return $this->stringTemplate(
|
||||
$this->label ?? Str::ucfirst($this->name())
|
||||
);
|
||||
}
|
||||
|
||||
protected function setLabel(array|string|null $label = null): void
|
||||
{
|
||||
$this->label = $this->i18n($label);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,9 @@ namespace Kirby\Form\Mixin;
|
|||
|
||||
trait Max
|
||||
{
|
||||
/**
|
||||
* Sets the maximum number of allowed items in the field
|
||||
*/
|
||||
protected int|null $max;
|
||||
|
||||
public function max(): int|null
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ namespace Kirby\Form\Mixin;
|
|||
|
||||
trait Min
|
||||
{
|
||||
/**
|
||||
* Sets the minimum number of required items in the field
|
||||
*/
|
||||
protected int|null $min;
|
||||
|
||||
public function min(): int|null
|
||||
|
|
|
|||
30
public/kirby/src/Form/Mixin/Placeholder.php
Normal file
30
public/kirby/src/Form/Mixin/Placeholder.php
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
/**
|
||||
* @package Kirby Form
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
trait Placeholder
|
||||
{
|
||||
/**
|
||||
* Optional placeholder value that will be shown when the field is empty
|
||||
*/
|
||||
protected array|string|null $placeholder;
|
||||
|
||||
public function placeholder(): string|null
|
||||
{
|
||||
return $this->stringTemplate(
|
||||
$this->placeholder
|
||||
);
|
||||
}
|
||||
|
||||
protected function setPlaceholder(array|string|null $placeholder = null): void
|
||||
{
|
||||
$this->placeholder = $this->i18n($placeholder);
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,9 @@ use Kirby\Cms\Language;
|
|||
*/
|
||||
trait Translatable
|
||||
{
|
||||
/**
|
||||
* Should the field be translatable?
|
||||
*/
|
||||
protected bool $translate = true;
|
||||
|
||||
/**
|
||||
|
|
@ -29,17 +32,11 @@ trait Translatable
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the translatable status
|
||||
*/
|
||||
protected function setTranslate(bool $translate = true): void
|
||||
{
|
||||
$this->translate = $translate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the field be translatable?
|
||||
*/
|
||||
public function translate(): bool
|
||||
{
|
||||
return $this->translate;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ use Kirby\Toolkit\V;
|
|||
*/
|
||||
trait Validation
|
||||
{
|
||||
/**
|
||||
* If `true`, the field has to be filled in correctly to be saved.
|
||||
*/
|
||||
protected bool $required;
|
||||
|
||||
/**
|
||||
|
|
@ -94,9 +97,6 @@ trait Validation
|
|||
return $this->errors() === [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the required property
|
||||
*/
|
||||
public function required(): bool
|
||||
{
|
||||
return $this->required;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,14 @@ use Kirby\Cms\Language;
|
|||
*/
|
||||
trait Value
|
||||
{
|
||||
/**
|
||||
* Default value for the field, which will be used when a page/file/user is created
|
||||
*/
|
||||
protected mixed $default = null;
|
||||
|
||||
/**
|
||||
* The value of the field
|
||||
*/
|
||||
protected mixed $value = null;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ namespace Kirby\Form\Mixin;
|
|||
*/
|
||||
trait When
|
||||
{
|
||||
/**
|
||||
* Conditions when the field will be shown
|
||||
*
|
||||
* @since 3.1.0
|
||||
*/
|
||||
protected array|null $when = null;
|
||||
|
||||
/**
|
||||
|
|
@ -40,17 +45,11 @@ trait When
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the `when` condition
|
||||
*/
|
||||
protected function setWhen(array|null $when = null): void
|
||||
{
|
||||
$this->when = $when;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the `when` condition of the field
|
||||
*/
|
||||
public function when(): array|null
|
||||
{
|
||||
return $this->when;
|
||||
|
|
|
|||
29
public/kirby/src/Form/Mixin/Width.php
Normal file
29
public/kirby/src/Form/Mixin/Width.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Kirby\Form\Mixin;
|
||||
|
||||
/**
|
||||
* @package Kirby Form
|
||||
* @author Bastian Allgeier <bastian@getkirby.com>
|
||||
* @link https://getkirby.com
|
||||
* @copyright Bastian Allgeier
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
*/
|
||||
trait Width
|
||||
{
|
||||
/**
|
||||
* The width of the field in the field grid.
|
||||
* Available widths: `1/1`, `1/2`, `1/3`, `1/4`, `2/3`, `3/4`
|
||||
*/
|
||||
protected string|null $width;
|
||||
|
||||
protected function setWidth(string|null $width = null): void
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
public function width(): string
|
||||
{
|
||||
return $this->width ?? '1/1';
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue