[TASK] Call explicit render() on icon objects
[Packages/TYPO3.CMS.git] / typo3 / sysext / version / Classes / View / VersionView.php
1 <?php
2 namespace TYPO3\CMS\Version\View;
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\Imaging\Icon;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Backend\Utility\BackendUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21
22 /**
23 * Contains some parts for staging, versioning and workspaces
24 * to interact with the TYPO3 Core Engine
25 */
26 class VersionView {
27
28 /**
29 * Creates the version selector for the page id inputted.
30 * Moved out of the core file \TYPO3\CMS\Backend\Template\DocumentTemplate
31 *
32 * @param int $id Page id to create selector for.
33 * @param bool $noAction If set, there will be no button for swapping page.
34 * @return void
35 * @see \TYPO3\CMS\Backend\Template\DocumentTemplate
36 */
37 public function getVersionSelector($id, $noAction = FALSE) {
38 if ($id <= 0) {
39 return;
40 }
41 if ($GLOBALS['BE_USER']->workspace == 0) {
42 // Get Current page record:
43 $curPage = BackendUtility::getRecord('pages', $id);
44 // If the selected page is not online, find the right ID
45 $onlineId = $curPage['pid'] == -1 ? $curPage['t3ver_oid'] : $id;
46 // Select all versions of online version:
47 $versions = BackendUtility::selectVersionsOfRecord('pages', $onlineId, 'uid,pid,t3ver_label,t3ver_oid,t3ver_wsid,t3ver_id', NULL);
48 // If more than one was found...:
49 if (count($versions) > 1) {
50 // Create selector box entries:
51 $opt = array();
52 foreach ($versions as $vRow) {
53 if ($vRow['uid'] == $onlineId) {
54 // Live version
55 $label = '[' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionSelect.live', TRUE) . ']';
56 } else {
57 $label = $vRow['t3ver_label'] . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionId', TRUE) . ' ' . $vRow['t3ver_id'] . ($vRow['t3ver_wsid'] != 0 ? ' ' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:workspaceId', TRUE) . ' ' . $vRow['t3ver_wsid'] : '') . ')';
58 }
59 $opt[] = '<option value="' . htmlspecialchars(GeneralUtility::linkThisScript(array('id' => $vRow['uid']))) . '"' . ($id == $vRow['uid'] ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
60 }
61 /** @var $iconFactory \TYPO3\CMS\Core\Imaging\IconFactory */
62 $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
63 // Add management link:
64 $management = '
65 <a class="btn btn-default" href="' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getModuleUrl('web_txversionM1', array('table' => 'pages', 'uid' => $onlineId))) . '">
66 ' . $iconFactory->getIcon('actions-version-open', Icon::SIZE_SMALL)->render() . '
67 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.mgm', TRUE) . '
68 </a>';
69 // Create onchange handler:
70 $onChange = 'window.location.href=this.options[this.selectedIndex].value;';
71 // Controls:
72 if ($id == $onlineId) {
73 $controls = '<strong class="text-success">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.online', TRUE) . '</strong>';
74 } elseif (!$noAction) {
75 $href = $GLOBALS['TBE_TEMPLATE']->issueCommand(
76 '&cmd[pages][' . $onlineId . '][version][swapWith]=' . $id . '&cmd[pages][' . $onlineId . '][version][action]=swap',
77 GeneralUtility::linkThisScript(array('id' => $onlineId))
78 );
79 $controls = '
80 <a href="' . htmlspecialchars($href) . '" class="btn btn-default" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swapPage', TRUE) . '">
81 ' . $iconFactory->getIcon('actions-version-swap-version', Icon::SIZE_SMALL)->render() . '
82 ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:ver.swap', TRUE) . '
83 </a>';
84 }
85 // Write out HTML code:
86 return '
87 <!--
88 Version selector:
89 -->
90 <div id="typo3-version-selector" class="form-inline form-inline-spaced">
91 <div class="form-group">
92 <label for="version-selector">' . $GLOBALS['LANG']->sL('LLL:EXT:version/Resources/Private/Language/locallang.xlf:versionSelect.label', TRUE) . '</label>
93 <select id="version-selector" class="form-control" onchange="' . htmlspecialchars($onChange) . '">
94 ' . implode('', $opt) . '
95 </select>
96 </div>
97 <div class="form-group">
98 ' . $controls . '
99 </div>
100 <div class="form-group">
101 ' . $management . '
102 </div>
103 </div>
104 ';
105 }
106 }
107 }
108
109 }