public function PreviewController::preview in Entity Embed 8
Returns a HTML response containing a preview of the text after filtering.
Applies all of the given text format's filters, not just the `entity_embed` filter, because for example `filter_align` and `filter_caption` may apply to it as well.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
\Drupal\filter\FilterFormatInterface $filter_format: The text format.
Return value
\Symfony\Component\HttpFoundation\Response The filtered text.
Throws
\Symfony\Component\HttpKernel\Exception\NotFoundHttpException Throws an exception if 'text' parameter is not found in the request.
See also
\Drupal\editor\EditorController::getUntransformedText
1 string reference to 'PreviewController::preview'
File
- src/
Controller/ PreviewController.php, line 64
Class
- PreviewController
- Controller which renders a preview of the provided text.
Namespace
Drupal\entity_embed\ControllerCode
public function preview(Request $request, FilterFormatInterface $filter_format) {
$text = $request
->get('text');
if ($text == '') {
throw new NotFoundHttpException();
}
$build = [
'#type' => 'processed_text',
'#text' => $text,
'#format' => $filter_format
->id(),
];
$html = $this->renderer
->renderPlain($build);
// Note that we intentionally do not use:
// - \Drupal\Core\Cache\CacheableResponse because caching it on the server
// side is wasteful, hence there is no need for cacheability metadata.
// - \Drupal\Core\Render\HtmlResponse because there is no need for
// attachments nor cacheability metadata.
return (new Response($html))
->setPrivate()
->setMaxAge(300);
}