You are here

protected function FormatterJsonApi::populateIncludes in RESTful 7.2

Gather all of the includes.

1 call to FormatterJsonApi::populateIncludes()
FormatterJsonApi::prepare in src/Plugin/formatter/FormatterJsonApi.php
Massages the raw data to create a structured array to pass to the renderer.

File

src/Plugin/formatter/FormatterJsonApi.php, line 379
Contains \Drupal\restful\Plugin\formatter\FormatterJsonApi.

Class

FormatterJsonApi
Class FormatterJsonApi @package Drupal\restful\Plugin\formatter

Namespace

Drupal\restful\Plugin\formatter

Code

protected function populateIncludes($output, $included) {

  // Loop through the included resource entities and add them to the output if
  // they are included from the request.
  $input = $this
    ->getRequest()
    ->getParsedInput();
  $requested_includes = empty($input['include']) ? array() : explode(',', $input['include']);

  // Keep track of everything that has been included.
  $included_keys = array();
  foreach ($requested_includes as $requested_include) {
    if (empty($included[$requested_include])) {
      continue;
    }
    foreach ($included[$requested_include] as $include_key => $included_item) {
      if (in_array($include_key, $included_keys)) {
        continue;
      }
      $output['included'][] = $included_item;
      $included_keys[] = $include_key;
    }
  }
  return $output;
}