42165470a670e5bf474c22d537b1674a73b96c55
[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 * @return string the rendered CSH icon
51 */
52 public function render($table = null, $field = '')
53 {
54 return static::renderStatic(
55 array(
56 'table' => $table,
57 'field' => $field,
58 ),
59 $this->buildRenderChildrenClosure(),
60 $this->renderingContext
61 );
62 }
63
64 /**
65 * @param array $arguments
66 * @param callable $renderChildrenClosure
67 * @param RenderingContextInterface $renderingContext
68 * @return string
69 */
70 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
71 {
72 $table = $arguments['table'];
73 $field = $arguments['field'];
74
75 if ($table === null) {
76 $currentRequest = $renderingContext->getControllerContext()->getRequest();
77 $moduleName = $currentRequest->getPluginName();
78 $table = '_MOD_' . $moduleName;
79 }
80 return '<div class="docheader-csh">' . BackendUtility::cshItem($table, $field) . '</div>';
81 }
82 }