@@ -25,6 +25,17 @@ public function match(object $provider): bool
2525
2626 public function getItem (object $ provider , int |string $ identifier ): DataObject
2727 {
28+ /** @var ArrayProviderInterface $provider */
29+ $ rows = $ provider ->getData ();
30+ $ primaryKey = $ this ->getPrimaryKey ($ provider );
31+ if (!empty ($ primaryKey )) {
32+ foreach ($ rows as $ row ) {
33+ if (isset ($ row [$ primaryKey ]) && $ row [$ primaryKey ] == $ identifier ) {
34+ return $ this ->dataObjectFactory ->create ()->setData ($ row );
35+ }
36+ }
37+ }
38+
2839 throw new RuntimeException ('Unable to retrieve item from array ' );
2940 }
3041
@@ -93,6 +104,9 @@ public function getItems(object $provider, GridState $gridState): array
93104
94105 public function saveItem (object $ provider , DataObject $ item )
95106 {
107+ if (method_exists ($ provider , 'saveItem ' )) {
108+ call_user_func ([$ provider , 'saveItem ' ], $ item );
109+ }
96110 }
97111
98112 public function deleteItem (object $ provider , DataObject $ item )
@@ -121,4 +135,13 @@ public function getResourceModelClass(object $provider): bool|string
121135 {
122136 return false ;
123137 }
138+
139+ public function getPrimaryKey (object $ provider ): ?string
140+ {
141+ if (method_exists ($ provider , 'getPrimaryKey ' )) {
142+ return call_user_func ([$ provider , 'getPrimaryKey ' ]);
143+ }
144+
145+ return null ;
146+ }
124147}
0 commit comments