91c56a01615a6fb352ff3916f046993279c17cf0
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / ContextHelpAjaxController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Http\JsonResponse;
21 use TYPO3\CMS\Core\Imaging\Icon;
22 use TYPO3\CMS\Core\Imaging\IconFactory;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * Class ContextHelpAjaxController
27 */
28 class ContextHelpAjaxController
29 {
30 /**
31 * The main dispatcher function. Collect data and prepare HTML output.
32 *
33 * @param ServerRequestInterface $request
34 * @param ResponseInterface $response
35 * @return ResponseInterface
36 */
37 public function getHelpAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
38 {
39 $params = isset($request->getParsedBody()['params']) ? $request->getParsedBody()['params'] : $request->getQueryParams()['params'];
40 if ($params['action'] === 'getContextHelp') {
41 $result = $this->getContextHelp($params['table'], $params['field']);
42 return GeneralUtility::makeInstance(JsonResponse::class, [
43 'title' => $result['title'],
44 'content' => $result['description'],
45 'link' => $result['moreInfo']
46 ]);
47 }
48 return $response;
49 }
50
51 /**
52 * Fetch the context help for the given table/field parameters
53 *
54 * @param string $table Table identifier
55 * @param string $field Field identifier
56 * @return array complete Help information
57 */
58 protected function getContextHelp($table, $field)
59 {
60 $helpTextArray = BackendUtility::helpTextArray($table, $field);
61 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
62 $moreIcon = $helpTextArray['moreInfo'] ? $iconFactory->getIcon('actions-view-go-forward', Icon::SIZE_SMALL)->render() : '';
63 return [
64 'title' => $helpTextArray['title'],
65 'description' => '<p class="t3-help-short' . ($moreIcon ? ' tipIsLinked' : '') . '">' . $helpTextArray['description'] . $moreIcon . '</p>',
66 'id' => $table . '.' . $field,
67 'moreInfo' => $helpTextArray['moreInfo']
68 ];
69 }
70 }