You are here

protected function ConfigEntityNormalizer::prepareInput in JSON:API Extras 8.2

Prepares the input data to create the entity.

Parameters

array $data: The input data to modify.

\Drupal\jsonapi\ResourceType\ResourceType $resource_type: Contains the info about the resource type.

Return value

array The modified input data.

Overrides EntityNormalizerTrait::prepareInput

File

src/Normalizer/ConfigEntityNormalizer.php, line 35

Class

ConfigEntityNormalizer
Override ConfigEntityNormalizer to prepare input.

Namespace

Drupal\jsonapi_extras\Normalizer

Code

protected function prepareInput(array $data, ResourceType $resource_type, $format = NULL, array $context = []) {
  foreach ($data as $public_field_name => &$field_value) {

    /** @var \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerInterface $enhancer */
    $enhancer = $resource_type
      ->getFieldEnhancer($public_field_name);
    if (!$enhancer) {
      continue;
    }
    $field_value = $enhancer
      ->transform($field_value);
  }
  return parent::prepareInput($data, $resource_type, $format, $context);
}