mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-16 21:17:45 +02:00
refactor(plugins): create Field objects per field type in settings forms + handle rendering in class
update manifest.schema.json to have defaultValue type differ based on field type
This commit is contained in:
parent
d3a98db6d0
commit
34be5bccab
48 changed files with 3875 additions and 2553 deletions
63
modules/Plugins/Manifest/Fields/SelectMultiple.php
Normal file
63
modules/Plugins/Manifest/Fields/SelectMultiple.php
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Plugins\Manifest\Fields;
|
||||
|
||||
use Modules\Plugins\Manifest\Field;
|
||||
use Modules\Plugins\Manifest\WithOptionsTrait;
|
||||
use Override;
|
||||
|
||||
/**
|
||||
* @property list<string> $defaultValue
|
||||
*/
|
||||
class SelectMultiple extends Field
|
||||
{
|
||||
use WithOptionsTrait;
|
||||
|
||||
public static array $validation_rules = [
|
||||
'defaultValue' => 'permit_empty|is_list',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected array $defaultValue = [];
|
||||
|
||||
public function __construct(string $pluginKey)
|
||||
{
|
||||
$this->injectRules();
|
||||
|
||||
parent::__construct($pluginKey);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function loadData(array $data): void
|
||||
{
|
||||
$data = $this->transformData($data);
|
||||
|
||||
parent::loadData($data);
|
||||
}
|
||||
|
||||
public function render(string $name, mixed $value, string $class = ''): string
|
||||
{
|
||||
$isRequired = $this->optional ? 'false' : 'true';
|
||||
$options = esc(json_encode($this->getOptionsArray()));
|
||||
$value = esc(json_encode($value));
|
||||
$defaultValue = esc(json_encode($this->defaultValue));
|
||||
return <<<HTML
|
||||
<x-Forms.Field
|
||||
as="SelectMulti"
|
||||
class="{$class}"
|
||||
name="{$name}"
|
||||
label="{$this->label}"
|
||||
hint="{$this->hint}"
|
||||
helper="{$this->helper}"
|
||||
options="{$options}"
|
||||
isRequired="{$isRequired}"
|
||||
value="{$value}"
|
||||
defaultValue="{$defaultValue}"
|
||||
/>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue