public function setRequestLayout(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     // Get the necessary informations to check them in layout configurations
     $path = $request->getPathInfo();
     $host = $request->getHost();
     $layouts = $this->config['layouts'];
     // As a layout must be set, we force it to be empty if no layout is properly configured.
     // Then this will throw an exception, and the user will be warned of the "no-layout" config problem.
     $finalLayout = null;
     foreach ($layouts as $layoutConfig) {
         $match = false;
         if ($layoutConfig['host'] && $host === $layoutConfig['host']) {
             $match = true;
         }
         if ($layoutConfig['pattern'] && preg_match('~' . $layoutConfig['pattern'] . '~', $path)) {
             $match = true;
         }
         if ($match) {
             $finalLayout = $layoutConfig;
             break;
         }
     }
     if (null === $finalLayout || !$this->templating->exists($finalLayout['resource'])) {
         throw new \Twig_Error_Loader(sprintf('Unable to find template %s for layout %s. The "layout" parameter must be a valid twig view to be used as a layout.', $finalLayout['resource'], $finalLayout['name']), 0, $finalLayout['resource']);
     }
     $event->getRequest()->attributes->set('_orbitale_cms_layout', $finalLayout);
 }
Example #2
0
 /**
  * @param string $view
  * @param string $templateName
  * @param array $params
  * @return string
  * @throws ResourceNotFoundException
  */
 protected function getHtml(string $view, string $templateName, array $params) : string
 {
     $template = null;
     if ($this->templating->exists($templateName)) {
         $template = $templateName;
     }
     if ($template === null) {
         $templateDir = $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     $viewPath = $view;
     if ($template === null && $viewPath !== '') {
         $templateDir = $viewPath . $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         $templateDir = static::$TEMPLATE_DIR . $templateName . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         throw new ResourceNotFoundException('View for ' . $templateName . ' does not exist!');
     }
     return $this->templating->render($template, $params);
 }
Example #3
0
 /**
  * @inheritDoc
  */
 public function configureOptions(OptionsResolver $resolver, $property, $templatePath)
 {
     parent::configureOptions($resolver, $property, $templatePath);
     $class = get_class($this);
     $resolver->setDefault('label', $this->templating->render($templatePath . strtolower(str_replace('Type', '', substr($class, strrpos($class, '\\') + 1))) . '.html.twig'));
     $resolver->remove('url');
     $resolver->remove('sort');
 }
 /**
  * Setup
  */
 public function setup()
 {
     $this->mailer = $this->prophesize(Swift_Mailer::class);
     $this->templating = $this->prophesize(TwigEngine::class);
     $requestCollectorConfiguration = ['from_email' => '*****@*****.**'];
     $this->requestObject = new RequestObject();
     $this->collector = new MailerCollector($this->mailer->reveal(), $this->templating->reveal(), $requestCollectorConfiguration);
 }
Example #5
0
 public function sendTemplateMail(SendTemplateMailCommand $command)
 {
     $message = \Swift_Message::newInstance();
     $ext = $command->format === 'text/html' ? 'html' : 'txt';
     $tplIdentifier = 'Email/' . $command->template . '.' . $ext;
     $template = $this->cr->getContent($tplIdentifier);
     $templateData = $command->templateData;
     if ($command->image !== null) {
         $templateData['image'] = $message->embed(\Swift_Image::fromPath($command->image));
     }
     // Subject
     $env = new \Twig_Environment(new \Twig_Loader_String());
     $subject = $template->getProperties()->containsKey('subject') ? $template->getProperties()->get('subject') : $this->mailFromName;
     $subject = $env->render($subject, $templateData);
     // Body
     $body = $this->templating->render('bcrm_content:' . $tplIdentifier, $templateData);
     $message->setCharset('UTF-8');
     $message->setFrom($this->mailFromEmail, $this->mailFromName)->setSubject($subject)->setTo($command->email)->setBody($body, $command->format);
     $this->mailer->send($message);
 }
 /**
  * Set all options for the twig template.
  *
  * @return string
  */
 public function createView()
 {
     $options = array();
     $options['id'] = $this->getTableId();
     $options['sAjaxSource'] = $this->getSAjaxSource();
     $options['tableHeaders'] = $this->getTableHeaders();
     $options['sDomOptions'] = $this->getSDomOptions();
     $options['fields'] = $this->getFieldsOptions();
     $options['actions'] = $this->getActions();
     $options['customizeOptions'] = $this->getCustomizeOptions();
     $options['routeParameters'] = $this->getRouteParameters();
     return $this->twig->render($this->getTemplate(), $options);
 }
 /**
  * {@inheritdoc}
  */
 public function render($name, array $parameters = array())
 {
     try {
         return parent::render($name, $parameters);
     } catch (\Twig_Error $e) {
         if ($name instanceof TemplateReference) {
             try {
                 // try to get the real file name of the template where the error occurred
                 $e->setTemplateFile(sprintf('%s', $this->locator->locate($this->parser->parse($e->getTemplateFile()))));
             } catch (\Exception $e2) {
             }
         }
         throw $e;
     }
 }
Example #8
0
 /**
  * {@inheritdoc}
  */
 public function renderView(string $view, array $params = []) : string
 {
     $template = null;
     if ($this->templating->exists($this->getTemplateName())) {
         $template = $this->getTemplateName();
     }
     $viewPath = $view;
     if ($template === null && $viewPath) {
         $templateDir = $viewPath . $this->getTemplateName() . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         $templateDir = self::TEMPLATE_DIR . $this->getTemplateName() . $this->templateEngine;
         if ($this->templating->exists($templateDir)) {
             $template = $templateDir;
         }
     }
     if ($template === null) {
         throw new ResourceNotFoundException('Vardius\\Bundle\\ListBundle\\View\\Renderer: Wrong template path');
     }
     return $this->templating->render($template, $params);
 }
Example #9
0
 /**
  * {@inheritdoc}
  */
 public function render($name, array $parameters = array())
 {
     try {
         return parent::render($name, $parameters);
     } catch (\Twig_Error $e) {
         if ($name instanceof TemplateReference) {
             try {
                 // try to get the real name of the template where the error occurred
                 $name = $e->getTemplateName();
                 $path = (string) $this->locator->locate($this->parser->parse($name));
                 if (method_exists($e, 'setSourceContext')) {
                     $e->setSourceContext(new \Twig_Source('', $name, $path));
                 } else {
                     $e->setTemplateName($path);
                 }
             } catch (\Exception $e2) {
             }
         }
         throw $e;
     }
 }
Example #10
0
 /**
  * Renders and set as html the template with the given context
  *
  * @param
  *        	$template
  * @param array $data
  */
 public function useTwigTemplate($template, array $data = array())
 {
     $html = $this->renderer->render($template, $data);
     $this->setHtml($html);
     return $this;
 }
Example #11
0
 /**
  * @inheritDoc
  */
 public function render($view = null)
 {
     $menuView = $view ?: $this->view;
     return $this->twigEngine->render($menuView, ['items' => $this->children]);
 }
 /**
  * Renders a mailing part.
  *
  * @param MailerEvent $event
  * @param string      $extension
  *
  * @return string
  */
 private function renderMailPart(MailerEvent $event, $extension)
 {
     return $this->engine->render(sprintf('%s.%s', $event->getTemplateSource(), (string) $extension), $event->getParameters());
 }
Example #13
0
 /**
  * Gets a DiaryView, passes it to the Twig template and returns the rendered HTML as a Symfony Response object
  *
  * @param Diary $diary
  *
  * @return Response
  */
 public function render(Diary $diary)
 {
     $view = $diary->createView();
     return $this->twig->render('ActsDiaryBundle:Diary:index.html.twig', array('diary' => $view));
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function render() : string
 {
     return $this->templating->render($this->getTemplatePath() . 'paginator.html.twig', ['currentPage' => $this->getCurrentPage(), 'previousPage' => $this->getPreviousPage(), 'lastPage' => $this->getLastPage(), 'nextPage' => $this->getNextPage()]);
 }
Example #15
0
 /**
  * Render and return the pool configuration.
  *
  * @return string
  */
 public function getPoolConfiguration()
 {
     $vars = array('poolname' => $this->getPoolName(), 'user' => $this->_user->getName(), 'group' => $this->_user->getGroupname(), 'socket' => $this->getSocketPath());
     $file = $this->_twig->render(self::CFG_POOL_TEMPLATE, $vars);
     return $file;
 }