From de259cf9e00dab05aa4bb639aac2965847ee6eb5 Mon Sep 17 00:00:00 2001 From: marijoo Date: Fri, 24 Nov 2023 12:57:56 +0100 Subject: [PATCH 1/2] fix: only assign panel if `null` resolves #87 --- src/Translatable.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Translatable.php b/src/Translatable.php index f49b13e..7d2226c 100644 --- a/src/Translatable.php +++ b/src/Translatable.php @@ -57,7 +57,7 @@ public static function make(array $fields): self public function __construct(array $fields = []) { - if (! count(static::$defaultLocales)) { + if (!count(static::$defaultLocales)) { throw InvalidConfiguration::defaultLocalesNotSet(); } @@ -66,7 +66,7 @@ public function __construct(array $fields = []) $this->originalFields = $fields; $this->displayLocalizedNameUsingCallback = self::$displayLocalizedNameByDefaultUsingCallback ?? function (Field $field, string $locale) { - return ucfirst($field->name)." ({$locale})"; + return ucfirst($field->name) . " ({$locale})"; }; $this->createTranslatableFields(); @@ -188,9 +188,9 @@ protected function createTranslatedField(Field $originalField, string $locale): $translatedField ->resolveUsing(function ($value, Model $model) use ($translatedField, $locale, $originalAttribute) { - $translatedField->attribute = 'translations_'.$originalAttribute.'_'.$locale; - $translatedField->panel = $this->panel; - $translatedField->assignedPanel = $this->assignedPanel; + $translatedField->attribute = 'translations_' . $originalAttribute . '_' . $locale; + $translatedField->panel ??= $this->panel; + $translatedField->assignedPanel ??= $this->assignedPanel; return $model->translations[$originalAttribute][$locale] ?? ''; }); @@ -226,7 +226,7 @@ protected function createTranslatedField(Field $originalField, string $locale): protected function onIndexPage(): bool { - if (! request()->route()) { + if (!request()->route()) { return false; } From 36c44a398462a7e54110369d2bc46f9902022adb Mon Sep 17 00:00:00 2001 From: marijoo Date: Mon, 27 Nov 2023 10:09:29 +0100 Subject: [PATCH 2/2] fix: use null coalescing operator This keeps PHP 7.3 support, since the null coalescing assigment operator was introduced in PHP 7.4. --- src/Translatable.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Translatable.php b/src/Translatable.php index 7d2226c..ae4673e 100644 --- a/src/Translatable.php +++ b/src/Translatable.php @@ -57,7 +57,7 @@ public static function make(array $fields): self public function __construct(array $fields = []) { - if (!count(static::$defaultLocales)) { + if (! count(static::$defaultLocales)) { throw InvalidConfiguration::defaultLocalesNotSet(); } @@ -66,7 +66,7 @@ public function __construct(array $fields = []) $this->originalFields = $fields; $this->displayLocalizedNameUsingCallback = self::$displayLocalizedNameByDefaultUsingCallback ?? function (Field $field, string $locale) { - return ucfirst($field->name) . " ({$locale})"; + return ucfirst($field->name)." ({$locale})"; }; $this->createTranslatableFields(); @@ -188,9 +188,9 @@ protected function createTranslatedField(Field $originalField, string $locale): $translatedField ->resolveUsing(function ($value, Model $model) use ($translatedField, $locale, $originalAttribute) { - $translatedField->attribute = 'translations_' . $originalAttribute . '_' . $locale; - $translatedField->panel ??= $this->panel; - $translatedField->assignedPanel ??= $this->assignedPanel; + $translatedField->attribute = 'translations_'.$originalAttribute.'_'.$locale; + $translatedField->panel = $translatedField->panel ?? $this->panel; + $translatedField->assignedPanel = $translatedField->assignedPanel ?? $this->assignedPanel; return $model->translations[$originalAttribute][$locale] ?? ''; }); @@ -226,7 +226,7 @@ protected function createTranslatedField(Field $originalField, string $locale): protected function onIndexPage(): bool { - if (!request()->route()) { + if (! request()->route()) { return false; }