You are here

public function DataProviderDbQuery::__construct in RESTful 7.2

Constructor.

Parameters

RequestInterface $request: The request.

ResourceFieldCollectionInterface $field_definitions: The field definitions.

object $account: The authenticated account.

string $plugin_id: The resource ID.

string $resource_path: The resource path.

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

string $langcode: (Optional) The entity language code.

Overrides DataProvider::__construct

File

src/Plugin/resource/DataProvider/DataProviderDbQuery.php, line 54
Contains \Drupal\restful\Plugin\resource\DataProvider\DataProviderDbQuery.

Class

DataProviderDbQuery

Namespace

Drupal\restful\Plugin\resource\DataProvider

Code

public function __construct(RequestInterface $request, ResourceFieldCollectionInterface $field_definitions, $account, $plugin_id, $resource_path = NULL, array $options = array(), $langcode = NULL) {
  parent::__construct($request, $field_definitions, $account, $plugin_id, $resource_path, $options, $langcode);

  // Validate keys exist in the plugin's "data provider options".
  $required_keys = array(
    'tableName',
    'idColumn',
  );
  $required_callback = function ($required_key) {
    if (!$this->options[$required_key]) {
      throw new ServiceUnavailableException(sprintf('%s is missing "%s" property in the "dataProvider" key of the $plugin', get_class($this), $required_key));
    }
  };
  array_walk($required_keys, $required_callback);
  $this->tableName = $this->options['tableName'];
  $this->idColumn = $this->options['idColumn'];
  $this->primary = empty($this->options['primary']) ? NULL : ($this->primary = $this->options['primary']);
}