/** * @param FilterResponseEvent $event */ public function onKernelResponse(FilterResponseEvent $event) { if (!$event->isMasterRequest()) { return; } try { if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) { return; } } catch (AuthenticationCredentialsNotFoundException $e) { return; } $request = $event->getRequest(); if ($request->isXmlHttpRequest()) { return; } $response = $event->getResponse(); if ($response->isRedirection() || false === strpos($response->headers->get('Content-Type', ''), 'text/html')) { return; } $html = $this->editor->renderEditor($response); if (!empty($html)) { $this->injectEditor($response, $html); } }
/** * @dataProvider getRenderContentEditableTestData * * @param string $expectedText * @param string $text * @param string $name * @param array $options * @param bool $isAuthorized * @param string $message */ public function testRenderContentEditable($expectedText, $text, $name, $options, $isAuthorized, $message) { $content = new Content(); $content->setId(1)->setName($name)->setText($text)->setLocale($options['locale']); $this->manager->method('get')->with($name, $options['locale'], $text)->willReturn($content); $this->authorizationChecker->method('isGranted')->with('ROLE_ADMIN')->willReturn($isAuthorized); $this->editor->method('renderContent')->with($content, $options)->willReturn(sprintf('editable_%s', $text)); $rendered = $this->extension->render($text, $name, $options); $this->assertSame($expectedText, $rendered, $message); }
/** * {@inheritdoc} */ public function render($default, $name = null, array $options = []) { if (null === $name) { $name = $default; } $locale = isset($options['locale']) ? $options['locale'] : null; $content = $this->manager->get($name, $locale, $default); if (!$this->authorizationChecker->isGranted('ROLE_ADMIN')) { return $content->getText(); } return $this->editor->renderContent($content, $options); }