Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS fixes #17

Merged
merged 1 commit into from
Apr 11, 2024
Merged
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
40 changes: 18 additions & 22 deletions src/Http/Controllers/TranslationManagerCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;

/**
* Class TranslationManagerCrudController
* @package Backpack\TranslationManager\Http\Controllers
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class TranslationManagerCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
Expand All @@ -32,7 +27,7 @@ public function setup(): void
CRUD::setEntityNameStrings(__('backpack.translation-manager::translation_manager.translation_line'), __('backpack.translation-manager::translation_manager.translation_lines'));

// access to edit and delete buttons
CRUD::setAccessCondition(['delete'], fn(TranslationLine $entry) => $entry->database);
CRUD::setAccessCondition(['delete'], fn (TranslationLine $entry) => $entry->database);

// disable create
if (! config('backpack.translation-manager.create', false)) {
Expand All @@ -46,23 +41,23 @@ public function setup(): void
protected function setupListOperation(): void
{
CRUD::addColumn([
'name' => 'text',
'type' => $this->editableColumnsEnabled() ? 'editable_text' : 'text',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.text')),
'value' => fn(TranslationLine $entry): mixed => $entry->getTranslation(App::getLocale()),
'name' => 'text',
'type' => $this->editableColumnsEnabled() ? 'editable_text' : 'text',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.text')),
'value' => fn (TranslationLine $entry): mixed => $entry->getTranslation(App::getLocale()),
'searchLogic' => function (Builder $query, mixed $column, string $search): void {
$query->orWhere('search', 'like', '%'.Str::slug($search).'%');
},
]);

CRUD::addColumn([
'name' => 'group_key',
'name' => 'group_key',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.key')),
'type' => 'custom_html',
'type' => 'custom_html',
'value' => function (TranslationLine $entry): string {
return '<span class="badge" title="'.$entry->group_key.'">'.Str::limit($entry->group_key, 50).'</span>';
},
'orderable' => true,
'orderable' => true,
'orderLogic' => function (Builder $query, mixed $column, mixed $columnDirection): Builder {
return $query
->orderBy('group', $columnDirection)
Expand All @@ -76,11 +71,12 @@ protected function setupListOperation(): void

if (config('backpack.translation-manager.display_source', false)) {
CRUD::addColumn([
'name' => 'database',
'name' => 'database',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.source')),
'type' => 'custom_html',
'type' => 'custom_html',
'value' => function (TranslationLine $entry): string {
$value = $entry->database ? 'database' : 'file';

return '<i class="las la-'.$value.'" title="'.$value.'"></i>';
},
]);
Expand Down Expand Up @@ -111,8 +107,8 @@ protected function setupShowOperation(): void

CRUD::removeColumn('text');
CRUD::addColumn([
'name' => 'text',
'type' => 'translation-preview-table',
'name' => 'text',
'type' => 'translation-preview-table',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.text')),
]);
}
Expand Down Expand Up @@ -173,8 +169,8 @@ public function setupFilters(): void

// group filter
CRUD::addFilter([
'name' => 'group',
'type' => 'select2_multiple',
'name' => 'group',
'type' => 'select2_multiple',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.group')),
], function (): array {
return TranslationLine::select('group')
Expand All @@ -187,12 +183,12 @@ public function setupFilters(): void

// database/file filter
CRUD::addFilter([
'name' => 'source',
'type' => 'select2',
'name' => 'source',
'type' => 'select2',
'label' => ucfirst(__('backpack.translation-manager::translation_manager.source')),
], [
'database' => ucfirst(__('backpack.translation-manager::translation_manager.database')),
'file' => ucfirst(__('backpack.translation-manager::translation_manager.file')),
'file' => ucfirst(__('backpack.translation-manager::translation_manager.file')),
], function (string $option): void {
CRUD::addClause('where', 'database', $option === 'database');
});
Expand Down
Loading