|
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 * A view helper for creating Links to extbase actions within widets. 00025 * 00026 * = Examples = 00027 * 00028 * <code title="URI to the show-action of the current controller"> 00029 * <f:widget.link action="show">link</f:widget.link> 00030 * </code> 00031 * <output> 00032 * <a href="index.php?id=123&tx_myextension_plugin[widgetIdentifier][action]=show&tx_myextension_plugin[widgetIdentifier][controller]=Standard&cHash=xyz">link</a> 00033 * (depending on the current page, widget and your TS configuration) 00034 * </output> 00035 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later 00036 * @api 00037 */ 00038 class Tx_Fluid_ViewHelpers_Widget_LinkViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper { 00039 00040 /** 00041 * @var string 00042 */ 00043 protected $tagName = 'a'; 00044 00045 /** 00046 * Initialize arguments 00047 * 00048 * @return void 00049 * @author Sebastian Kurfürst <sebastian@typo3.org> 00050 * @api 00051 */ 00052 public function initializeArguments() { 00053 $this->registerUniversalTagAttributes(); 00054 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor'); 00055 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document'); 00056 $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document'); 00057 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); 00058 } 00059 00060 /** 00061 * Render the link. 00062 * 00063 * @param string $action Target action 00064 * @param array $arguments Arguments 00065 * @param string $section The anchor to be added to the URI 00066 * @param string $format The requested format, e.g. ".html" 00067 * @param boolean $ajax TRUE if the URI should be to an AJAX widget, FALSE otherwise. 00068 * @return string The rendered link 00069 * @author Sebastian Kurfürst <sebastian@typo3.org> 00070 * @author Bastian Waidelich <bastian@typo3.org> 00071 * @api 00072 */ 00073 public function render($action = NULL, $arguments = array(), $section = '', $format = '', $ajax = FALSE) { 00074 if ($ajax === TRUE) { 00075 $uri = $this->getAjaxUri(); 00076 } else { 00077 $uri = $this->getWidgetUri(); 00078 } 00079 $this->tag->addAttribute('href', $uri); 00080 $this->tag->setContent($this->renderChildren()); 00081 00082 return $this->tag->render(); 00083 } 00084 00085 /** 00086 * Get the URI for an AJAX Request. 00087 * 00088 * @return string the AJAX URI 00089 * @author Sebastian Kurfürst <sebastian@typo3.org> 00090 */ 00091 protected function getAjaxUri() { 00092 $action = $this->arguments['action']; 00093 $arguments = $this->arguments['arguments']; 00094 00095 if ($action === NULL) { 00096 $action = $this->controllerContext->getRequest()->getControllerActionName(); 00097 } 00098 $arguments['id'] = $GLOBALS['TSFE']->id; 00099 // TODO page type should be configurable 00100 $arguments['type'] = 7076; 00101 $arguments['fluid-widget-id'] = $this->controllerContext->getRequest()->getWidgetContext()->getAjaxWidgetIdentifier(); 00102 $arguments['action'] = $action; 00103 00104 return '?' . http_build_query($arguments, NULL, '&'); 00105 } 00106 00107 /** 00108 * Get the URI for a non-AJAX Request. 00109 * 00110 * @return string the Widget URI 00111 * @author Sebastian Kurfürst <sebastian@typo3.org> 00112 */ 00113 protected function getWidgetUri() { 00114 $uriBuilder = $this->controllerContext->getUriBuilder(); 00115 00116 $argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix(); 00117 $arguments = $this->arguments->hasArgument('arguments') ? $this->arguments['arguments'] : array(); 00118 if ($this->arguments->hasArgument('action')) { 00119 $arguments['action'] = $this->arguments['action']; 00120 } 00121 if ($this->arguments->hasArgument('format') && $this->arguments['format'] !== '') { 00122 $arguments['format'] = $this->arguments['format']; 00123 } 00124 return $uriBuilder 00125 ->reset() 00126 ->setArguments(array($argumentPrefix => $arguments)) 00127 ->setSection($this->arguments['section']) 00128 ->setAddQueryString(TRUE) 00129 ->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash')) 00130 ->setFormat($this->arguments['format']) 00131 ->build(); 00132 } 00133 } 00134 00135 ?>
1.8.0