You are here

public function EntityNormalizerValue::rasterizeValue in JSON:API 8

Get the rasterized value.

Return value

mixed The value.

Overrides ValueExtractorInterface::rasterizeValue

File

src/Normalizer/Value/EntityNormalizerValue.php, line 93

Class

EntityNormalizerValue
Helps normalize entities in compliance with the JSON API spec.

Namespace

Drupal\jsonapi\Normalizer\Value

Code

public function rasterizeValue() {

  // Create the array of normalized fields, starting with the URI.
  $rasterized = [
    'type' => $this->context['resource_type']
      ->getTypeName(),
    'id' => $this->entity
      ->uuid(),
    'attributes' => [],
    'relationships' => [],
  ];
  $rasterized['links'] = [
    'self' => $this->linkManager
      ->getEntityLink($rasterized['id'], $this->context['resource_type'], [], 'individual'),
  ];
  foreach ($this
    ->getValues() as $field_name => $normalizer_value) {
    $rasterized[$normalizer_value
      ->getPropertyType()][$field_name] = $normalizer_value
      ->rasterizeValue();
  }
  return array_filter($rasterized);
}