You are here

public function EntityNormalizerTrait::normalize in JSON:API Extras 8

File

src/Normalizer/EntityNormalizerTrait.php, line 61

Class

EntityNormalizerTrait
Common code for entity normalizers.

Namespace

Drupal\jsonapi_extras\Normalizer

Code

public function normalize($entity, $format = NULL, array $context = []) {
  $output = parent::normalize($entity, $format, $context);

  /** @var \Drupal\jsonapi\ResourceType\ResourceType $resource_type */
  $resource_type = $context['resource_type'];
  $entity_type_id = $resource_type
    ->getEntityTypeId();
  $bundle_id = $resource_type
    ->getBundle();

  // The output depends on the configuration entity for caching.
  if ($resource_config = $this
    ->getResourceConfig($entity_type_id, $bundle_id)) {
    $context['cacheable_metadata']
      ->addCacheableDependency($resource_config);
  }
  $context['cacheable_metadata']
    ->addCacheableDependency(\Drupal::config('jsonapi_extras.settings'));
  return $output;
}