22
33namespace Loki \AdminComponents \Component \Form ;
44
5+ use Loki \AdminComponents \Ui \Button \ButtonsResolver ;
56use Loki \AdminComponents \Form \Field \Field ;
67use Loki \AdminComponents \Form \Field \FieldFactory ;
7- use Loki \AdminComponents \Form \FieldResolver ;
8+ use Loki \AdminComponents \Form \Field \ FieldResolver ;
89use Loki \AdminComponents \Form \Fieldset \Fieldset ;
910use Loki \AdminComponents \Form \Fieldset \FieldsetFactory ;
1011use Loki \AdminComponents \Form \ItemConvertorInterface ;
11- use Loki \AdminComponents \Ui \Button ;
12- use Loki \AdminComponents \Ui \ButtonFactory ;
12+ use Loki \AdminComponents \Ui \Button \ Button ;
13+ use Loki \AdminComponents \Ui \Button \ ButtonFactory ;
1314use Loki \Components \Component \ComponentViewModel ;
1415use Magento \Framework \App \RequestInterface ;
1516use Magento \Framework \DataObject ;
1617use Magento \Framework \Exception \LocalizedException ;
1718use Magento \Framework \ObjectManagerInterface ;
1819use Magento \Framework \UrlFactory ;
20+ use Throwable ;
1921
2022/**
2123 * @method FormRepository getRepository()
@@ -31,6 +33,7 @@ public function __construct(
3133 protected FieldsetFactory $ fieldsetFactory ,
3234 protected RequestInterface $ request ,
3335 protected FieldResolver $ fieldResolver ,
36+ protected ButtonsResolver $ buttonsResolver ,
3437 protected array $ itemFilters = [],
3538 ) {
3639 }
@@ -53,8 +56,9 @@ private function getItemData(): array
5356 {
5457 try {
5558 $ item = $ this ->getRepository ()->getItem ();
56- } catch ( \ Throwable $ e ) {
59+ } catch ( Throwable $ e ) {
5760 $ this ->getContext ()->getMessageManager ()->addErrorMessage ($ e ->getMessage ());
61+
5862 return [];
5963 }
6064
@@ -77,43 +81,14 @@ public function getIndexUrl(): string
7781
7882 /**
7983 * @return Button[]
80- * @todo Move this to Form
8184 */
8285 public function getButtons (): array
8386 {
84- $ buttonDefinitions = $ this ->getBlock ()->getButtons ();
85- if (!empty ($ buttonDefinitions )) {
86- $ buttons = [];
87- foreach ($ buttonDefinitions as $ buttonDefinition ) {
88- $ buttons [] = $ this ->buttonFactory ->create (
89- method: (string )$ buttonDefinition ['method ' ],
90- label: (string )$ buttonDefinition ['label ' ],
91- cssClass: isset ($ buttonDefinition ['cssClass ' ]) ? (string )$ buttonDefinition ['cssClass ' ] : '' ,
92- url: isset ($ buttonDefinition ['url ' ]) ? (string )$ buttonDefinition ['url ' ] : '' ,
93- primary: $ buttonDefinition ['primary ' ] ?? false ,
94- );
95- }
96-
97- return $ buttons ;
98- }
99-
100- $ item = $ this ->getValue ();
101- if ($ item instanceof DataObject && $ item ->getId () > 0 ) {
102- return [
103- $ this ->buttonFactory ->createCloseAction (),
104- $ this ->buttonFactory ->createDeleteAction (),
105- $ this ->buttonFactory ->createSaveContinueAction (),
106- $ this ->buttonFactory ->createSaveDuplicateAction (),
107- $ this ->buttonFactory ->createSaveCloseAction (),
108- ];
109- }
110-
111- return [
112- $ this ->buttonFactory ->createCloseAction (),
113- $ this ->buttonFactory ->createSaveCloseAction (),
114- // @todo: This looses current changes when creating a new item
115- //$this->buttonFactory->createSaveContinueAction(),
116- ];
87+ return $ this ->buttonsResolver ->resolve (
88+ $ this ->getBlock (),
89+ $ this ->getRepository ()->getProvider (),
90+ $ this ->getValue ()
91+ );
11792 }
11893
11994 /**
0 commit comments