Skip to content

Commit

Permalink
add save_last_selected_lang to config
Browse files Browse the repository at this point in the history
  • Loading branch information
kongulov committed Sep 18, 2021
1 parent c3bb557 commit 04399c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
```

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions config/tab-translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
6 changes: 3 additions & 3 deletions src/NovaTabTranslatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
]);
}

Expand Down

0 comments on commit 04399c7

Please sign in to comment.