[TASK] Add argument wrap to CSH ViewHelper
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Be / Buttons / CshViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Be\Buttons;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
19 use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
20
21 /**
22 * View helper which returns CSH (context sensitive help) button with icon
23 * Note: The CSH button will only work, if the current BE user has the "Context Sensitive Help mode"
24 * set to something else than "Display no help information" in the Users settings
25 * Note: This view helper is experimental!
26 *
27 * = Examples =
28 *
29 * <code title="Default">
30 * <f:be.buttons.csh />
31 * </code>
32 * <output>
33 * CSH button as known from the TYPO3 backend.
34 * </output>
35 *
36 * <code title="Full configuration">
37 * <f:be.buttons.csh table="xMOD_csh_corebe" field="someCshKey" />
38 * </code>
39 * <output>
40 * CSH button as known from the TYPO3 backend with some custom settings.
41 * </output>
42 */
43 class CshViewHelper extends AbstractBackendViewHelper
44 {
45 /**
46 * Render context sensitive help (CSH) for the given table
47 *
48 * @param string $table Table name ('_MOD_'+module name). If not set, the current module name will be used
49 * @param string $field Field name (CSH locallang main key)
50 * @param string $wrap Markup to wrap around the CSH, split by "|"
51 * @return string the rendered CSH icon
52 */
53 public function render($table = null, $field = '', $wrap = '')
54 {
55 return static::renderStatic(
56 array(
57 'table' => $table,
58 'field' => $field,
59 'wrap' => $wrap
60 ),
61 $this->buildRenderChildrenClosure(),
62 $this->renderingContext
63 );
64 }
65
66 /**
67 * @param array $arguments
68 * @param callable $renderChildrenClosure
69 * @param RenderingContextInterface $renderingContext
70 * @return string
71 */
72 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
73 {
74 $table = $arguments['table'];
75 $field = $arguments['field'];
76 $wrap = $arguments['wrap'];
77
78 if ($table === null) {
79 $currentRequest = $renderingContext->getControllerContext()->getRequest();
80 $moduleName = $currentRequest->getPluginName();
81 $table = '_MOD_' . $moduleName;
82 }
83 return '<div class="docheader-csh">' . BackendUtility::cshItem($table, $field, '', $wrap) . '</div>';
84 }
85 }