| | |
| | | $this->config = $config; |
| | | } |
| | | |
| | | /** |
| | | * Set field value and track dirty state |
| | | */ |
| | | public function set(mixed $value): self |
| | | { |
| | | $this->value = $value; |
| | |
| | | return $this; |
| | | } |
| | | |
| | | /** |
| | | * Get current value |
| | | */ |
| | | public function get(): mixed |
| | | { |
| | | return $this->value; |
| | | } |
| | | |
| | | /** |
| | | * Mark field as clean (after save) |
| | | */ |
| | | public function markClean(): self |
| | | { |
| | | $this->originalValue = $this->value; |
| | |
| | | return $this; |
| | | } |
| | | |
| | | /** |
| | | * Reset to original value |
| | | */ |
| | | public function reset(): self |
| | | { |
| | | $this->value = $this->originalValue; |
| | |
| | | return $this; |
| | | } |
| | | |
| | | /** |
| | | * Add validation error |
| | | */ |
| | | public function addError(string $message): self |
| | | { |
| | | $this->errors[] = $message; |
| | |
| | | return $this; |
| | | } |
| | | |
| | | /** |
| | | * Clear all errors |
| | | */ |
| | | public function clearErrors(): self |
| | | { |
| | | $this->errors = []; |
| | |
| | | return $this; |
| | | } |
| | | |
| | | /** |
| | | * Get field type from config |
| | | */ |
| | | public function type(): string |
| | | { |
| | | return $this->config['type'] ?? 'text'; |
| | | } |
| | | |
| | | /** |
| | | * Check if this is a WordPress default field |
| | | */ |
| | | public function isWpDefault(): bool |
| | | { |
| | | return $this->config['_wp_default'] ?? false; |
| | | } |
| | | |
| | | /** |
| | | * Check if this is a taxonomy relationship field (not taxonomy_type) |
| | | */ |
| | | public function isTaxonomy(): bool |
| | | { |
| | | return $this->type() === 'taxonomy' && !isset($this->config['taxonomy_type']); |
| | | } |
| | | |
| | | /** |
| | | * Check if field is required |
| | | */ |
| | | public function isRequired(): bool |
| | | { |
| | | return !empty($this->config['required']); |
| | | } |
| | | |
| | | /** |
| | | * Get field label |
| | | */ |
| | | public function label(): string |
| | | { |
| | | return $this->config['label'] ?? $this->name; |
| | | } |
| | | |
| | | /** |
| | | * Get field description |
| | | */ |
| | | public function description(): string |
| | | { |
| | | return $this->config['description'] ?? ''; |
| | | } |
| | | } |