| | |
| | | { |
| | | $this->meta = $meta; |
| | | $this->name = $name; |
| | | $this->config = $meta->config($name) ?? []; |
| | | $this->config = $meta->getFieldConfig($name) ?? []; |
| | | |
| | | $data = $meta->get($name); |
| | | $this->data = is_array($data) ? $data : []; |
| | |
| | | return $this->getPath($nested, $fieldConfig['fields'] ?? [], $parts); |
| | | } |
| | | |
| | | public function set(string $path, mixed $value, bool $autosave = true): self |
| | | public function set(string $path, mixed $value, bool $autosave = true): bool |
| | | { |
| | | $parts = explode('|', $path); |
| | | $parts = explode('|', $path, 2); |
| | | $this->setPath($this->data, $this->config['fields'] ?? [], $parts, $value); |
| | | $this->sync($autosave); |
| | | return $this; |
| | | return $this->sync($autosave); |
| | | } |
| | | |
| | | protected function setPath(array &$data, array $fieldsConfig, array $parts, mixed $value): void |
| | |
| | | } |
| | | $this->data[$field] = $value; |
| | | } |
| | | $this->sync(true); |
| | | $this->sync(); |
| | | return $this; |
| | | } |
| | | |
| | |
| | | return isset($this->config['fields'][$field]); |
| | | } |
| | | |
| | | protected function sync(bool $autosave = true): void |
| | | protected function sync(bool $autosave = true): bool |
| | | { |
| | | $this->meta->set($this->name, $this->data, $autosave); |
| | | error_log('Setting '.$this->name.' group with data: '.print_r($this->data, true)); |
| | | return $this->meta->set($this->name, $this->data); |
| | | } |
| | | } |