Skip to content

Commit

Permalink
locales config moved to common config
Browse files Browse the repository at this point in the history
  • Loading branch information
dobrik committed Jun 12, 2019
1 parent 83a2861 commit 82c7c27
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function create(string $form_name, Model $model = null): HtmlAbstract
throw new \InvalidArgumentException(sprintf('Model must be instance of "TranslatableModelAbstract", "%s" given', get_parent_class($model)));
}
$field = $this->factory->html('tabs')->setLabel($field_config['title']);
foreach (config('app.locales') as $locale) {
foreach (config('easy_form.config.locales') as $locale) {
$fieldObject = $this->prepareField($field_config, $model, $locale);
$field->addTab(
$this->factory->html('tab')->setTitle($locale)->setId($field_config['name'] . '_' . $locale)->setContent($fieldObject)
Expand Down Expand Up @@ -141,7 +141,7 @@ private function prepareField(array $field_data, Model $model = null, string $lo
$field = $this->factory->autoMake($input_name, $field_data['type'], $field_data['title']);

switch (true) {
case ($value = $this->getRequest()->old(array_key(Arr::dot($input_name)))) !== null:
case ($value = $this->getRequest()->old(arrayToDot($input_name))) !== null:
break;
case $model !== null:
$value = null === $locale ? $model->getAttribute($field_data['name']) : $model->getLocalizedAttribute($locale, $field_data['name']);
Expand Down
4 changes: 2 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function __construct(array $aliases = [])
*/
public function make(string $alias, string $type)
{
if (!array_key_exists($alias, $this->aliases[$type])) {
if (!array_key_exists(strtolower($alias), $this->aliases[$type])) {
throw new InvalidAliasException(sprintf('Alias "%s" for type "%s" not registered', $alias, $type));
}

$class = $this->aliases[$type][$alias];
$class = $this->aliases[$type][strtolower($alias)];
return new $class($this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Models/TranslatableModelAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function saveTranslations(): void
return;
}
$isUpdated = false;
foreach (config('app.locales') as $locale) {
foreach (config('easy_form.config.locales') as $locale) {
$_data = [];
foreach ($this->request_translations as $attr => $translations) {
$_data[$attr] = $translations[$locale];
Expand Down
7 changes: 7 additions & 0 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public function register()
{
$this->mergeConfigFrom($this->getAliasesConfigPath(), 'easy_form.aliases');
$this->mergeConfigFrom($this->getFormsConfigPath(), 'easy_form.forms');
$this->mergeConfigFrom($this->getMainConfigPath(), 'easy_form.config');

$this->app->singleton(Creator::class, function () {
$configResolver = $this->app->make('config');
Expand All @@ -25,11 +26,17 @@ public function boot()

$this->publishes([
$this->getAliasesConfigPath() => config_path('easy_form/aliases.php'),
$this->getMainConfigPath() => config_path('easy_form/config.php'),
$this->getFormsConfigPath() => config_path('easy_form/forms.php'),
$this->getViewsPath() => resource_path('views/vendor/easy_form'),
]);
}

private function getMainConfigPath()
{
return __DIR__ . '/resources/config/config.php';
}

private function getAliasesConfigPath()
{
return __DIR__ . '/resources/config/aliases.php';
Expand Down
7 changes: 7 additions & 0 deletions src/resources/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'locales' => [
'en'
],
];

0 comments on commit 82c7c27

Please sign in to comment.