From 04399c7bdabef8a6a3cdf16494a959f3a4ea6ec0 Mon Sep 17 00:00:00 2001 From: Ramiz Kongulov Date: Sat, 18 Sep 2021 14:30:08 +0400 Subject: [PATCH] add save_last_selected_lang to config --- README.md | 10 ++++++++-- config/tab-translatable.php | 5 +++++ src/NovaTabTranslatable.php | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 045c908..e66d587 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,12 @@ return [ 'model' => 'App\\Language', 'code_field' => 'lang', ], + + /* + * If you want to save the tab in the last selected language for the whole project, set this "true". + * But if you want to use in one place call the saveLastSelectedLang(true|false) method + */ + 'save_last_selected_lang' => false, ]; ``` @@ -133,11 +139,11 @@ NovaTabTranslatable::make([ ])->setTitle('Own Title'), ``` -* If you want to save the tab in the last selected language, call the `saveLastSelectedLang()` method +* If you want to save the tab in the last selected language, call the `saveLastSelectedLang()` method or in the config replace `'save_last_selected_lang' => false` with `'save_last_selected_lang' => true` ```php NovaTabTranslatable::make([ Text::make('Title'), -])->saveLastSelectedLang(), +])->saveLastSelectedLang(true|false), ``` * If on the index and detail pages you want to turn off the tab and show it each as a row, use trait `TranslatableTabToRowTrait` in your resource diff --git a/config/tab-translatable.php b/config/tab-translatable.php index ecc90ba..f60b1b9 100644 --- a/config/tab-translatable.php +++ b/config/tab-translatable.php @@ -24,4 +24,9 @@ 'code_field' => 'lang', ], + /* + * If you want to save the tab in the last selected language for the whole project, set this "true". + * But if you want to use in one place call the saveLastSelectedLang(true|false) method + */ + 'save_last_selected_lang' => false, ]; diff --git a/src/NovaTabTranslatable.php b/src/NovaTabTranslatable.php index 7228c53..917028b 100644 --- a/src/NovaTabTranslatable.php +++ b/src/NovaTabTranslatable.php @@ -53,7 +53,7 @@ public function __construct(array $fields = []) $this->createTranslatableFields(); $this->withMeta([ - 'saveLastSelectedLang' => false, + 'saveLastSelectedLang' => $config['save_last_selected_lang'] ?? false, 'languages' => $this->locales, 'fields' => $this->data, 'originalFieldsCount' => count($fields), @@ -68,10 +68,10 @@ public function setTitle($title): self return $this; } - public function saveLastSelectedLang(): self + public function saveLastSelectedLang(bool $state = true): self { return $this->withMeta([ - 'saveLastSelectedLang' => true, + 'saveLastSelectedLang' => $state, ]); }