OData client implements configuration entity for OData servers, IO functions to OData collections and Drupal format OdataQuery object.
The module requires the following library:
- saintsystems/odata-client: ^0.2.4
Install as you would normally install a contributed Drupal module. Visit: https://www.drupal.org/documentation/install/modules-themes/modules-8 for further information.
- Go to /admin/structure/odata_server and create new server configuration
After made a server configuration name default able to connect to server:
$odata_client = \Drupal::service('odata_client.io');
$odata_client->connect('default');
In configuration can define the default collection but may to change it:
$odata_client->setCollection('People');
Return the data of element key 'russellwhyte':
$result = $odata_client->find('russellwhyte');
Return elements count the collection:
$result = $odata_client->count();
Create new element in collection:
$data = array (
'UserName' => 'teresa',
'FirstName' => 'Teresa',
'LastName' => 'Gilbert',
'Gender' => 'Female',
'Emails' =>
array (
0 => '[email protected]',
1 => '[email protected]',
),
'AddressInfo' =>
array (
0 =>
array (
'Address' => '1 Suffolk Ln.',
'City' =>
array (
'CountryRegion' => 'United States',
'Name' => 'Boise',
'Region' => 'ID',
),
),
),
);
$result = $odata_client->post($data);
Return max 4 elements FirstName and LastName columns where FirstName is Teresa, sort by LastName descending:
$query = \Drupal::service('odata_client.query');
$query->connect('default')
->fields(['FirstName','LastName'])
->condition('FirstName', 'Teresa')
->orderBy('LastName', 'desc');
->range(0, 4);
$result = $query->execute();
Current maintainer:
- Jozsef Dudas (dj199) - https://www.drupal.org/user/387119
#Supporting organizations: Brainsum Kft. sponsored