/** * Dojo-enable a view instance * * @param \Zend\View\Renderer $view * @return void */ public static function enableView(Renderer $view) { if (!$view instanceof PhpRenderer) { return; } $view->broker()->getClassLoader()->registerPlugins(new View\HelperLoader()); }
/** * Set the view object * * Ensures that the view object has the dojo view helper path set. * * @param \Zend\View\Renderer $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); }
/** * 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->broker('doctype')->setDoctype(strtoupper($options['doctype'])); } } return $this->_view; }
/** * 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(); }
/** * Render dojo module paths and requires * * @return string */ protected function _renderExtras() { $js = array(); $modulePaths = $this->getModulePaths(); if (!empty($modulePaths)) { foreach ($modulePaths as $module => $path) { $js[] = 'dojo.registerModulePath("' . $this->view->vars()->escape($module) . '", "' . $this->view->vars()->escape($path) . '");'; } } $modules = $this->getModules(); if (!empty($modules)) { foreach ($modules as $module) { $js[] = 'dojo.require("' . $this->view->vars()->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; }
/** * Recurse through a form object, rendering errors * * @param \Zend\Form\Form $form * @param \Zend\View\Renderer $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; }
/** * Display the captcha * * @param Renderer $view * @param mixed $element * @return string */ public function render(Renderer $view = null, $element = null) { $endTag = ' />'; if ($view instanceof Pluggable) { $doctype = $view->plugin('doctype'); if ($doctype && !$doctype->isXhtml()) { $endTag = '>'; } } return '<img width="' . $this->getWidth() . '" height="' . $this->getHeight() . '" alt="' . $this->getImgAlt() . '" src="' . $this->getImgUrl() . $this->getId() . $this->getSuffix() . '"' . $endTag; }
/** * Initialize View object * * Initializes {@link $view} if not otherwise a Zend_View_Interface. * * If {@link $view} is not otherwise set, instantiates a new Zend_View * object, using the 'views' subdirectory at the same level as the * controller directory for the current module as the base directory. * It uses this to set the following: * - script path = views/scripts/ * - helper path = views/helpers/ * - filter path = views/filters/ * * @return \Zend\View\Renderer * @throws \Zend\Controller\Exception if base view directory does not exist */ public function initView() { $broker = $this->broker(); if (!$this->getInvokeArg('noViewRenderer') && $broker && $broker->hasPlugin('viewRenderer')) { return $this->view; } if (isset($this->view) && $this->view instanceof View\Renderer) { return $this->view; } $request = $this->getRequest(); $module = $request->getModuleName(); $dirs = $this->getFrontController()->getControllerDirectory(); if (empty($module) || !isset($dirs[$module])) { $module = $this->getFrontController()->getDispatcher()->getDefaultModule(); } $baseDir = dirname($dirs[$module]) . DIRECTORY_SEPARATOR . 'views'; if (!file_exists($baseDir) || !is_dir($baseDir)) { throw new Exception('Missing base view directory ("' . $baseDir . '")'); } $this->view = new View\PhpRenderer(); $this->view->resolver()->addPath($baseDir . '/scripts'); return $this->view; }
/** * Dojo-disable a dojo enabled view * * @param \Zend\View\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); } }