[TASK] Make BaseViewHelper Compilable
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / BaseViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
15 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
16 use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
17
18 /**
19 * View helper which creates a <base href="..."></base> tag. The Base URI
20 * is taken from the current request.
21 * In TYPO3 Flow, you should always include this ViewHelper to make the links work.
22 *
23 * = Examples =
24 *
25 * <code title="Example">
26 * <f:base />
27 * </code>
28 * <output>
29 * <base href="http://yourdomain.tld/" />
30 * (depending on your domain)
31 * </output>
32 *
33 * @api
34 */
35 class BaseViewHelper extends AbstractViewHelper implements CompilableInterface {
36
37 /**
38 * Render the "Base" tag by outputting $request->getBaseUri()
39 *
40 * Note: renders as <base></base>, because IE6 will else refuse to display
41 * the page...
42 *
43 * @return string "base"-Tag.
44 * @api
45 */
46 public function render() {
47 return self::renderStatic(
48 array(),
49 $this->buildRenderChildrenClosure(),
50 $this->renderingContext
51 );
52 }
53
54 /**
55 * Render the "Base" tag by outputting $request->getBaseUri()
56 *
57 * Note: renders as <base></base>, because IE6 will else refuse to display
58 * the page...
59 *
60 * @param array $arguments
61 * @param \Closure $renderChildrenClosure
62 * @param RenderingContextInterface $renderingContext
63 *
64 * @return string "base"-Tag.
65 * @api
66 */
67 static public function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) {
68 $controllerContext = $renderingContext->getControllerContext();
69 return '<base href="' . htmlspecialchars($controllerContext->getRequest()->getBaseUri()) . '" />';
70 }
71
72 }