You are here

class DataProviderResource in RESTful 7.2

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

Class DataProviderResource @package Drupal\restful\Plugin\resource\DataProvider

Hierarchy

Expanded class hierarchy of DataProviderResource

1 file declares its use of DataProviderResource
ResourceFieldEntityReference.php in src/Plugin/resource/Field/ResourceFieldEntityReference.php
Contains \Drupal\restful\Plugin\resource\Field\ResourceFieldEntityReference.

File

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

Namespace

Drupal\restful\Plugin\resource\DataProvider
View source
class DataProviderResource extends DataProvider implements DataProviderResourceInterface {

  /**
   * The referenced resource.
   *
   * @var ResourceInterface
   */
  protected $resource;

  /**
   * The referenced data provider.
   *
   * @var DataProviderInterface
   */
  protected $referencedDataProvider;

  /**
   * Constructor.
   *
   * @param RequestInterface $request
   *   The request.
   * @param ResourceFieldCollectionInterface $field_definitions
   *   The field definitions.
   * @param object $account
   *   The authenticated account.
   * @param string $plugin_id
   *   The resource ID.
   * @param string $resource_path
   *   The resource path.
   * @param array $options
   *   The plugin options for the data provider.
   * @param string $langcode
   *   (Optional) The entity language code.
   * @param ResourceInterface $resource
   *   The referenced resource.
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  public function index() {
    return $this->referencedDataProvider
      ->index();
  }

  /**
   * {@inheritdoc}
   */
  public function getIndexIds() {
    return $this->referencedDataProvider
      ->getIndexIds();
  }

  /**
   * {@inheritdoc}
   */
  public function create($object) {
    return $this->referencedDataProvider
      ->create($object);
  }

  /**
   * {@inheritdoc}
   */
  public function view($identifier) {
    return $this->referencedDataProvider
      ->view($identifier);
  }

  /**
   * {@inheritdoc}
   */
  public function viewMultiple(array $identifiers) {
    return $this->referencedDataProvider
      ->viewMultiple($identifiers);
  }

  /**
   * {@inheritdoc}
   */
  public function update($identifier, $object, $replace = FALSE) {
    return $this->referencedDataProvider
      ->update($identifier, $object, $replace);
  }

  /**
   * {@inheritdoc}
   */
  public function remove($identifier) {
    $this->referencedDataProvider
      ->remove($identifier);
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  public function count() {
    return $this->referencedDataProvider
      ->count();
  }

  /**
   * {@inheritdoc}
   */
  protected function initDataInterpreter($identifier) {
    return NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DataProvider::$account protected property The account authenticated from the request for entity access checks.
DataProvider::$fieldDefinitions protected property The field definitions.
DataProvider::$langcode protected property Determines the language of the items that should be returned.
DataProvider::$metadata protected property Array of metadata. Use this as a mean to pass info to the render layer.
DataProvider::$options protected property User defined options.
DataProvider::$pluginId protected property Resource identifier.
DataProvider::$range protected property Determines the number of items that should be returned when viewing lists.
DataProvider::$request protected property The request
DataProvider::$resourcePath protected property The resource path.
DataProvider::addExtraInfoToQuery protected function Adds query tags and metadata to the EntityFieldQuery. 2
DataProvider::addOptions public function Adds the options in the provided array to the data provider options. Overrides DataProviderInterface::addOptions
DataProvider::canonicalPath public function Generates the canonical path for a given path. Overrides DataProviderInterface::canonicalPath 1
DataProvider::discover public function Return the discovery information for the given entity. Overrides DataProviderInterface::discover
DataProvider::getAccount public function Gets the authenticated account. Overrides DataProviderInterface::getAccount
DataProvider::getCacheFragments public function Gets the entity context. Overrides DataProviderInterface::getCacheFragments 3
DataProvider::getLangCode public function Get the language code. Overrides DataProviderInterface::getLangCode
DataProvider::getLanguage protected static function Gets the global language.
DataProvider::getMetadata public function Returns the metadata collection. Overrides DataProviderInterface::getMetadata
DataProvider::getOptions public function Gets the data provider options. Overrides DataProviderInterface::getOptions
DataProvider::getRange public function Gets the range. Overrides DataProviderInterface::getRange
DataProvider::getRequest public function Gets the request. Overrides DataProviderInterface::getRequest
DataProvider::getResourcePath public function Get the resource path. Overrides DataProviderInterface::getResourcePath
DataProvider::initResourceFieldCollection protected function Initialize the empty resource field collection to bundle the output.
DataProvider::isNestedField public static function Checks if the passed in string is a dot-nested field. Overrides DataProviderInterface::isNestedField
DataProvider::isValidConjunctionForFilter protected static function Check if a conjunction is valid for filtering. 1
DataProvider::isValidOperatorsForFilter protected static function Check if an operator is valid for filtering. 1
DataProvider::methodAccess public function Checks if the provided field can be used with the current method. Overrides DataProviderInterface::methodAccess
DataProvider::parseRequestForListFilter protected function Filter the query for list.
DataProvider::parseRequestForListPagination protected function Parses the request object to get the pagination options.
DataProvider::parseRequestForListSort protected function Parses the request to get the sorting options.
DataProvider::processFilterInput public static function Processes the input for a filter and adds the appropriate defaults. Overrides DataProviderInterface::processFilterInput
DataProvider::setAccount public function Sets the authenticated account. Overrides DataProviderInterface::setAccount
DataProvider::setHttpHeader protected function Sets an HTTP header.
DataProvider::setLangCode public function Sets the language code. Overrides DataProviderInterface::setLangCode
DataProvider::setOptions public function Sets the options. Overrides DataProviderInterface::setOptions
DataProvider::setRange public function Sets the range. Overrides DataProviderInterface::setRange
DataProvider::setRequest public function Sets the request. Overrides DataProviderInterface::setRequest
DataProvider::setResourcePath public function Set the resource path. Overrides DataProviderInterface::setResourcePath
DataProviderResource::$referencedDataProvider protected property The referenced data provider.
DataProviderResource::$resource protected property The referenced resource.
DataProviderResource::count public function Counts the total results for the index call. Overrides CrudInterface::count
DataProviderResource::create public function Create operation. Overrides CrudInterface::create
DataProviderResource::getIndexIds public function Returns the ID to render for the current index GET request. Overrides DataProviderInterface::getIndexIds
DataProviderResource::index public function List operation. Overrides DataProvider::index
DataProviderResource::init public static function Creates a new DataProviderResource object from the resource info. Overrides DataProviderResourceInterface::init
DataProviderResource::initDataInterpreter protected function Get the data interpreter. Overrides DataProvider::initDataInterpreter
DataProviderResource::merge public function Create or update an item based on the payload. Overrides DataProviderResourceInterface::merge
DataProviderResource::remove public function Delete operation. Overrides CrudInterface::remove
DataProviderResource::update public function Update operation. Overrides CrudInterface::update
DataProviderResource::view public function Read operation. Overrides CrudInterface::view
DataProviderResource::viewMultiple public function Read operation. Overrides CrudInterface::viewMultiple
DataProviderResource::__construct public function Constructor. Overrides DataProvider::__construct