3 namespace Drupal\embed\Controller;
5 use Drupal\Core\Ajax\AjaxResponse;
6 use Drupal\Core\Controller\ControllerBase;
7 use Drupal\editor\EditorInterface;
8 use Drupal\embed\Ajax\EmbedInsertCommand;
9 use Drupal\embed\EmbedButtonInterface;
10 use Drupal\filter\FilterFormatInterface;
11 use Symfony\Component\HttpFoundation\Request;
12 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15 * Returns responses for Embed module routes.
17 class EmbedController extends ControllerBase {
20 * Returns an Ajax response to generate preview of embedded items.
22 * Expects the the HTML element as GET parameter.
24 * @param \Symfony\Component\HttpFoundation\Request $request
26 * @param \Drupal\filter\FilterFormatInterface $filter_format
29 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
30 * Throws an exception if 'value' parameter is not found in the request.
32 * @return \Symfony\Component\HttpFoundation\Response
33 * The preview of the embedded item specified by the data attributes.
35 public function preview(Request $request, FilterFormatInterface $filter_format) {
36 $text = $request->get('value');
38 throw new NotFoundHttpException();
42 '#type' => 'processed_text',
44 '#format' => $filter_format->id(),
47 $response = new AjaxResponse();
48 $response->addCommand(new EmbedInsertCommand($build));
53 * Returns an Ajax response to generate preview of an entity.
55 * Expects the the HTML element as GET parameter.
57 * @param \Symfony\Component\HttpFoundation\Request $request
59 * @param \Drupal\editor\EditorInterface $editor
61 * @param \Drupal\embed\EmbedButtonInterface $embed_button
64 * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
65 * Throws an exception if 'value' parameter is not found in the request.
67 * @return \Symfony\Component\HttpFoundation\Response
68 * The preview of the embedded item specified by the data attributes.
70 public function previewEditor(Request $request, EditorInterface $editor, EmbedButtonInterface $embed_button) {
71 return $this->preview($request, $editor->getFilterFormat());