@@ -46,7 +46,12 @@ public function getItem(): ?DataObject
4646 }
4747 }
4848
49- $ item = $ this ->getFactory ()->create ();
49+ try {
50+ $ item = $ this ->getFactory ()->create ();
51+ } catch (RuntimeException $ e ) {
52+ return null ;
53+ }
54+
5055 $ resourceModel = $ this ->getResourceModel ();
5156 if ($ resourceModel ) {
5257 // @todo: Move this into separate class TableSchema (or use core)
@@ -136,13 +141,17 @@ public function getProvider(): object
136141 return $ provider ;
137142 }
138143
144+ if (empty ($ provider )) {
145+ throw new RuntimeException ('No provider for block " ' .$ this ->getBlock ()->getNameInLayout ().'" ' );
146+ }
147+
139148 $ provider = $ this ->objectManager ->get ($ provider );
140149
141150 if (is_object ($ provider )) {
142151 return $ provider ;
143152 }
144153
145- throw new \ RuntimeException ('Empty grid provider for block " ' .$ this ->getBlock ()->getNameInLayout ().'" ' );
154+ throw new RuntimeException ('Empty grid provider for block " ' .$ this ->getBlock ()->getNameInLayout ().'" ' );
146155 }
147156
148157 private function getFactory (): object
@@ -195,9 +204,15 @@ public function getModel(): ?object
195204
196205 public function getResourceModel (): ?AbstractDb
197206 {
207+ try {
208+ $ providerHandler = $ this ->getProviderHandler ();
209+ } catch (RuntimeException $ e ) {
210+ return null ;
211+ }
212+
198213 $ resourceModelClass = $ this ->getBlock ()->getResourceModel ();
199214 if (empty ($ resourceModelClass )) {
200- $ resourceModelClass = $ this -> getProviderHandler () ->getResourceModelClass ($ this ->getProvider ());
215+ $ resourceModelClass = $ providerHandler ->getResourceModelClass ($ this ->getProvider ());
201216 }
202217
203218 if (empty ($ resourceModelClass )) {
@@ -206,11 +221,11 @@ public function getResourceModel(): ?AbstractDb
206221
207222 $ resourceModel = $ this ->objectManager ->get ($ resourceModelClass );
208223 if (empty ($ resourceModel )) {
209- throw new \ RuntimeException ('Unable to instantiate resource model from class " ' .$ resourceModelClass .'" ' );
224+ throw new RuntimeException ('Unable to instantiate resource model from class " ' .$ resourceModelClass .'" ' );
210225 }
211226
212227 if (false === $ resourceModel instanceof AbstractDb) {
213- throw new \ RuntimeException (
228+ throw new RuntimeException (
214229 'Resource model " ' .$ resourceModelClass .'" is not an instance of ' .AbstractDb::class
215230 );
216231 }
0 commit comments