Skip to content

Commit 9b320dd

Browse files
cleanup language switch
1 parent 81a2583 commit 9b320dd

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<select onchange="if(this.value) window.location.href = window.location.pathname + '?lang=' + this.value"
2+
class="fi-input block w-full rounded-lg border-gray-300 shadow-sm outline-none transition duration-75 focus:border-primary-500 focus:ring-1 focus:ring-inset focus:ring-primary-500 disabled:opacity-70 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:focus:border-primary-500">
3+
<option value="">Select Language</option>
4+
@foreach(\Moox\Localization\Models\Localization::all() as $locale)
5+
<option value="{{ $locale->language->alpha2 }}" {{ request()->get('lang') == $locale->language->alpha2 ? 'selected' : '' }}>
6+
{{ $locale->language->common_name }}
7+
</option>
8+
@endforeach
9+
</select>

packages/tag/src/Resources/TagResource.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ public static function table(Table $table): Table
194194
TextColumn::make('translations.locale'),
195195
TextColumn::make('title')
196196
->label(__('core::core.title'))
197-
->searchable()
198197
->limit(30)
199198
->toggleable()
200199
->sortable()
@@ -208,7 +207,6 @@ public static function table(Table $table): Table
208207
}),
209208
TextColumn::make('slug')
210209
->label(__('core::core.slug'))
211-
->searchable()
212210
->toggleable(isToggledHiddenByDefault: false)
213211
->sortable()
214212
->state(function ($record) {
@@ -223,7 +221,6 @@ public static function table(Table $table): Table
223221
->label(__('core::core.content'))
224222
->sortable()
225223
->limit(30)
226-
->searchable()
227224
->toggleable()
228225
->state(function ($record) {
229226
$lang = request()->get('lang');

packages/tag/src/Resources/TagResource/Pages/CreateTag.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Moox\Tag\Resources\TagResource\Pages;
66

77
use Filament\Resources\Pages\CreateRecord;
8-
use Illuminate\Database\Eloquent\Model;
98
use Moox\Tag\Resources\TagResource;
109
use Override;
10+
use Illuminate\Database\Eloquent\Model;
1111

1212
class CreateTag extends CreateRecord
1313
{
@@ -26,26 +26,24 @@ public function mount(): void
2626
protected function handleRecordCreation(array $data): Model
2727
{
2828
$model = static::getModel();
29-
// Create new record instance
30-
$record = new $model;
31-
32-
// Get translatable attributes
29+
30+
$record = new $model();
31+
3332
$translatableAttributes = ['title', 'slug', 'content'];
3433
$translationData = array_intersect_key($data, array_flip($translatableAttributes));
3534
$nonTranslatableData = array_diff_key($data, array_flip($translatableAttributes));
36-
37-
// Fill non-translatable data
35+
3836
$record->fill($nonTranslatableData);
3937
$record->save();
40-
// Handle translations
38+
4139
if ($this->selectedLang) {
4240
$record->translateOrNew($this->selectedLang)->fill($translationData);
4341
} else {
4442
$record->translateOrNew(app()->getLocale())->fill($translationData);
4543
}
46-
44+
4745
$record->save();
48-
46+
4947
return $record;
5048
}
5149

@@ -60,4 +58,4 @@ protected function getFormActions(): array
6058
{
6159
return [];
6260
}
63-
}
61+
}

packages/tag/src/TagServiceProvider.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Moox\Tag\Commands\InstallCommand;
1111
use Moox\Tag\Resources\TagResource\Pages\ListTags;
1212
use Spatie\LaravelPackageTools\Package;
13+
use Moox\Localization\Models\Locale;
1314
use Spatie\LaravelPackageTools\PackageServiceProvider;
1415

1516
class TagServiceProvider extends PackageServiceProvider
@@ -29,16 +30,7 @@ public function packageBooted(): void
2930
{
3031
FilamentView::registerRenderHook(
3132
TablesRenderHook::TOOLBAR_TOGGLE_COLUMN_TRIGGER_BEFORE,
32-
fn (): string => Blade::render('
33-
<select onchange="window.location.href = window.location.pathname + \'?lang=\' + this.value" class="fi-input block w-full rounded-lg border-gray-300 shadow-sm outline-none transition duration-75 focus:border-primary-500 focus:ring-1 focus:ring-inset focus:ring-primary-500 disabled:opacity-70 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:focus:border-primary-500">
34-
<option value="">Select Language</option>
35-
<option value="en">English</option>
36-
<option value="fr">French</option>
37-
<option value="es">Spanish</option>
38-
<option value="de">German</option>
39-
<option value="it">Italian</option>
40-
</select>
41-
'),
33+
fn (): string => Blade::render('@include("localization::lang-selector")'),
4234
scopes: ListTags::class
4335
);
4436
}

0 commit comments

Comments
 (0)