You are here

protected function SingleNestedEnhancer::doTransform in JSON:API Extras 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/jsonapi/FieldEnhancer/SingleNestedEnhancer.php \Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer\SingleNestedEnhancer::doTransform()

File

src/Plugin/jsonapi/FieldEnhancer/SingleNestedEnhancer.php, line 48

Class

SingleNestedEnhancer
Perform additional manipulations to date fields.

Namespace

Drupal\jsonapi_extras\Plugin\jsonapi\FieldEnhancer

Code

protected function doTransform($data, Context $context) {
  $input = $data;
  $configuration = $this
    ->getConfiguration();
  $path = $configuration['path'];
  $path_parts = explode('.', $path);

  // Start wrapping up until there are no more path parts.
  while ($path_part = array_pop($path_parts)) {
    $input = [
      $path_part => $input,
    ];
  }
  return $input;
}