public function render() { if ($response = $this->pageStack->getPageResponse()->getPluginResponse($this->getContent())) { return $response->getContent(); } elseif ($this->plugin) { $config = $this->jarves->getConfig($this->bundleName); if (!$config) { return sprintf('Bundle `%s` does not exist. You probably have to install this bundle.', $this->bundleName); } if ($this->pluginDef = $config->getPlugin($this->plugin['plugin'])) { $controller = $this->pluginDef->getController(); if ($this->isPreview()) { if (!$this->pluginDef->isPreview()) { //plugin does not allow to have a preview on the actual action method return ($config->getLabel() ?: $config->getBundleName()) . ': ' . $this->pluginDef->getLabel(); } } //create a sub request $request = new Request(); $request->attributes->add(array('_controller' => $controller, '_content' => $this->getContent(), '_jarves_is_plugin' => true, 'options' => isset($this->plugin['options']) ? $this->plugin['options'] : array())); $dispatcher = $this->eventDispatcher; $callable = array($this, 'exceptionHandler'); $fixResponse = array($this, 'fixResponse'); $dispatcher->addListener(KernelEvents::EXCEPTION, $callable, 100); $dispatcher->addListener(KernelEvents::VIEW, $fixResponse, 100); ob_start(); $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST); //EventListener\PluginRequestListener converts all PluginResponse objects to PageResponses if ($response instanceof PageResponse) { if ($pluginResponse = $response->getPluginResponse($this->getContent()->getId())) { $response = $pluginResponse; } } // if ($response instanceof PageResponse) { // if ($response->getPluginResponse($this->getContent()->getId())) { // $response = $response->getPluginResponse($this->getContent()->getId()); // } // } $ob = ob_get_clean(); $dispatcher->removeListener(KernelEvents::EXCEPTION, $callable); $dispatcher->removeListener(KernelEvents::VIEW, $fixResponse); return trim($ob) . $response->getContent(); } else { return sprintf('Plugin `%s` in bundle `%s` does not exist. You probably have to install the bundle first.', $this->plugin['plugin'], $this->bundleName); } } }
public function valueTest(Plugin $plugin) { $this->assertEquals('listing', $plugin->getId()); $this->assertEquals('News Listing', $plugin->getLabel()); $this->assertEquals('Publication\\Controller\\Plugin\\News:listing', $plugin->getController()); $this->assertInstanceOf('\\Jarves\\Configuration\\Route', $plugin->getRoutes()[0]); $this->assertInstanceOf('\\Jarves\\Configuration\\Route', $plugin->getRoutes()[1]); $this->assertEquals('1', $plugin->getRoutes()[0]->getDefaultValue('page')); $this->assertEquals('Items per page', $plugin->getOption('itemsPerPage')->getLabel()); $this->assertEquals('@PublicationBundle/news/list/', $plugin->getOption('template')->getOption('directory')); $array = $plugin->toArray(); $this->assertEquals('listing', $array['id']); $this->assertEquals('News Listing', $array['label']); $this->assertEquals('Publication\\Controller\\Plugin\\News:listing', $array['controller']); $this->assertCount(2, $array['routes']); $this->assertCount(3, $array['options']); $this->assertEquals(['pattern' => '{page}', 'defaults' => ['page' => 1], 'requirements' => ['page' => '\\d']], $array['routes'][0]); $this->assertEquals('Items per page', $array['options']['itemsPerPage']['label']); $this->assertEquals($this->xml, $plugin->toXml()); }