You are here

protected function EntityShareCronService::getPage in Entity Share Cron 8

Same name and namespace in other branches
  1. 8.2 src/EntityShareCronService.php \Drupal\entity_share_cron\EntityShareCronService::getPage()
  2. 3.0.x src/EntityShareCronService.php \Drupal\entity_share_cron\EntityShareCronService::getPage()

Returns the page data to import entities.

Parameters

string $remote_id: The ID of the remote the channel belongs to.

string $channel_id: The ID of the channel to be synchronized.

string $url: The URL of the page.

Return value

array An associative array with the following keys:

  • data => parsed JSON of entities to import.
  • next => URL of the next page.
1 call to EntityShareCronService::getPage()
EntityShareCronService::sync in src/EntityShareCronService.php
Synchronizes entities starting from provided channel URL.

File

src/EntityShareCronService.php, line 148

Class

EntityShareCronService
Entity Share Cron service.

Namespace

Drupal\entity_share_cron

Code

protected function getPage($remote_id, $channel_id, $url) {
  $data = [
    'data' => [],
    'next' => FALSE,
  ];
  if ($remote = Remote::load($remote_id)) {

    // Makes request to get profiles.
    $this->jsonapiHelper
      ->setRemote($remote);
    $http_client = $this->remoteManager
      ->prepareJsonApiClient($remote);
    $json_response = $http_client
      ->get($url)
      ->getBody()
      ->getContents();

    // Parses the JSON of entities to import.
    $json = Json::decode($json_response);
    $data['data'] = $this->jsonapiHelper
      ->prepareData($json['data']);

    // Gets the URL of the next page.
    $data['next'] = !empty($json['links']['next']) ? $json['links']['next'] : FALSE;
  }
  return $data;
}