From 8744197667e58d3aa4b09b8e96f0aad5c1dd9e32 Mon Sep 17 00:00:00 2001 From: Gennadiy Sevalnev Date: Wed, 6 Nov 2024 15:26:09 +0700 Subject: [PATCH 1/2] feat(methods): Add custom input field setter --- src/Fields/Translatable.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Fields/Translatable.php b/src/Fields/Translatable.php index 7fba24a..f80815b 100644 --- a/src/Fields/Translatable.php +++ b/src/Fields/Translatable.php @@ -130,6 +130,17 @@ public function json(): static return $this; } + public function customInputField(string $class): static + { + if (!is_subclass_of($class, Field::class)) { + throw new FieldException('The passed class must be a subclass of MoonShine\Fields\Field'); + } + + $this->inputField = $class; + + return $this; + } + public function keyValue( string $key = 'Language', string $value = 'Value', From 6b07268dbe17b1e36d996839b5f22b43369bf5d7 Mon Sep 17 00:00:00 2001 From: Gennadiy Sevalnev Date: Wed, 18 Dec 2024 18:36:17 +0700 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20moonshine=203+=20=D1=81ompatibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Fields/Translatable.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Fields/Translatable.php b/src/Fields/Translatable.php index f80815b..307ec15 100644 --- a/src/Fields/Translatable.php +++ b/src/Fields/Translatable.php @@ -3,14 +3,15 @@ namespace VI\MoonShineSpatieTranslatable\Fields; use Illuminate\Support\Str; -use MoonShine\Exceptions\FieldException; -use MoonShine\Fields\Field; -use MoonShine\Fields\Fields; -use MoonShine\Fields\Json; -use MoonShine\Fields\Select; -use MoonShine\Fields\Text; -use MoonShine\Fields\Textarea; -use MoonShine\Fields\TinyMce; +use MoonShine\Contracts\Core\DependencyInjection\FieldsContract; +use MoonShine\Contracts\UI\FieldContract; +use MoonShine\UI\Exceptions\FieldException; +use MoonShine\UI\Fields\Field; +use MoonShine\UI\Fields\Json; +use MoonShine\UI\Fields\Select; +use MoonShine\UI\Fields\Text; +use MoonShine\UI\Fields\Textarea; +use MoonShine\TinyMce\Fields\TinyMce; use Illuminate\Contracts\View\View; @@ -21,7 +22,7 @@ final class Translatable extends Json protected bool $onlyValue = false; /** - * @var class-string + * @var class-string */ protected string $inputField = Text::class; @@ -43,7 +44,7 @@ final class Translatable extends Json protected function prepareFill(array $raw = [], mixed $casted = null): mixed { - return $casted->getTranslations($this->column()); + return $casted->getOriginal()->getTranslations($this->column); } /** @@ -51,15 +52,14 @@ protected function prepareFill(array $raw = [], mixed $casted = null): mixed */ public function onlyValue( string $value = 'Value', - ?Field $valueField = null, + ?FieldContract $valueField = null, ): static { throw new FieldException('Can`t set onlyValue for this field!'); } - public function getFields(mixed $data = null): Fields + public function getFields(mixed $data = null): FieldsContract { - $inputField = $this->inputField::make(__('Value'), 'value'); if (empty($this->fields)) { @@ -110,7 +110,6 @@ protected function getLanguagesCodes(): array public function textarea(): static { - $this->inputField = Textarea::class; return $this; @@ -133,7 +132,7 @@ public function json(): static public function customInputField(string $class): static { if (!is_subclass_of($class, Field::class)) { - throw new FieldException('The passed class must be a subclass of MoonShine\Fields\Field'); + throw new FieldException('The passed class must be a subclass of MoonShine\UI\Fields\Field'); } $this->inputField = $class; @@ -144,8 +143,8 @@ public function customInputField(string $class): static public function keyValue( string $key = 'Language', string $value = 'Value', - ?Field $keyField = null, - ?Field $valueField = null, + ?FieldContract $keyField = null, + ?FieldContract $valueField = null, ): static { $this->fields([ Select::make($key, 'key') @@ -165,6 +164,7 @@ public function hasFields(): bool protected function resolvePreview(): View|string { - return $this?->data?->{$this->column()} ?? ''; + return $this?->data?->{$this->column} ?? ''; } } +