feat(06-admin-base): Admin\ base infrastructure — Form Edit System + Support layer (Phase 6)
Phase 6 zamknięta po 2 planach. Pełny fundament dla Phase 7-13 (migracja 17 admin controllers do Admin\ namespace). 06-01 (Forms infrastructure): - Admin\ViewModels\Forms\* — 5 ViewModeli (687 L) - Admin\Validation\FormValidator (196 L) - composer.json: php >=7.4, PSR-4 paths cross-platform safe (Admin\ → autoload/admin/, Frontend\ → autoload/front/) 06-02 (Support layer): - Admin\Support\TableListRequestFactory (99 L) — parser list z $_GET - Admin\Support\Forms\FormRequestHandler (159 L) — POST + CSRF + walidacja + persist - Admin\Support\Forms\FormFieldRenderer (494 L) — renderer HTML pól Decyzje: - Brak BaseController — Phase 7+ kontrolery jako POJOs z DI (jak shopPRO) - PSR-4 filename fix: TableListRequestFactory.php (bez shopPRO 'class.' prefix) - PascalCase namespace (Admin\Support) na lowercase folder admin/ ze względu na Windows fs case-insensitivity vs legacy admin/controls/ Pliki: 8 nowych klas, 1635 L kodu PHP 7.4-kompatybilnego, zero regresji. Smoke test: walidacja e-maila zwraca PL komunikat, factory parsuje ?page=&per_page=&sort=&filter=, Domain/Shared nadal ładują się. PHPUnit: 37/37 OK. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
364
autoload/admin/ViewModels/Forms/FormField.php
Normal file
364
autoload/admin/ViewModels/Forms/FormField.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
namespace Admin\ViewModels\Forms;
|
||||
|
||||
/**
|
||||
* Definicja pojedynczego pola formularza
|
||||
*/
|
||||
class FormField
|
||||
{
|
||||
public string $name;
|
||||
public string $type;
|
||||
public string $label;
|
||||
public $value;
|
||||
public string $tabId;
|
||||
public bool $required;
|
||||
public array $attributes;
|
||||
public array $options;
|
||||
public ?string $helpText;
|
||||
public ?string $placeholder;
|
||||
public ?string $id;
|
||||
|
||||
// Specyficzne dla obrazów/plików
|
||||
public bool $useFilemanager;
|
||||
public ?string $filemanagerUrl;
|
||||
|
||||
// Specyficzne dla edytora
|
||||
public string $editorToolbar;
|
||||
public int $editorHeight;
|
||||
|
||||
// Specyficzne dla lang_section
|
||||
public ?array $langFields;
|
||||
public ?string $langSectionParentTab;
|
||||
public ?string $customHtml;
|
||||
|
||||
/**
|
||||
* @param string $name Nazwa pola (name)
|
||||
* @param string $type Typ pola (z FormFieldType)
|
||||
* @param string $label Etykieta pola
|
||||
* @param mixed $value Wartość domyślna
|
||||
* @param string $tabId Identyfikator zakładki
|
||||
* @param bool $required Czy pole wymagane
|
||||
* @param array $attributes Atrybuty HTML
|
||||
* @param array $options Opcje dla select
|
||||
* @param string|null $helpText Tekst pomocniczy
|
||||
* @param string|null $placeholder Placeholder
|
||||
* @param bool $useFilemanager Czy używać filemanagera
|
||||
* @param string|null $filemanagerUrl URL filemanagera
|
||||
* @param string $editorToolbar Konfiguracja toolbar CKEditor
|
||||
* @param int $editorHeight Wysokość edytora
|
||||
* @param array|null $langFields Pola w sekcji językowej
|
||||
* @param string|null $langSectionParentTab Zakładka nadrzędna dla sekcji językowej
|
||||
*/
|
||||
public function __construct(
|
||||
string $name,
|
||||
string $type = FormFieldType::TEXT,
|
||||
string $label = '',
|
||||
$value = null,
|
||||
string $tabId = 'default',
|
||||
bool $required = false,
|
||||
array $attributes = [],
|
||||
array $options = [],
|
||||
?string $helpText = null,
|
||||
?string $placeholder = null,
|
||||
bool $useFilemanager = false,
|
||||
?string $filemanagerUrl = null,
|
||||
string $editorToolbar = 'MyTool',
|
||||
int $editorHeight = 300,
|
||||
?array $langFields = null,
|
||||
?string $langSectionParentTab = null,
|
||||
?string $customHtml = null
|
||||
) {
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->label = $label;
|
||||
$this->value = $value;
|
||||
$this->tabId = $tabId;
|
||||
$this->required = $required;
|
||||
$this->attributes = $attributes;
|
||||
$this->options = $options;
|
||||
$this->helpText = $helpText;
|
||||
$this->placeholder = $placeholder;
|
||||
$this->useFilemanager = $useFilemanager;
|
||||
$this->filemanagerUrl = $filemanagerUrl;
|
||||
$this->editorToolbar = $editorToolbar;
|
||||
$this->editorHeight = $editorHeight;
|
||||
$this->langFields = $langFields;
|
||||
$this->langSectionParentTab = $langSectionParentTab;
|
||||
$this->customHtml = $customHtml;
|
||||
$this->id = $attributes['id'] ?? $name;
|
||||
}
|
||||
|
||||
// Factory methods dla różnych typów pól
|
||||
|
||||
public static function text(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::TEXT,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
$config['help'] ?? null,
|
||||
$config['placeholder'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public static function number(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::NUMBER,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
$config['help'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public static function email(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::EMAIL,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
public static function password(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::PASSWORD,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
public static function date(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::DATE,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
array_merge(['class' => 'date'], $config['attributes'] ?? [])
|
||||
);
|
||||
}
|
||||
|
||||
public static function datetime(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::DATETIME,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
array_merge(['class' => 'datetime'], $config['attributes'] ?? [])
|
||||
);
|
||||
}
|
||||
|
||||
public static function switch(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::SWITCH,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? false,
|
||||
$config['tab'] ?? 'default',
|
||||
false,
|
||||
$config['attributes'] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
public static function select(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::SELECT,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
$config['options'] ?? []
|
||||
);
|
||||
}
|
||||
|
||||
public static function textarea(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::TEXTAREA,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
array_merge(['rows' => $config['rows'] ?? 4], $config['attributes'] ?? [])
|
||||
);
|
||||
}
|
||||
|
||||
public static function editor(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::EDITOR,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
$config['toolbar'] ?? 'MyTool',
|
||||
$config['height'] ?? 300
|
||||
);
|
||||
}
|
||||
|
||||
public static function image(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::IMAGE,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
$config['filemanager'] ?? true,
|
||||
$config['filemanager_url'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public static function file(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::FILE,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
$config['filemanager'] ?? true
|
||||
);
|
||||
}
|
||||
|
||||
public static function color(string $name, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::COLOR,
|
||||
$config['label'] ?? '',
|
||||
$config['value'] ?? null,
|
||||
$config['tab'] ?? 'default',
|
||||
$config['required'] ?? false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
$config['help'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public static function hidden(string $name, $value = null): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::HIDDEN,
|
||||
'',
|
||||
$value,
|
||||
'default'
|
||||
);
|
||||
}
|
||||
|
||||
public static function custom(string $name, string $html, array $config = []): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::CUSTOM,
|
||||
$config['label'] ?? '',
|
||||
null,
|
||||
$config['tab'] ?? 'default',
|
||||
false,
|
||||
$config['attributes'] ?? [],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
'MyTool',
|
||||
300,
|
||||
null,
|
||||
null,
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sekcja językowa - grupa pól powtarzana dla każdego języka
|
||||
*
|
||||
* @param string $name Nazwa sekcji (prefiks dla pól)
|
||||
* @param string $parentTab Identyfikator zakładki nadrzędnej
|
||||
* @param array $fields Pola w sekcji językowej (tablica FormField)
|
||||
*/
|
||||
public static function langSection(string $name, string $parentTab, array $fields): self
|
||||
{
|
||||
return new self(
|
||||
$name,
|
||||
FormFieldType::LANG_SECTION,
|
||||
'',
|
||||
null,
|
||||
$parentTab,
|
||||
false,
|
||||
[],
|
||||
[],
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
'MyTool',
|
||||
300,
|
||||
$fields,
|
||||
$parentTab
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca nazwę pola z sufiksem dla konkretnego języka
|
||||
*/
|
||||
public function getLocalizedName($languageId): string
|
||||
{
|
||||
return "{$this->name}[{$languageId}]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Zwraca ID pola z sufiksem dla konkretnego języka
|
||||
*/
|
||||
public function getLocalizedId($languageId): string
|
||||
{
|
||||
return "{$this->id}_{$languageId}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user