diff --git a/config/config.php b/config/config.php index de89c4a..f0d5268 100644 --- a/config/config.php +++ b/config/config.php @@ -27,6 +27,9 @@ 'classes' => [ \Jonassiewertsen\Livewire\Synthesizers\EntryCollectionSynthesizer::class, \Jonassiewertsen\Livewire\Synthesizers\EntrySynthesizer::class, + \Jonassiewertsen\Livewire\Synthesizers\FieldSynthesizer::class, + \Jonassiewertsen\Livewire\Synthesizers\FieldtypeSynthesizer::class, + \Jonassiewertsen\Livewire\Synthesizers\ValueSynthesizer::class, ], ], diff --git a/src/Synthesizers/FieldSynthesizer.php b/src/Synthesizers/FieldSynthesizer.php new file mode 100644 index 0000000..da2a85f --- /dev/null +++ b/src/Synthesizers/FieldSynthesizer.php @@ -0,0 +1,39 @@ + $target->handle(), + 'config' => $target->config(), + ]; + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [$data, []]; + } + + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return new Field(...$value); + } +} diff --git a/src/Synthesizers/FieldtypeSynthesizer.php b/src/Synthesizers/FieldtypeSynthesizer.php new file mode 100644 index 0000000..a391e53 --- /dev/null +++ b/src/Synthesizers/FieldtypeSynthesizer.php @@ -0,0 +1,41 @@ + $target->field(), + ]; + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [ + $data, + ['class' => get_class($target)], + ]; + } + + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return app($meta['class'])->setField($value['field']); + } +} diff --git a/src/Synthesizers/ValueSynthesizer.php b/src/Synthesizers/ValueSynthesizer.php new file mode 100644 index 0000000..1eb5792 --- /dev/null +++ b/src/Synthesizers/ValueSynthesizer.php @@ -0,0 +1,46 @@ + $value->raw, + 'handle' => $value->handle, + 'fieldtype' => $value->fieldtype, + 'augmentable' => $value->augmentable, + 'shallow' => $value->shallow, + ]; + + foreach ($data as $key => $child) { + $data[$key] = $dehydrateChild($key, $child); + } + + return [$data, []]; + } + + public function hydrate($value, $meta, $hydrateChild) + { + foreach ($value as $key => $child) { + $value[$key] = $hydrateChild($key, $child); + } + + return new Value(...$value); + } +}