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}"; } }