-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return [ | ||
'label' => 'Copy Translation', | ||
'copy translation for :label' => 'Copy translation for :label', | ||
'success notification' => 'Translation copied successfully.', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Codedor\TranslatableTabs\Actions; | ||
|
||
use Filament\Actions\Action; | ||
use Filament\Forms\Components\Select; | ||
use Livewire\Component; | ||
use Throwable; | ||
|
||
class CopyTranslationAction extends Action | ||
{ | ||
private array $locales = []; | ||
|
||
public static function getDefaultName(): ?string | ||
{ | ||
return 'copy-translation'; | ||
} | ||
|
||
public function locales(array $locales) : self | ||
{ | ||
$this->locales = $locales; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLocales(): array | ||
{ | ||
return $this->locales; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label(__('filament-translatable-tabs::copy-translation.label')); | ||
|
||
$this->modalHeading(fn (): string => __('filament-translatable-tabs::copy-translation.copy translation for :label', ['label' => $this->getRecordTitle()])); | ||
|
||
$this->successNotificationTitle(__('filament-translatable-tabs::copy-translation.success notification')); | ||
|
||
$this->form([ | ||
Select::make('from_locale') | ||
->options($this->getLocales()) | ||
->required(), | ||
|
||
Select::make('to_locale') | ||
->options($this->getLocales()) | ||
->required() | ||
->different('from_locale'), | ||
]); | ||
|
||
$this->action(function (array $data, Component $livewire) { | ||
try { | ||
$livewire->data[$data['to_locale']] = $livewire->data[$data['from_locale']]; | ||
|
||
$this->success(); | ||
} catch (Throwable $e) { | ||
$this->failure(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters