[BUGFIX] Remove unused references to former ElementBrowser
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / View / ElementBrowserPageTreeView.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tree\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\Utility\GeneralUtility;
18 use TYPO3\CMS\Frontend\Page\PageRepository;
19 use TYPO3\CMS\Recordlist\Tree\View\LinkParameterProviderInterface;
20
21 /**
22 * Class which generates the selectable page tree
23 *
24 * Browsable tree, used in PagePositionMaps (move elements), the Link Wizard and the Database Browser (for which it will be extended)
25 */
26 class ElementBrowserPageTreeView extends BrowseTreeView
27 {
28 /**
29 * whether the page ID should be shown next to the title, activate through
30 * userTSconfig (options.pageTree.showPageIdWithTitle)
31 *
32 * @var bool
33 */
34 public $ext_showPageId = false;
35
36 /**
37 * @var bool
38 */
39 public $ext_showNavTitle = false;
40
41 /**
42 * @var bool
43 */
44 public $ext_pArrPages = true;
45
46 /**
47 * @var LinkParameterProviderInterface
48 */
49 protected $linkParameterProvider;
50
51 /**
52 * Constructor. Just calling init()
53 */
54 public function __construct()
55 {
56 parent::__construct();
57 $this->init();
58 $this->clause = ' AND doktype <> ' . PageRepository::DOKTYPE_RECYCLER . $this->clause;
59 }
60
61 /**
62 * @param LinkParameterProviderInterface $linkParameterProvider
63 *
64 * @return void
65 */
66 public function setLinkParameterProvider(LinkParameterProviderInterface $linkParameterProvider)
67 {
68 $this->linkParameterProvider = $linkParameterProvider;
69 $this->thisScript = $linkParameterProvider->getScriptUrl();
70 }
71
72 /**
73 * Wrapping the title in a link, if applicable.
74 *
75 * @param string $title Title, (must be ready for output, that means it must be htmlspecialchars()'ed).
76 * @param array $v The record
77 * @param bool $ext_pArrPages (ignored)
78 * @return string Wrapping title string.
79 */
80 public function wrapTitle($title, $v, $ext_pArrPages = false)
81 {
82 if ($this->ext_isLinkable($v['doktype'], $v['uid'])) {
83 return '<span class="list-tree-title"><a href="#" class="t3js-pageLink" data-id="' . (int)$v['uid'] . '">' . $title . '</a></span>';
84 } else {
85 return '<span class="list-tree-title text-muted">' . $title . '</span>';
86 }
87 }
88
89 /**
90 * Create the page navigation tree in HTML
91 *
92 * @param array|string $treeArr Tree array
93 * @return string HTML output.
94 */
95 public function printTree($treeArr = '')
96 {
97 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
98 if (!is_array($treeArr)) {
99 $treeArr = $this->tree;
100 }
101 $out = '';
102 // We need to count the opened <ul>'s every time we dig into another level,
103 // so we know how many we have to close when all children are done rendering
104 $closeDepth = array();
105 foreach ($treeArr as $treeItem) {
106 $classAttr = $treeItem['row']['_CSSCLASS'];
107 if ($treeItem['isFirst']) {
108 $out .= '<ul class="list-tree">';
109 }
110
111 // Add CSS classes to the list item
112 if ($treeItem['hasSub']) {
113 $classAttr .= ' list-tree-control-open';
114 }
115
116 $selected = '';
117 if ($this->linkParameterProvider->isCurrentlySelectedItem(['pid' => (int)$treeItem['row']['uid']])) {
118 $selected = ' bg-success';
119 $classAttr .= ' active';
120 }
121 $urlParameters = $this->linkParameterProvider->getUrlParameters(['pid' => (int)$treeItem['row']['uid']]);
122 $aOnClick = 'return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParameters), '&')) . ');';
123 $cEbullet = $this->ext_isLinkable($treeItem['row']['doktype'], $treeItem['row']['uid'])
124 ? '<a href="#" class="list-tree-show" onclick="' . htmlspecialchars($aOnClick) . '"><i class="fa fa-caret-square-o-right"></i></a>'
125 : '';
126 $out .= '
127 <li' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '>
128 <span class="list-tree-group' . $selected . '">
129 ' . $cEbullet . $treeItem['HTML'] . $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLen), $treeItem['row'], $this->ext_pArrPages) . '
130 </span>
131 ';
132 if (!$treeItem['hasSub']) {
133 $out .= '</li>';
134 }
135
136 // We have to remember if this is the last one
137 // on level X so the last child on level X+1 closes the <ul>-tag
138 if ($treeItem['isLast']) {
139 $closeDepth[$treeItem['invertedDepth']] = 1;
140 }
141 // If this is the last one and does not have subitems, we need to close
142 // the tree as long as the upper levels have last items too
143 if ($treeItem['isLast'] && !$treeItem['hasSub']) {
144 for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) {
145 $closeDepth[$i] = 0;
146 $out .= '</ul></li>';
147 }
148 }
149 }
150 return '<ul class="list-tree list-tree-root">' . $out . '</ul>';
151 }
152
153 /**
154 * Returns TRUE if a doktype can be linked.
155 *
156 * @param int $doktype Doktype value to test
157 * @param int $uid uid to test.
158 * @return bool
159 */
160 public function ext_isLinkable($doktype, $uid)
161 {
162 return $uid && $doktype < PageRepository::DOKTYPE_SPACER;
163 }
164
165 /**
166 * Wrap the plus/minus icon in a link
167 *
168 * @param string $icon HTML string to wrap, probably an image tag.
169 * @param string $cmd Command for 'PM' get var
170 * @param string $bMark If set, the link will have an anchor point (=$bMark) and a name attribute (=$bMark)
171 * @param bool $isOpen
172 * @return string Link-wrapped input string
173 */
174 public function PM_ATagWrap($icon, $cmd, $bMark = '', $isOpen = false)
175 {
176 $anchor = $bMark ? '#' . $bMark : '';
177 $name = $bMark ? ' name=' . $bMark : '';
178 $urlParameters = $this->linkParameterProvider->getUrlParameters([]);
179 $urlParameters['PM'] = $cmd;
180 $aOnClick = 'return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParameters), '&')) . ',' . GeneralUtility::quoteJSvalue($anchor) . ');';
181 return '<a class="list-tree-control ' . ($isOpen ? 'list-tree-control-open' : 'list-tree-control-closed')
182 . '" href="#"' . htmlspecialchars($name) . ' onclick="' . htmlspecialchars($aOnClick) . '"><i class="fa"></i></a>';
183 }
184
185 /**
186 * Wrapping the image tag, $icon, for the row, $row
187 *
188 * @param string $icon The image tag for the icon
189 * @param array $row The row for the current element
190 * @return string The processed icon input value.
191 */
192 public function wrapIcon($icon, $row)
193 {
194 if ($this->ext_showPageId) {
195 $icon .= '[' . $row['uid'] . ']&nbsp;';
196 }
197 return $icon;
198 }
199 }