Skip to content

Commit

Permalink
Merge pull request #4 from lara-zeus/fix-multi-lang
Browse files Browse the repository at this point in the history
fix setting the state for creation and edit
  • Loading branch information
atmonshi authored Mar 12, 2024
2 parents 96882ef + 89d3f17 commit 94cbf9a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 35 deletions.
8 changes: 1 addition & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,5 @@
"LaraZeus\\Chaos\\ChaosServiceProvider"
]
}
},
"repositories": [
{
"type": "path",
"url": "../*"
}
]
}
}
58 changes: 30 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/Forms/Components/MultiLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,23 @@
class MultiLang extends TextInput
{
protected string $view = 'zeus-chaos::forms.components.multi-lang';

protected function setUp(): void
{
parent::setUp();
$this->formatStateUsing(function () {
$defaultDataForLang = [];

foreach (config('app.locales') as $lang => $info) {
if (static::getRecord() === null) {
$defaultDataForLang[$lang] = '';
} else {
// @phpstan-ignore-next-line
$defaultDataForLang[$lang] = static::getRecord()->getTranslation('name', $lang);
}
}

return $defaultDataForLang;
});
}
}

0 comments on commit 94cbf9a

Please sign in to comment.