You are here

class RenderNormalizer in REST Views 8

Same name and namespace in other branches
  1. 2.0.x src/Normalizer/RenderNormalizer.php \Drupal\rest_views\Normalizer\RenderNormalizer

Unwrap a RenderableData object and render the element inside.

@package Drupal\rest_views\Normalizer

Hierarchy

Expanded class hierarchy of RenderNormalizer

1 file declares its use of RenderNormalizer
EntityFieldExportTest.php in tests/src/Unit/EntityFieldExportTest.php
1 string reference to 'RenderNormalizer'
rest_views.services.yml in ./rest_views.services.yml
rest_views.services.yml
1 service uses RenderNormalizer
serializer.normalizer.render in ./rest_views.services.yml
Drupal\rest_views\Normalizer\RenderNormalizer

File

src/Normalizer/RenderNormalizer.php, line 14

Namespace

Drupal\rest_views\Normalizer
View source
class RenderNormalizer extends NormalizerBase {

  /**
   * The interface or class that this Normalizer supports.
   *
   * @var array
   */
  protected $supportedInterfaceOrClass = [
    RenderableData::class,
  ];

  /**
   * The renderer service.
   *
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;

  /**
   * DataNormalizer constructor.
   *
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer service.
   */
  public function __construct(RendererInterface $renderer) {
    $this->renderer = $renderer;
  }

  /**
   * {@inheritdoc}
   *
   * @throws \Exception
   */
  public function normalize($object, $format = NULL, array $context = []) {

    /** @var \Drupal\rest_views\SerializedData $object */

    /** @var \Symfony\Component\Serializer\Normalizer\NormalizerInterface $normalizer */
    $normalizer = $this->serializer;
    $data = $object
      ->getData();
    return $normalizer
      ->normalize($this->renderer
      ->render($data));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableNormalizerInterface::SERIALIZATION_CONTEXT_CACHEABILITY constant Name of key for bubbling cacheability metadata via serialization context.
NormalizerBase::$format protected property List of formats which supports (de-)normalization. 3
NormalizerBase::addCacheableDependency protected function Adds cacheability if applicable.
NormalizerBase::checkFormat protected function Checks if the provided format is supported by this normalizer. 2
NormalizerBase::supportsDenormalization public function Implements \Symfony\Component\Serializer\Normalizer\DenormalizerInterface::supportsDenormalization() 1
NormalizerBase::supportsNormalization public function Checks whether the given class is supported for normalization by this normalizer. 1
RenderNormalizer::$renderer protected property The renderer service.
RenderNormalizer::$supportedInterfaceOrClass protected property The interface or class that this Normalizer supports. Overrides NormalizerBase::$supportedInterfaceOrClass
RenderNormalizer::normalize public function
RenderNormalizer::__construct public function DataNormalizer constructor.