public function MediaForm::renderPreview in Varbase Media 8.6
Same name and namespace in other branches
- 8.7 modules/entity_browser_generic_embed/src/Form/MediaForm.php \Drupal\entity_browser_generic_embed\Form\MediaForm::renderPreview()
- 8.5 modules/entity_browser_generic_embed/src/Form/MediaForm.php \Drupal\entity_browser_generic_embed\Form\MediaForm::renderPreview()
- 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\FormCode
public function renderPreview(array $element) {
$entity = $this
->getEntity();
return $element + Helper::getSourceField($entity)
->view('default');
}