/** * Alertify filter * @param TwigEnvironment $environment * @param Session $session * * @return string */ public function alertifyFilter($environment, Session $session) { $flashes = $session->getFlashBag()->all(); $renders = array(); foreach ($flashes as $type => $flash) { if ($type == "callback") { foreach ($flash as $key => $currentFlash) { $currentFlash['body'] .= $environment->render('AvAlertifyBundle:Modal:callback.html.twig', $currentFlash); $session->getFlashBag()->add($currentFlash['engine'], $currentFlash); $renders[$type . $key] = $this->alertifyFilter($session); } } else { foreach ($flash as $key => $content) { if (is_array($content)) { $context = isset($content['context']) ? $content['context'] : null; $defaultParameters = self::getDefaultParametersFromContext($context); $parameters = array_merge($defaultParameters, $content); } else { $defaultParameters = self::getDefaultParametersFromContext(null); $parameters = array_merge($defaultParameters, array('body' => $content)); } $parameters['type'] = $type; $renders[$type . $key] = $environment->render('AvAlertifyBundle:Modal:' . $parameters['engine'] . '.html.twig', $parameters); } } } return implode(' ', $renders); }
public function setUp() { $timezone = new DateTimeZone(date_default_timezone_get()); $coreExtension = $this->getMock('Twig_Extension_Core'); $coreExtension->expects($this->any())->method('getTimezone')->will($this->returnValue($timezone)); $this->env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); $this->env->expects($this->any())->method('getExtension')->with('core')->will($this->returnValue($coreExtension)); }
/** * Returns a list of global variables to add to the existing list. * * @return array An array of global variables */ public function getGlobals() { $safeMode = $this->environment->isSafeMode(); $isInstalled = craft()->isInstalled(); $globals = array('user' => null, 'currentUser' => null); if (!$safeMode) { // Keep the 'blx' variable around for now $craftVariable = new CraftVariable(); $globals['craft'] = $craftVariable; $globals['blx'] = $craftVariable; $globals['loginUrl'] = UrlHelper::getUrl(craft()->config->getLoginPath()); $globals['logoutUrl'] = UrlHelper::getUrl(craft()->config->getLogoutPath()); $globals['isInstalled'] = $isInstalled; if ($isInstalled) { $globals['currentUser'] = craft()->userSession->getUser(); } // Keep 'user' around so long as it's not hurting anyone. // Technically deprecated, though. $globals['user'] = $globals['currentUser']; if (craft()->request->isCpRequest()) { $globals['CraftEdition'] = craft()->getEdition(); $globals['CraftPersonal'] = Craft::Personal; $globals['CraftClient'] = Craft::Client; $globals['CraftPro'] = Craft::Pro; } } $globals['now'] = new DateTime(null, new \DateTimeZone(craft()->getTimeZone())); if ($isInstalled && !craft()->updates->isCraftDbMigrationNeeded()) { $globals['siteName'] = craft()->getSiteName(); $globals['siteUrl'] = craft()->getSiteUrl(); if (craft()->request->isSiteRequest()) { foreach (craft()->globals->getAllSets() as $globalSet) { $globals[$globalSet->handle] = $globalSet; } } } else { $globals['siteName'] = null; $globals['siteUrl'] = null; } return $globals; }
public function setUp() { $this->env = $this->getMock('Twig_Environment'); $this->env->expects($this->any())->method('getCharset')->will($this->returnValue('utf-8')); }
/** * Returns the Twig Environment instance for a given template loader class. * * @param string $loaderClass The name of the class that should be initialized as the Twig instance’s template * loader. If no class is passed in, {@link TemplateLoader} will be used. * * @return TwigEnvironment The Twig Environment instance. */ public function getTwig($loaderClass = null, $options = array()) { if (!$loaderClass) { $loaderClass = __NAMESPACE__ . '\\TemplateLoader'; } $options = array_merge(array('safe_mode' => false), $options); $cacheKey = $loaderClass . ':' . md5(serialize($options)); if (!isset($this->_twigs[$cacheKey])) { $loader = new $loaderClass(); $options = array_merge($this->_getTwigOptions(), $options); $twig = new TwigEnvironment($loader, $options); $twig->addExtension(new \Twig_Extension_StringLoader()); $twig->addExtension(new CraftTwigExtension($twig)); if (craft()->config->get('devMode')) { $twig->addExtension(new \Twig_Extension_Debug()); } // Set our timezone $timezone = craft()->getTimeZone(); $twig->getExtension('core')->setTimezone($timezone); // Set our custom parser to support "include" tags using the capture mode $twig->setParser(new TwigParser($twig)); $this->_twigs[$cacheKey] = $twig; // Give plugins a chance to add their own Twig extensions $this->_addPluginTwigExtensions($twig); } return $this->_twigs[$cacheKey]; }
public function setUp() { $this->env = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); $this->env->expects($this->any())->method('getCharset')->will($this->returnValue('utf-8')); }