public function ResourceManager::getPluginCopy in RESTful 7.2
Get a copy of resource plugin instance by instance ID.
This is useful when you have sub-requests, since you don't want to change state to other resources.
Parameters
string $instance_id: The instance ID.
RequestInterface $request: The request object.
Return value
ResourceInterface The plugin.
Throws
PluginNotFoundException If the plugin instance cannot be found.
Overrides ResourceManagerInterface::getPluginCopy
File
- src/
Resource/ ResourceManager.php, line 100 - Contains \Drupal\restful\Resource\ResourceManager.
Class
Namespace
Drupal\restful\ResourceCode
public function getPluginCopy($instance_id, RequestInterface $request = NULL) {
if (!($plugin = $this->pluginManager
->createInstance($instance_id))) {
return NULL;
}
if ($request) {
$plugin
->setRequest($request);
}
// Allow altering the resource, this way we can read the resource's
// definition to return a different class that is using composition.
drupal_alter('restful_resource', $plugin);
$plugin = $plugin
->isEnabled() ? $plugin : NULL;
return $plugin;
}