Skip to content

Commit eaaea79

Browse files
committed
wip
1 parent 7b2148b commit eaaea79

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/resources/views/crud/reorder.blade.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
trans('backpack::crud.reorder') => false,
88
];
99
10+
$columns = $crud->getOperationSetting('reorderColumnNames');
11+
1012
// if breadcrumbs aren't defined in the CrudController, use the default breadcrumbs
1113
$breadcrumbs = $breadcrumbs ?? $defaultBreadcrumbs;
1214
@endphp
@@ -24,9 +26,11 @@
2426
@endsection
2527

2628
@section('content')
27-
<?php
28-
function tree_element($entry, $key, $all_entries, $crud)
29-
{
29+
<?php
30+
if(!function_exists('tree_element')) {
31+
function tree_element($entry, $key, $all_entries, $crud) {
32+
$columns = $crud->getOperationSetting('reorderColumnNames');
33+
3034
if (! isset($entry->tree_element_shown)) {
3135
// mark the element as shown
3236
$all_entries[$key]->tree_element_shown = true;
@@ -39,12 +43,12 @@ function tree_element($entry, $key, $all_entries, $crud)
3943
// see if this element has any children
4044
$children = [];
4145
foreach ($all_entries as $key => $subentry) {
42-
if ($subentry->parent_id == $entry->getKey()) {
46+
if ($subentry->{$columns['parent_id']} == $entry->getKey()) {
4347
$children[] = $subentry;
4448
}
4549
}
4650
47-
$children = collect($children)->sortBy('lft');
51+
$children = collect($children)->sortBy($columns['lft']);
4852
4953
// if it does have children, show them
5054
if (count($children)) {
@@ -59,6 +63,7 @@ function tree_element($entry, $key, $all_entries, $crud)
5963
6064
return $entry;
6165
}
66+
}
6267
6368
?>
6469

@@ -68,15 +73,15 @@ function tree_element($entry, $key, $all_entries, $crud)
6873
<p>{{ trans('backpack::crud.reorder_text') }}</p>
6974

7075
<ol class="sortable mt-0 mb-0">
71-
<?php
72-
$all_entries = collect($entries->all())->sortBy('lft')->keyBy($crud->getModel()->getKeyName());
73-
$root_entries = $all_entries->filter(function ($item) {
74-
return $item->parent_id == 0;
75-
});
76-
foreach ($root_entries as $key => $entry) {
77-
$root_entries[$key] = tree_element($entry, $key, $all_entries, $crud);
78-
}
79-
?>
76+
<?php
77+
$all_entries = collect($entries->all())->sortBy($columns['lft'])->keyBy($crud->getModel()->getKeyName());
78+
$root_entries = $all_entries->filter(function ($item) use ($columns) {
79+
return $item->{$columns['parent_id']} == 0;
80+
});
81+
foreach ($root_entries as $key => $entry) {
82+
$root_entries[$key] = tree_element($entry, $key, $all_entries, $crud);
83+
}
84+
?>
8085
</ol>
8186

8287
</div>{{-- /.card --}}

0 commit comments

Comments
 (0)