You are here

public function MediaEntityRenderer::renderArray in Gutenberg 8.2

Return the media entity render array.

Parameters

\Drupal\media\Entity\Media|string $media_entity: Media entity ID or loaded media entity instance.

string $view_mode: (optional) View mode of media entity, 'full' is default.

Return value

array Render array of the media entity.

Overrides MediaEntityRendererInterface::renderArray

1 call to MediaEntityRenderer::renderArray()
MediaEntityRenderer::render in src/MediaEntityRenderer.php
Render media entities.

File

src/MediaEntityRenderer.php, line 56

Class

MediaEntityRenderer
Renders media entities to the HTML.

Namespace

Drupal\gutenberg

Code

public function renderArray($media_entity, string $view_mode = 'full') {
  try {
    if (is_numeric($media_entity)) {
      $media_entity = $this->entityTypeManager
        ->getStorage('media')
        ->load($media_entity);
    }
    $this
      ->assertIsMediaEntity($media_entity);
    return $this->entityTypeManager
      ->getViewBuilder('media')
      ->view($media_entity, $view_mode);
  } catch (\Throwable $exception) {
    return [];
  }
}