View source
<?php
namespace Drupal\restful\Plugin\resource\DataProvider;
use Drupal\Component\Plugin\PluginBase;
use Drupal\restful\Http\Request;
use Drupal\restful\Plugin\resource\ResourceInterface;
use Drupal\restful\Http\RequestInterface;
use Drupal\restful\Plugin\resource\Field\ResourceFieldCollectionInterface;
use Drupal\restful\Plugin\ResourcePluginManager;
class DataProviderResource extends DataProvider implements DataProviderResourceInterface {
protected $resource;
protected $referencedDataProvider;
public function __construct(RequestInterface $request, ResourceFieldCollectionInterface $field_definitions, $account, $plugin_id, $resource_path, array $options, $langcode = NULL, ResourceInterface $resource = NULL) {
$resource
->setRequest($request);
$this->resource = $resource;
$this->referencedDataProvider = $resource
->getDataProvider();
parent::__construct($request, $field_definitions, $account, $plugin_id, $resource_path, $options, $langcode);
}
public static function init(RequestInterface $request, $resource_name, array $version, $resource_path = NULL) {
$instance_id = $resource_name . PluginBase::DERIVATIVE_SEPARATOR . $version[0] . '.' . $version[1];
$resource = restful()
->getResourceManager()
->getPluginCopy($instance_id, Request::create('', array(), RequestInterface::METHOD_GET));
$plugin_definition = $resource
->getPluginDefinition();
$resource
->setPath($resource_path);
return new static($request, $resource
->getFieldDefinitions(), $resource
->getAccount(), $resource
->getPluginId(), $resource
->getPath(), $plugin_definition['dataProvider'], static::getLanguage(), $resource);
}
public function index() {
return $this->referencedDataProvider
->index();
}
public function getIndexIds() {
return $this->referencedDataProvider
->getIndexIds();
}
public function create($object) {
return $this->referencedDataProvider
->create($object);
}
public function view($identifier) {
return $this->referencedDataProvider
->view($identifier);
}
public function viewMultiple(array $identifiers) {
return $this->referencedDataProvider
->viewMultiple($identifiers);
}
public function update($identifier, $object, $replace = FALSE) {
return $this->referencedDataProvider
->update($identifier, $object, $replace);
}
public function remove($identifier) {
$this->referencedDataProvider
->remove($identifier);
}
public function merge($identifier, $object) {
if (!$identifier) {
return $this->referencedDataProvider
->create($object);
}
$replace = ($method = $this
->getRequest()
->getMethod()) ? $method == RequestInterface::METHOD_PUT : FALSE;
return $this->referencedDataProvider
->update($identifier, $object, $replace);
}
public function count() {
return $this->referencedDataProvider
->count();
}
protected function initDataInterpreter($identifier) {
return NULL;
}
}