You are here

class RenderableData in REST Views 8

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

Wrapper for renderable data that will be rendered during normalization.

@package Drupal\rest_views

Hierarchy

Expanded class hierarchy of RenderableData

2 files declare their use of RenderableData
EntityReferenceExportFormatter.php in src/Plugin/Field/FieldFormatter/EntityReferenceExportFormatter.php
RenderNormalizer.php in src/Normalizer/RenderNormalizer.php

File

src/RenderableData.php, line 10

Namespace

Drupal\rest_views
View source
class RenderableData {

  /**
   * The render array.
   *
   * @var string
   */
  protected $data;

  /**
   * RenderableData constructor.
   *
   * @param array $data
   *   The render array.
   */
  public function __construct(array $data) {
    $this->data = $data;
  }

  /**
   * Create a renderable data object.
   *
   * @param array $data
   *   The render array.
   *
   * @return static
   */
  public static function create(array $data) {
    if ($data instanceof static) {
      return $data;
    }
    return new static($data);
  }

  /**
   * Convert renderable object to a string.
   *
   * This function needs to return a non-empty string in order to be processed
   * correctly by Drupal's rendering system.
   *
   * @return string
   *   A placeholder string representation.
   */
  public function __toString() {

    // This must not be empty.
    return '[...]';
  }

  /**
   * Extract the render array.
   *
   * @return mixed
   *   The render array.
   */
  public function getData() {
    return $this->data;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RenderableData::$data protected property The render array.
RenderableData::create public static function Create a renderable data object.
RenderableData::getData public function Extract the render array.
RenderableData::__construct public function RenderableData constructor.
RenderableData::__toString public function Convert renderable object to a string.