You are here

public function RestfulFormatterHalJson::prepareRow in RESTful 7

Massage the data of a single row.

Parameters

array $row: A single row array.

array $output: The output array, passed by reference.

Return value

array The massaged data of a single row.

2 calls to RestfulFormatterHalJson::prepareRow()
RestfulFormatterHalJson::moveReferencesToEmbeds in plugins/formatter/hal_json/RestfulFormatterHalJson.class.php
Move the fields referencing other resources to the _embed key.
RestfulFormatterHalJson::prepare in plugins/formatter/hal_json/RestfulFormatterHalJson.class.php
Massages the raw data to create a structured array to pass to the renderer.

File

plugins/formatter/hal_json/RestfulFormatterHalJson.class.php, line 140
Contains RestfulFormatterHalJson.

Class

RestfulFormatterHalJson
@file Contains RestfulFormatterHalJson.

Code

public function prepareRow(array $row, array &$output) {
  $this
    ->addHateoasRow($row);
  if (!($curie = $this
    ->getCurie())) {

    // Skip if there is no curie defined.
    return $row;
  }
  $embedded = array();
  foreach ($this->handler
    ->getPublicFields() as $public_field_name => $public_field) {
    if (empty($public_field['resource'])) {

      // Not a resource.
      continue;
    }
    if (empty($row[$public_field_name])) {

      // No value.
      continue;
    }
    $nested_embed = $this->handler
      ->isListRequest();
    if ($nested_embed) {
      $output += array(
        '_embedded' => array(),
      );
    }
    $this
      ->moveReferencesToEmbeds($embedded, $row, $public_field, $public_field_name, $output);
  }
  if (!empty($embedded) && $nested_embed) {
    $row['_embedded'] = $embedded;
  }
  return $row;
}