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

Add currentLocale meta to form & detail #43

Merged
merged 3 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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