You are here

public function DataProviderEntity::__construct in RESTful 7.2

Constructor.

Parameters

RequestInterface $request: The request.

ResourceFieldCollectionInterface $field_definitions: The field definitions.

object $account: The account object.

string $plugin_id: The resource ID.

string $resource_path: The resource path.

array $options: The plugin definition options for the data provider.

string $langcode: The entity language code.

Throws

InternalServerErrorException If there is no entity type.

ServerConfigurationException If the field mappings are not for entities.

Overrides DataProvider::__construct

1 call to DataProviderEntity::__construct()
DataProviderFile::__construct in src/Plugin/resource/DataProvider/DataProviderFile.php
Constructs a DataProviderFile object.
1 method overrides DataProviderEntity::__construct()
DataProviderFile::__construct in src/Plugin/resource/DataProvider/DataProviderFile.php
Constructs a DataProviderFile object.

File

src/Plugin/resource/DataProvider/DataProviderEntity.php, line 87
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderEntity.

Class

DataProviderEntity
Class DataProviderEntity.

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public function __construct(RequestInterface $request, ResourceFieldCollectionInterface $field_definitions, $account, $plugin_id, $resource_path, array $options, $langcode = NULL) {
  parent::__construct($request, $field_definitions, $account, $plugin_id, $resource_path, $options, $langcode);
  if (empty($options['entityType'])) {

    // Entity type is mandatory.
    throw new InternalServerErrorException('The entity type was not provided.');
  }
  $this->entityType = $options['entityType'];
  $options += array(
    'bundles' => array(),
  );
  if ($options['bundles']) {
    $this->bundles = $options['bundles'];
  }
  elseif ($options['bundles'] !== FALSE) {

    // If no bundles are passed, then assume all the bundles of the entity
    // type.
    $entity_info = entity_get_info($this->entityType);
    $this->bundles = !empty($entity_info['bundles']) ? array_keys($entity_info['bundles']) : $entity_info['type'];
  }
  if (isset($options['EFQClass'])) {
    $this->EFQClass = $options['EFQClass'];
  }
  $this
    ->setResourcePath($resource_path);
  if (empty($this->options['urlParams'])) {
    $this->options['urlParams'] = array(
      'filter' => TRUE,
      'sort' => TRUE,
      'fields' => TRUE,
      'loadByFieldName' => TRUE,
    );
  }
}