/** * @param Message $message * @return Message */ public function render(Message $message) { $viewModel = new ViewModel($this->variables); $viewModel->setTemplate($this->template); $helperPluginManager = $this->renderer->getHelperPluginManager(); /** @var HeadTitle $helper */ $helper = $helperPluginManager->get('HeadTitle'); // replace headTitle $headTitle = new HeadTitle(); $headTitle->setAutoEscape(false); $helperPluginManager->setAllowOverride(true); $helperPluginManager->setService('HeadTitle', $headTitle); if (!$message->getBody()) { $message->setBody(new MimeMessage()); } $text = new Part($this->renderer->render($viewModel)); $text->charset = 'UTF-8'; $text->boundary = $message->getBody()->getMime()->boundary(); $text->encoding = Mime::ENCODING_BASE64; $text->type = Mime::TYPE_HTML; $message->getBody()->addPart($text); $message->setSubject($headTitle->renderTitle()); // hack for ZF $message->setBody($message->getBody()); // restore original helper $helperPluginManager->setService('HeadTitle', $helper); return $message; }
/** * Render extra data for this log-event * * @return string */ public function render(RendererInterface $renderer) { if (empty($this->paragraphId)) { return ''; } return $renderer->htmlTag('a', $this->getDescription(), array('title' => $this->originalTitle, 'href' => '/app/' . $this->locale . '/paragraph/render/' . $this->paragraphId)); }
/** * @param array $data * @return string */ public function getBody(array $data = []) { $viewContent = new ViewModel($data); $viewContent->setTemplate($this->template); $content = $this->renderer->render($viewContent); $this->layout->setVariable('content', $content); return $this->renderer->render($this->layout); }
public function testCanGetDoctypeFromDoctypeHelper() { if (!extension_loaded('intl')) { $this->markTestSkipped('ext/intl not enabled'); } $this->renderer->doctype(Doctype::XHTML1_STRICT); $this->assertEquals(Doctype::XHTML1_STRICT, $this->helper->getDoctype()); }
public function it_should_render_chartjs_charts(Renderer $view, ChartInterface $chart) { $view->render(Argument::that(function ($viewModel) use($chart) { return $viewModel instanceof ViewModel && $viewModel->getTemplate() === 'zf-charts/chartjs' && $viewModel->getVariable('chart') === $chart->getWrappedObject() && $viewModel->getVariable('width') === 100 && $viewModel->getVariable('height') === 100 && $viewModel->getVariable('showLegend') === false; }))->willReturn('chart-html'); $this->markAsInitialized(true); $this->render($chart, ['width' => 100, 'height' => 100, 'show_legend' => false])->shouldBe('chart-html'); }
/** * @param RenderableMailInterface $mail * * @return string */ protected function renderContent(RenderableMailInterface $mail) { $viewModel = new ViewModel(); $viewModel->setTemplate($mail->getViewFile()); $viewModel->setTerminal(true); $viewModel->setVariables($mail->getParams()); return $this->viewRenderer->render($viewModel); }
/** * Set the view object * * Ensures that the view object has the dojo view helper path set. * * @param View $view * @return \Zend\Dojo\Form\Element\Dijit */ public function setView(View $view = null) { if (null !== $view) { if (false === $view->getBroker()->isLoaded('dojo')) { $loader = new \Zend\Dojo\View\HelperLoader(); $view->getBroker()->getClassLoader()->registerPlugins($loader); } } return parent::setView($view); }
/** * includeHead * * @param RendererInterface|PhpRenderer $view * @param string $type * @param string $path * * @return void */ public function includeHead(RendererInterface $view, $type, $path) { switch ($type) { case 'css': $view->headLink()->appendStylesheet($path); break; case 'js': $view->headScript()->appendFile($path); break; } }
/** * Get the URL for bulk export. * * @param \Zend\View\Renderer\RendererInterface $view View object (needed for * URL generation) * @param string $format Export format being used * @param array $ids Array of IDs to export * (in source|id format) * * @return string */ public static function getBulkUrl($view, $format, $ids) { $params = array(); $params[] = 'f=' . urlencode($format); foreach ($ids as $id) { $params[] = urlencode('i[]') . '=' . urlencode($id); } $serverUrlHelper = $view->plugin('serverurl'); $urlHelper = $view->plugin('url'); $url = $serverUrlHelper($urlHelper('cart-doexport')) . '?' . implode('&', $params); return self::needsRedirect($format) ? self::getRedirectUrl($format, $url) : $url; }
/** * Retrieve view object * * @return \Zend\View\View */ public function getView() { if (null === $this->_view) { $options = $this->getOptions(); $this->_view = new \Zend\View\PhpRenderer($options); if(isset($options['doctype'])) { $this->_view->plugin('doctype')->setDoctype(strtoupper($options['doctype'])); } } return $this->_view; }
/** * @param RendererInterface $view * @param Config $config * @param Closure $valid * @param string $action */ public function addaptUrlsForMinify(RendererInterface $view, Config $config, Closure $valid, $action = self::CODE_CSS) { foreach ($this as $index => $item) { if (!$valid($item)) { continue; } $url = $view->url('core_assets', array('action' => $action, 'set' => $this->getCacheKey(), 'key' => $index, 'min' => 1)); if ($action === 'css') { $item->href = $url; } else { $item->attributes['src'] = $url; } } }
public function testCanRenderAnotherResourceWithoutVersion() { $currentViewModel = new ResourceViewModel([], ['version' => 'default']); $viewModelHelper = $this->getMock(ViewModelHelper::class); $viewModelHelper->expects($this->once())->method('getCurrent')->will($this->returnValue($currentViewModel)); $this->view->expects($this->once())->method('viewModel')->will($this->returnValue($viewModelHelper)); $this->view->expects($this->once())->method('render')->with($this->callback(function (ResourceViewModel $resourceViewModel) { $this->assertEquals('default/foo.php', $resourceViewModel->getTemplate()); $this->assertEquals('default', $resourceViewModel->getVersion()); $this->assertEquals(['key' => 'value'], $resourceViewModel->getVariables()); return true; })); $helper = $this->helper; $helper('foo', ['key' => 'value']); }
public function onSendEmail(Event $e) { /** @var QueueInterface $queue */ $queue = $this->queues->get('user'); $emailJob = $queue->getJobPluginManager()->get(SendEmailJob::class); $email = $e->getParams(); $html = $this->renderer->render($email->getHtmlTemplate(), $email->getVars()); $text = $this->renderer->render($email->getTextTemplate(), $email->getVars()); $message = new MessageStruct(); $message->html = $html; $message->text = $text; $message->to = $email->getTo(); $emailJob->setContent($message); $queue->push($emailJob); }
/** * Manipulate the body based on configuration options. * * @param mixed $body * @param string $mimeType * * @return string */ protected function manipulateBody($body, $mimeType = null) { // Make sure we have a string. if ($body instanceof ViewModel) { $body = $this->viewRenderer->render($body); $detectedMimeType = 'text/html'; } elseif (null === $body) { $detectedMimeType = 'text/plain'; $body = ''; } if (null !== ($layout = $this->getLayout())) { $layout->setVariables(array('content' => $body)); $detectedMimeType = 'text/html'; $body = $this->viewRenderer->render($layout); } if (null === $mimeType && !isset($detectedMimeType)) { $mimeType = preg_match("/<[^<]+>/", $body) ? 'text/html' : 'text/plain'; } elseif (null === $mimeType) { $mimeType = $detectedMimeType; } $mimePart = new MimePart($body); $mimePart->type = $mimeType; $message = new MimeMessage(); if (!isset($this->config['message']['generate_alternative_body'])) { $this->config['message']['generate_alternative_body'] = true; } if ($this->config['message']['generate_alternative_body'] && $mimeType === 'text/html') { $generatedBody = $this->renderTextBody($body); $altPart = new MimePart($generatedBody); $altPart->type = 'text/plain'; $message->addPart($altPart); } $message->addPart($mimePart); return $message; }
/** * @param \Zend\View\Renderer\RendererInterface $viewRenderer */ public function it_should_render_a_html_body($viewRenderer) { $mail = $this->getMailStub(); $parsedTemplate = '<html><body></body></html>'; $parsedBody = '<body></body>'; // Lay-out rendering $viewRenderer->render(Argument::type('Zend\\View\\Model\\ViewModel'))->will(function ($arguments) use($mail, $parsedBody, $parsedTemplate) { $viewModel = $arguments[0]; if ($mail->getLayoutFile() == $viewModel->getTemplate()) { return sprintf('<html>%s</html>', $viewModel->getVariables()['mailBody']); } else { return $parsedBody; } }); // Run method: $html = $this->render($mail); $html->shouldBe($parsedTemplate); }
/** * Render dojo module paths and requires * * @return string */ protected function _renderExtras() { $js = array(); $modulePaths = $this->getModulePaths(); $escape = $this->view->plugin('escape'); if (!empty($modulePaths)) { foreach ($modulePaths as $module => $path) { $js[] = 'dojo.registerModulePath("' . $escape($module) . '", "' . $escape($path) . '");'; } } $modules = $this->getModules(); if (!empty($modules)) { foreach ($modules as $module) { $js[] = 'dojo.require("' . $escape($module) . '");'; } } $onLoadActions = array(); // Get Zend specific onLoad actions; these will always be first to // ensure that dijits are created in the correct order foreach ($this->_getZendLoadActions() as $callback) { $onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');'; } // Get all other onLoad actions foreach ($this->getOnLoadActions() as $callback) { $onLoadActions[] = 'dojo.addOnLoad(' . $callback . ');'; } $javascript = implode("\n ", $this->getJavascript()); $content = ''; if (!empty($js)) { $content .= implode("\n ", $js) . "\n"; } if (!empty($onLoadActions)) { $content .= implode("\n ", $onLoadActions) . "\n"; } if (!empty($javascript)) { $content .= $javascript . "\n"; } if (preg_match('/^\s*$/s', $content)) { return ''; } $html = '<script type="text/javascript">' . PHP_EOL . (($this->_isXhtml) ? '//<![CDATA[' : '//<!--') . PHP_EOL . $content . (($this->_isXhtml) ? '//]]>' : '//-->') . PHP_EOL . PHP_EOL . '</script>'; return $html; }
/** * Notify user via sending mail * * @access public * @param array $mailArray * @throws \Exception Missing some required Mail option(s) */ public function notify($mailArray) { $requiredKeys = array('from', 'to', 'subject', 'templateName', 'templateParameters'); if (count(array_intersect_key(array_flip($requiredKeys), $mailArray)) !== count($requiredKeys)) { throw new \Exception("Missing some required Mail option(s)"); } $mailViewModel = new ViewModel($mailArray['templateParameters']); $mailViewModel->setTemplate("notifications/mail/" . $mailArray['templateName']); $layout = new ViewModel(); $layout->setTemplate("notifications/mail/layout"); $layout->setVariable("emailBody", $this->viewRenderer->render($mailViewModel)); $htmlMarkup = $this->viewRenderer->render($layout); $html = new MimePart($htmlMarkup); $html->type = "text/html"; $body = new MimeMessage(); $body->setParts(array($html)); $mailArray["body"] = $body; $this->sendEmailJob->setContent($mailArray); $this->queue->push($this->sendEmailJob); }
/** * Render a given template with given data assigned. * * @param string $tpl * @param array $data * @return string The rendered content. */ protected function renderMail($tpl, array $data) { $viewModel = new ViewModel($data); if (isset($data['layout'])) { $viewModel->setTemplate('layout/' . $data['layout']); } else { $viewModel->setTemplate('layout/layout'); } $viewModel->setVariables(['template' => $tpl]); return $this->renderer->render($viewModel); }
/** * Callback that does the work of injecting the toolbar into the response * * @param MvcEvent $event * @return void */ public function injectToolbar(MvcEvent $event) { if (!$this->shouldRender()) { return; } $formManager = $this->serviceLocator->get('FormElementManager'); $select = $formManager->get('NetgluePrismic\\Form\\Element\\SelectPrismicRef'); $request = $event->getApplication()->getRequest(); $url = (string) $request->getUri(); $response = $event->getApplication()->getResponse(); $toolbarView = new ViewModel(); $toolbarView->selectRef = $select; $toolbarView->url = $url; $toolbarView->setTemplate('netglue-prismic/toolbar/toolbar'); $toolbar = $this->renderer->render($toolbarView); $toolbarCss = new ViewModel(); $toolbarCss->setTemplate('netglue-prismic/toolbar/styles'); $style = $this->renderer->render($toolbarCss); $injected = preg_replace('/<\\/body>/i', $toolbar . "\n</body>", $response->getBody(), 1); $injected = preg_replace('/<\\/head>/i', $style . "\n</head>", $injected, 1); $response->setContent($injected); }
/** * Render a view script (optionally to a named response segment) * * Sets the noRender flag to true when called. * * @param string $script * @param string $name * @return void */ public function renderScript($script, $name = null) { if (null === $name) { $name = $this->getResponseSegment(); } $this->getResponse()->appendBody( $this->view->render($script), $name ); $this->setNoRender(); }
/** * Dojo-disable a dojo enabled view * * @param Renderer $view * @return void */ public static function disableView(Renderer $view) { if (!$view instanceof PhpRenderer) { return; } $broker = $view->getBroker(); $loader = $broker->getClassLoader(); $plugins = $broker->getPlugins(); foreach ($plugins as $plugin => $void) { $broker->unregister($plugin); $loader->unregisterPlugin($plugin); } }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ public function setUp() { parent::setUp(); if (empty(static::$helperClass) || !class_exists(static::$helperClass)) { throw new PHPUnit_Framework_Exception(sprintf('%s: view-helper class "%s" does not exists', __METHOD__, static::$helperClass)); } $this->viewMock = $this->getMock(static::$rendererClass); if (method_exists($this->viewMock, 'plugin')) { $this->viewMock->expects($this->any())->method('plugin')->will($this->returnCallback(array($this, 'plugin'))); } $this->helper = $this->createHelper(); $this->pluginInstances = array(); }
/** * Renders a img tag with a base64-encoded QR code * @param string $message * @param string|null $extension * @param int|null $size * @param null $padding * @param array $attribs * @return mixed */ public function renderBase64Img($message, $extension = null, $size = null, $padding = null, $attribs = array()) { if (isset($extension)) { if (is_array($extension)) { $attribs = $extension; $extension = null; } elseif (isset($size)) { if (is_array($size)) { $attribs = $size; $size = null; } elseif (isset($padding) && is_array($padding)) { $attribs = $padding; $padding = null; } } } $image = $this->qrCodeService->getQrCodeContent($message, $extension, $size, $padding); $contentType = $this->qrCodeService->generateContentType(isset($extension) ? $extension : QrCodeServiceInterface::DEFAULT_EXTENSION); return $this->renderer->render(self::IMG_BASE64_TEMPLATE, array('base64' => base64_encode($image), 'contentType' => $contentType, 'attribs' => $attribs)); }
/** * Renders template childrens. * Inspired on Zend\View\View implementation to recursively render child models * @param ViewModel $model * @see Zend\View\View::renderChildren */ protected function renderChildren(ViewModel $model) { if (!$model->hasChildren()) { return; } /* @var ViewModel $child */ foreach ($model as $child) { $capture = $child->captureTo(); if (!empty($capture)) { // Recursively render children $this->renderChildren($child); $result = $this->renderer->render($child); if ($child->isAppend()) { $oldResult = $model->{$capture}; $model->setVariable($capture, $oldResult . $result); } else { $model->setVariable($capture, $result); } } } }
public static function addCss(\Zend\View\Renderer\RendererInterface $renderer, $href, $media = 'screen', $conditionalStylesheet = '', $extras = array()) { self::$renderer = $renderer; self::$renderer->headLink()->appendStylesheet(self::$renderer->basePath($href), $media, $conditionalStylesheet, $extras); }
/** * Render the widget */ public function render(RendererInterface $renderer) { return $renderer->render($this->getTemplate(), $this->getVariables()); }
/** * Clone the current View * * @param RendererInterface $view View * @param array $values Variables to populate in the view * * @return RendererInterface */ public function assignVars($view, $values) { if (!empty($values)) { if (is_array($values)) { $view->vars()->assign($values); } elseif (is_object($values)) { if (null !== ($objectKey = $this->getObjectKey())) { $view->vars()->offsetSet($objectKey, $values); } elseif (method_exists($values, 'toArray')) { $view->vars()->assign($values->toArray()); } else { $view->vars()->assign(get_object_vars($values)); } } } }
/** * Recurse through a form object, rendering errors * * @param \Zend\Form\Form $form * @param \Zend\View\Renderer\RendererInterface $view * @return string */ protected function _recurseForm(Form\Form $form, View $view) { $content = ''; $custom = $form->getCustomMessages(); if ($this->getShowCustomFormErrors() && count($custom)) { $content .= $this->getMarkupListItemStart() . $view->formErrors($custom, $this->getOptions()) . $this->getMarkupListItemEnd(); } foreach ($form->getElementsAndSubFormsOrdered() as $subitem) { if ($subitem instanceof Form\Element && !$this->getOnlyCustomFormErrors()) { $messages = $subitem->getMessages(); if (count($messages)) { $subitem->setView($view); $content .= $this->getMarkupListItemStart() . $this->renderLabel($subitem, $view) . $view->formErrors($messages, $this->getOptions()) . $this->getMarkupListItemEnd(); } } elseif ($subitem instanceof Form\Form && !$this->ignoreSubForms()) { $content .= $this->getMarkupListStart() . $this->_recurseForm($subitem, $view) . $this->getMarkupListEnd(); } } return $content; }
/** * Render extra data for this log-event * * @return string */ public function render(RendererInterface $renderer) { return $renderer->translate('default.' . ($this->successful ? 'success' : 'failed'), 'default') . (empty($this->loginWith) ? '' : ', ' . sprintf($renderer->translate('user.action.loginWith.%s', 'user'), $renderer->translate('user.loginWith.' . $this->loginWith, 'user'))); }
/** * Send a text message representing a record. * * @param string $provider Target SMS provider * @param string $to Recipient phone number * @param \VuFind\RecordDriver\AbstractBase $record Record being emailed * @param \Zend\View\Renderer\RendererInterface $view View object (used to * render email templates) * * @throws MailException * @return void */ public function textRecord($provider, $to, $record, $view) { $body = $view->partial('Email/record-sms.phtml', array('driver' => $record, 'to' => $to)); return $this->text($provider, $to, null, $body); }