|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /* 00004 * This script belongs to the FLOW3 package "Fluid". * 00005 * * 00006 * It is free software; you can redistribute it and/or modify it under * 00007 * the terms of the GNU Lesser General Public License as published by the * 00008 * Free Software Foundation, either version 3 of the License, or (at your * 00009 * option) any later version. * 00010 * * 00011 * This script is distributed in the hope that it will be useful, but * 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- * 00013 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser * 00014 * General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with the script. * 00018 * If not, see http://www.gnu.org/licenses/lgpl.html * 00019 * * 00020 * The TYPO3 project - inspiring people to share! * 00021 * */ 00022 00023 /** 00024 * Render the inner parts of a Widget. 00025 * This ViewHelper can only be used in a template which belongs to a Widget Controller. 00026 * 00027 * It renders everything inside the Widget ViewHelper, and you can pass additional 00028 * arguments. 00029 * 00030 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00031 * @api 00032 */ 00033 class Tx_Fluid_ViewHelpers_RenderChildrenViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper { 00034 00035 /** 00036 * @param array $arguments 00037 * @return string 00038 * @author Sebastian Kurfürst <sebastian@typo3.org> 00039 */ 00040 public function render(array $arguments = array()) { 00041 $renderingContext = $this->getWidgetRenderingContext(); 00042 $widgetChildNodes = $this->getWidgetChildNodes(); 00043 00044 $this->addArgumentsToTemplateVariableContainer($arguments); 00045 $output = $widgetChildNodes->evaluate($renderingContext); 00046 $this->removeArgumentsFromTemplateVariableContainer($arguments); 00047 00048 return $output; 00049 } 00050 00051 /** 00052 * Get the widget rendering context, or throw an exception if it cannot be found. 00053 * 00054 * @return Tx_Fluid_Core_Rendering_RenderingContextInterface 00055 * @author Sebastian Kurfürst <sebastian@typo3.org> 00056 */ 00057 protected function getWidgetRenderingContext() { 00058 $renderingContext = $this->getWidgetContext()->getViewHelperChildNodeRenderingContext(); 00059 if (!($renderingContext instanceof Tx_Fluid_Core_Rendering_RenderingContextInterface)) { 00060 throw new Tx_Fluid_Core_Widget_Exception_RenderingContextNotFoundException('Rendering Context not found inside Widget. <f:renderChildren> has been used in an AJAX Request, but is only usable in non-ajax mode.', 1284986604); 00061 } 00062 return $renderingContext; 00063 } 00064 00065 /** 00066 * @return Tx_Fluid_Core_Parser_SyntaxTree_RootNode 00067 * @author Sebastian Kurfürst <sebastian@typo3.org> 00068 */ 00069 protected function getWidgetChildNodes() { 00070 return $this->getWidgetContext()->getViewHelperChildNodes(); 00071 } 00072 00073 /** 00074 * @return Tx_Fluid_Core_Widget_WidgetContext 00075 * @author Sebastian Kurfürst <sebastian@typo3.org> 00076 */ 00077 protected function getWidgetContext() { 00078 $request = $this->controllerContext->getRequest(); 00079 if (!($request instanceof Tx_Fluid_Core_Widget_WidgetRequest)) { 00080 throw new Tx_Fluid_Core_Widget_Exception_WidgetRequestNotFoundException('The Request is not a WidgetRequest! <f:renderChildren> must be called inside a Widget Template.', 1284986120); 00081 } 00082 00083 return $request->getWidgetContext(); 00084 } 00085 00086 /** 00087 * Add the given arguments to the TemplateVariableContainer of the widget. 00088 * 00089 * @param array $arguments 00090 * @return void 00091 * @author Sebastian Kurfürst <sebastian@typo3.org> 00092 */ 00093 protected function addArgumentsToTemplateVariableContainer(array $arguments) { 00094 $templateVariableContainer = $this->getWidgetRenderingContext()->getTemplateVariableContainer(); 00095 foreach ($arguments as $identifier => $value) { 00096 $templateVariableContainer->add($identifier, $value); 00097 } 00098 } 00099 00100 /** 00101 * Remove the given arguments from the TemplateVariableContainer of the widget. 00102 * 00103 * @param array $arguments 00104 * @return void 00105 * @author Sebastian Kurfürst <sebastian@typo3.org> 00106 */ 00107 protected function removeArgumentsFromTemplateVariableContainer(array $arguments) { 00108 $templateVariableContainer = $this->getWidgetRenderingContext()->getTemplateVariableContainer(); 00109 foreach ($arguments as $identifier => $value) { 00110 $templateVariableContainer->remove($identifier); 00111 } 00112 } 00113 } 00114 ?>
1.8.0