@@ -84,14 +84,31 @@ public function getPlugins($only_enabled = TRUE) {
84
84
* {@inheritdoc}
85
85
*/
86
86
public function getPlugin ($ instance_id , RequestInterface $ request = NULL ) {
87
- return $ this ->massagePlugin ($ this ->plugins ->get ($ instance_id ), $ request );
87
+ /* @var ResourceInterface $plugin */
88
+ if (!$ plugin = $ this ->plugins ->get ($ instance_id )) {
89
+ return NULL ;
90
+ }
91
+ if ($ request ) {
92
+ $ plugin ->setRequest ($ request );
93
+ }
94
+ return $ plugin ;
88
95
}
89
96
90
97
/**
91
98
* {@inheritdoc}
92
99
*/
93
100
public function getPluginCopy ($ instance_id , RequestInterface $ request = NULL ) {
94
- return $ this ->massagePlugin ($ this ->pluginManager ->createInstance ($ instance_id ), $ request );
101
+ if (!$ plugin = $ this ->pluginManager ->createInstance ($ instance_id )) {
102
+ return NULL ;
103
+ }
104
+ if ($ request ) {
105
+ $ plugin ->setRequest ($ request );
106
+ }
107
+ // Allow altering the resource, this way we can read the resource's
108
+ // definition to return a different class that is using composition.
109
+ drupal_alter ('restful_resource ' , $ plugin );
110
+ $ plugin = $ plugin ->isEnabled () ? $ plugin : NULL ;
111
+ return $ plugin ;
95
112
}
96
113
97
114
/**
@@ -318,30 +335,4 @@ public function getResourceLastVersion($resource_name, $major_version = NULL) {
318
335
return array ($ resource ['majorVersion ' ], $ resource ['minorVersion ' ]);
319
336
}
320
337
321
- /**
322
- * Helper method that sets the request and alters the resource.
323
- *
324
- * @param ResourceInterface $plugin
325
- * The resource to return.
326
- * @param RequestInterface $request
327
- * The request.
328
- *
329
- * @return ResourceInterface
330
- * The transformed resource.
331
- */
332
- protected function massagePlugin (ResourceInterface $ plugin = NULL , RequestInterface $ request = NULL ) {
333
- if (!$ plugin ) {
334
- return NULL ;
335
- }
336
- if ($ request ) {
337
- $ plugin ->setRequest ($ request );
338
- }
339
- // Allow altering the resource, this way we can read the resource's
340
- // definition to return a different class that is using composition.
341
- drupal_alter ('restful_resource ' , $ plugin );
342
- $ plugin = $ plugin ->isEnabled () ? $ plugin : NULL ;
343
-
344
- return $ plugin ;
345
- }
346
-
347
338
}
0 commit comments