Skip to content
This repository has been archived by the owner on Mar 11, 2022. It is now read-only.

Commit

Permalink
Add currentLocale meta to form & detail (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork authored May 18, 2020
1 parent 986e616 commit e0b092a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default {
data() {
return {
currentLocale: Object.keys(this.field.locales)[0]
currentLocale: this.field.currentLocale
}
},
Expand Down
6 changes: 1 addition & 5 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,10 @@ export default {
data() {
return {
locales: Object.keys(this.field.locales),
currentLocale: null,
currentLocale: this.field.currentLocale,
}
},
mounted() {
this.currentLocale = this.locales[0] || null
},
methods: {
/*
* Set the initial, internal value for the field.
Expand Down
22 changes: 16 additions & 6 deletions src/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ public function __construct($name, $attribute = null, $resolveCallback = null)
{
parent::__construct($name, $attribute, $resolveCallback);

$locales = array_map(function ($value) {
return __($value);
}, config('translatable.locales'));

$this->withMeta([
'locales' => $locales,
'indexLocale' => app()->getLocale()
'locales' => array_map(static function ($value) {
return __($value);
}, config('translatable.locales', [])),
'indexLocale' => app()->getLocale(),
'currentLocale' => app()->getLocale(),
]);
}

Expand Down Expand Up @@ -72,6 +71,17 @@ public function indexLocale($locale)
return $this->withMeta(['indexLocale' => $locale]);
}

/**
* Set the locale to display on detail and form.
*
* @param string $locale
* @return $this
*/
public function currentLocale($locale)
{
return $this->withMeta(['currentLocale' => $locale]);
}

/**
* Set the input field to a single line text field.
*/
Expand Down

0 comments on commit e0b092a

Please sign in to comment.