4bede3060df2c553d1f6941e2568a21b5c238046
[Packages/TYPO3.CMS.git] / typo3 / sysext / context_help / Classes / ExtDirect / ContextHelpDataProvider.php
1 <?php
2 namespace TYPO3\CMS\ContextHelp\ExtDirect;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2010-2013 Steffen Kamper <steffen@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 /**
31 * ExtDirect DataProvider for ContextHelp
32 *
33 * @author Steffen Kamper <steffen@typo3.org>
34 */
35 class ContextHelpDataProvider {
36
37 /**
38 * Fetch the context help for the given table/field parameters
39 *
40 * @param string $table Table identifier
41 * @param string $field Field identifier
42 * @return array complete Help information
43 */
44 public function getContextHelp($table, $field) {
45 $helpTextArray = \TYPO3\CMS\Backend\Utility\BackendUtility::helpTextArray($table, $field);
46 $moreIcon = $helpTextArray['moreInfo'] ? \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-forward') : '';
47 return array(
48 'title' => $helpTextArray['title'],
49 'description' => '<p class="t3-help-short' . ($moreIcon ? ' tipIsLinked' : '') . '">' . $helpTextArray['description'] . $moreIcon . '</p>',
50 'id' => $table . '.' . $field,
51 'moreInfo' => $helpTextArray['moreInfo']
52 );
53 }
54
55 /**
56 * Fetch the context help for the given table
57 *
58 * @param string $table Table identifier
59 * @return array Complete help information
60 */
61 public function getTableContextHelp($table) {
62 $output = array();
63 if (!isset($GLOBALS['TCA_DESCR'][$table]['columns'])) {
64 $GLOBALS['LANG']->loadSingleTableDescription($table);
65 }
66 if (is_array($GLOBALS['TCA_DESCR'][$table]) && is_array($GLOBALS['TCA_DESCR'][$table]['columns'])) {
67 $arrow = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-view-go-forward');
68 foreach ($GLOBALS['TCA_DESCR'][$table]['columns'] as $field => $data) {
69 $output[$field] = array(
70 'description' => NULL,
71 'title' => NULL,
72 'moreInfo' => FALSE,
73 'id' => $table . '.' . $field
74 );
75 // Add alternative title, if defined
76 if ($data['alttitle']) {
77 $output[$field]['title'] = $data['alttitle'];
78 }
79 // If we have more information to show
80 if ($data['image_descr'] || $data['seeAlso'] || $data['details'] || $data['syntax']) {
81 $output[$field]['moreInfo'] = TRUE;
82 }
83 // Add description
84 if ($data['description']) {
85 $output[$field]['description'] = $data['description'] . ($output[$field]['moreInfo'] ? $arrow : '');
86 }
87 }
88 }
89 return $output;
90 }
91
92 }