You are here

public static function DataProviderResource::init in RESTful 7.2

Creates a new DataProviderResource object from the resource info.

Parameters

RequestInterface $request: The request.

string $resource_name: The resource name.

array $version: The first position is the major version, the second is the minor version.

Return value

DataProviderResourceInterface The data provider.

Overrides DataProviderResourceInterface::init

1 call to DataProviderResource::init()
ResourceFieldEntityReference::mergeEntityFromReference in src/Plugin/resource/Field/ResourceFieldEntityReference.php
Helper function; Create an entity from a a sub-resource.

File

src/Plugin/resource/DataProvider/DataProviderResource.php, line 69
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderResource.

Class

DataProviderResource
This data provider creates a resource and uses it to access the data.

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public static function init(RequestInterface $request, $resource_name, array $version, $resource_path = NULL) {

  /* @var ResourceInterface $resource */
  $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);
}