| | |
| | | $this->meta = $meta; |
| | | $this->name = $name; |
| | | $this->data = $meta->get($name) ?: []; |
| | | $this->config = $meta->config($name) ?? []; |
| | | $this->config = $meta->getFieldConfig($name) ?? []; |
| | | |
| | | // Ensure data is array |
| | | if (!is_array($this->data)) { |
| | |
| | | /** |
| | | * Set field value in specific row |
| | | */ |
| | | public function setField(int $index, string $field, mixed $value): self |
| | | public function setField(int $index, string $field, mixed $value):bool |
| | | { |
| | | if (!isset($this->data[$index])) { |
| | | $this->data[$index] = []; |
| | | } |
| | | |
| | | $this->data[$index][$field] = $value; |
| | | $this->sync(); |
| | | |
| | | return $this; |
| | | return $this->sync(); |
| | | } |
| | | |
| | | /** |
| | |
| | | /** |
| | | * Sync data back to Meta instance |
| | | */ |
| | | protected function sync(): void |
| | | protected function sync(): bool |
| | | { |
| | | $this->meta->set($this->name, $this->data); |
| | | return $this->meta->set($this->name, $this->data); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public function rowLabelField(): ?string |
| | | { |
| | | return $this->config['row_label'] ?? null; |
| | | return $this->config['add_label'] ?? null; |
| | | } |
| | | } |