Jarves\ContentTypes\TypePlugin::render PHP Method

render() public method

public render ( )
    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);
            }
        }
    }