From 479c6c0799ba819ed9008abb0da03546eb883cf6 Mon Sep 17 00:00:00 2001 From: pxpm Date: Fri, 20 Sep 2024 10:20:30 +0100 Subject: [PATCH 1/3] fix save actions throw error when all actions removed --- src/app/Library/CrudPanel/Traits/SaveActions.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/app/Library/CrudPanel/Traits/SaveActions.php b/src/app/Library/CrudPanel/Traits/SaveActions.php index de4d494179..ba72cf6727 100644 --- a/src/app/Library/CrudPanel/Traits/SaveActions.php +++ b/src/app/Library/CrudPanel/Traits/SaveActions.php @@ -275,6 +275,10 @@ public function getSaveAction() //get only the save actions that pass visibility callback $saveOptions = $this->getVisibleSaveActions(); + if (empty($saveOptions)) { + return []; + } + //get the current action $saveCurrent = $this->getCurrentSaveAction($saveOptions); @@ -287,7 +291,7 @@ public function getSaveAction() } return [ - 'active' => $saveCurrent, + 'active' => $saveCurrent, 'options' => $dropdownOptions, ]; } @@ -345,8 +349,8 @@ public function performSaveAction($itemId = null) // if the request is AJAX, return a JSON response if ($this->getRequest()->ajax()) { return response()->json([ - 'success' => true, - 'data' => $this->entry, + 'success' => true, + 'data' => $this->entry, 'redirect_url' => $redirectUrl, 'referrer_url' => $referrer_url ?? false, ]); @@ -368,7 +372,7 @@ public function setupDefaultSaveActions() { $defaultSaveActions = [ [ - 'name' => 'save_and_back', + 'name' => 'save_and_back', 'visible' => function ($crud) { return $crud->hasAccess('list'); }, @@ -378,7 +382,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_back'), ], [ - 'name' => 'save_and_edit', + 'name' => 'save_and_edit', 'visible' => function ($crud) { return $crud->hasAccess('update'); }, @@ -400,7 +404,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_edit'), ], [ - 'name' => 'save_and_new', + 'name' => 'save_and_new', 'visible' => function ($crud) { return $crud->hasAccess('create'); }, From 765c6573b44f3316b53ece2f5df5b30e330bd4b6 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 20 Sep 2024 09:20:45 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI [ci skip] [skip ci] --- src/app/Library/CrudPanel/Traits/SaveActions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/Library/CrudPanel/Traits/SaveActions.php b/src/app/Library/CrudPanel/Traits/SaveActions.php index ba72cf6727..d7d5fa759f 100644 --- a/src/app/Library/CrudPanel/Traits/SaveActions.php +++ b/src/app/Library/CrudPanel/Traits/SaveActions.php @@ -291,7 +291,7 @@ public function getSaveAction() } return [ - 'active' => $saveCurrent, + 'active' => $saveCurrent, 'options' => $dropdownOptions, ]; } @@ -349,8 +349,8 @@ public function performSaveAction($itemId = null) // if the request is AJAX, return a JSON response if ($this->getRequest()->ajax()) { return response()->json([ - 'success' => true, - 'data' => $this->entry, + 'success' => true, + 'data' => $this->entry, 'redirect_url' => $redirectUrl, 'referrer_url' => $referrer_url ?? false, ]); @@ -372,7 +372,7 @@ public function setupDefaultSaveActions() { $defaultSaveActions = [ [ - 'name' => 'save_and_back', + 'name' => 'save_and_back', 'visible' => function ($crud) { return $crud->hasAccess('list'); }, @@ -382,7 +382,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_back'), ], [ - 'name' => 'save_and_edit', + 'name' => 'save_and_edit', 'visible' => function ($crud) { return $crud->hasAccess('update'); }, @@ -404,7 +404,7 @@ public function setupDefaultSaveActions() 'button_text' => trans('backpack::crud.save_action_save_and_edit'), ], [ - 'name' => 'save_and_new', + 'name' => 'save_and_new', 'visible' => function ($crud) { return $crud->hasAccess('create'); }, From be029ad42c21afc1eb5ebc36ab2862bec1b6c19b Mon Sep 17 00:00:00 2001 From: pxpm Date: Fri, 20 Sep 2024 10:22:43 +0100 Subject: [PATCH 3/3] show cancel and delete buttons if no save actions are present --- .../crud/inc/form_save_buttons.blade.php | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/resources/views/crud/inc/form_save_buttons.blade.php b/src/resources/views/crud/inc/form_save_buttons.blade.php index b5d6f3447f..7bcfbd3798 100644 --- a/src/resources/views/crud/inc/form_save_buttons.blade.php +++ b/src/resources/views/crud/inc/form_save_buttons.blade.php @@ -1,5 +1,6 @@ -@if(isset($saveAction['active']) && !is_null($saveAction['active']['value'])) -
+
+ @if(isset($saveAction['active']) && !is_null($saveAction['active']['value'])) + @if(empty($saveAction['options'])) @@ -23,16 +24,16 @@
@endif + @endif + @if(!$crud->hasOperationSetting('showCancelButton') || $crud->getOperationSetting('showCancelButton') == true) +  {{ trans('backpack::crud.cancel') }} + @endif - @if(!$crud->hasOperationSetting('showCancelButton') || $crud->getOperationSetting('showCancelButton') == true) -  {{ trans('backpack::crud.cancel') }} - @endif + @if ($crud->get('update.showDeleteButton') && $crud->get('delete.configuration') && $crud->hasAccess('delete')) + + @endif +
- @if ($crud->get('update.showDeleteButton') && $crud->get('delete.configuration') && $crud->hasAccess('delete')) - - @endif - -@endif @push('after_scripts')