You are here

public function MediaForm::renderPreview in Varbase Media 8.7

Same name and namespace in other branches
  1. 8.5 modules/entity_browser_generic_embed/src/Form/MediaForm.php \Drupal\entity_browser_generic_embed\Form\MediaForm::renderPreview()
  2. 8.6 modules/entity_browser_generic_embed/src/Form/MediaForm.php \Drupal\entity_browser_generic_embed\Form\MediaForm::renderPreview()
  3. 9.0.x modules/entity_browser_generic_embed/src/Form/MediaForm.php \Drupal\entity_browser_generic_embed\Form\MediaForm::renderPreview()

Pre-render callback for the preview element.

You might wonder why this rinky-dink bit of logic cannot be done in ::form(). The reason is that, under some circumstances, the renderable preview element will contain unserializable dependencies (like such as the database connection), which will produce a 500 error when trying to cache the form for AJAX purposes.

By putting this logic in a pre-render callback, we ensure that the unserializable preview element will only exist during the rendering stage, and thus never be serialized for caching.

Parameters

array $element: The preview element.

Return value

array The renderable preview element.

File

modules/entity_browser_generic_embed/src/Form/MediaForm.php, line 78

Class

MediaForm
Adds dynamic preview support to the media entity form.

Namespace

Drupal\entity_browser_generic_embed\Form

Code

public function renderPreview(array $element) {
  $entity = $this
    ->getEntity();
  return $element + MediaHelper::getSourceField($entity)
    ->view('default');
}