90dd7e40749efce34453f9aa0a90bef777bbdcb6
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FrontendFormEngine.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form;
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\Core\Utility\GeneralUtility;
18
19 /**
20 * Extension class for the rendering of TCEforms in the frontend
21 *
22 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
23 */
24 class FrontendFormEngine extends \TYPO3\CMS\Backend\Form\FormEngine {
25
26 /**
27 * Constructs this object.
28 */
29 public function __construct() {
30 $this->initializeTemplateContainer();
31 parent::__construct();
32 }
33
34 /**
35 * Prints the palette in the frontend editing (forms-on-page?)
36 *
37 * @param array $paletteArray The palette array to print
38 * @return string HTML output
39 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
40 */
41 public function printPalette(array $paletteArray) {
42 GeneralUtility::logDeprecatedFunction();
43 $out = '';
44 $bgColor = ' bgcolor="#D6DAD0"';
45 foreach ($paletteArray as $content) {
46 $hRow[] = '<td' . $bgColor . '><font face="verdana" size="1">&nbsp;</font></td><td nowrap="nowrap"' . $bgColor . '><font color="#666666" face="verdana" size="1">' . $content['NAME'] . '</font></td>';
47 $iRow[] = '<td valign="top">' . '<img name="req_' . $content['TABLE'] . '_' . $content['ID'] . '_' . $content['FIELD'] . '" src="clear.gif" width="10" height="10" alt="" /></td><td nowrap="nowrap" valign="top">' . $content['ITEM'] . $content['HELP_ICON'] . '</td>';
48 }
49 $out = '<table border="0" cellpadding="0" cellspacing="0">
50 <tr><td><img src="clear.gif" width="1" height="1" alt="" /></td>' . implode('', $hRow) . '</tr>
51 <tr><td></td>' . implode('', $iRow) . '</tr>
52 </table>';
53 return $out;
54 }
55
56 /**
57 * Includes a javascript library that exists in the core /typo3/ directory. The
58 * backpath is automatically applied.
59 * This method adds the library to $GLOBALS['TSFE']->additionalHeaderData[$lib].
60 *
61 * @param string $lib Library name. Call it with the full path like "contrib/prototype/prototype.js" to load it
62 * @return void
63 */
64 public function loadJavascriptLib($lib) {
65 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
66 $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
67 $pageRenderer->addJsLibrary($lib, $this->prependBackPath($lib));
68 }
69
70 /**
71 * Initializes an anonymous template container.
72 * The created container can be compared to "record_edit" module in backend-only disposal.
73 *
74 * @return void
75 */
76 public function initializeTemplateContainer() {
77 $GLOBALS['TBE_TEMPLATE'] = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\FrontendDocumentTemplate::class);
78 $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->addInlineSetting('', 'PATH_typo3', GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . TYPO3_mainDir);
79 $GLOBALS['SOBE'] = new \stdClass();
80 $GLOBALS['SOBE']->doc = $GLOBALS['TBE_TEMPLATE'];
81 }
82
83 /**
84 * Prepends backPath to given URL if it's not an absolute URL
85 *
86 * @param string $url
87 * @return string
88 */
89 private function prependBackPath($url) {
90 return $url;
91 }
92
93 }