[BUGFIX] Show mountpoint path in record + link browsers if enabled in UserTS
[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_pArrPages = true;
40
41 /**
42 * @var LinkParameterProviderInterface
43 */
44 protected $linkParameterProvider;
45
46 /**
47 * Constructor. Just calling init()
48 */
49 public function __construct()
50 {
51 parent::__construct();
52 $this->init();
53 $this->clause = ' AND doktype <> ' . PageRepository::DOKTYPE_RECYCLER . $this->clause;
54 }
55
56 /**
57 * @param LinkParameterProviderInterface $linkParameterProvider
58 *
59 * @return void
60 */
61 public function setLinkParameterProvider(LinkParameterProviderInterface $linkParameterProvider)
62 {
63 $this->linkParameterProvider = $linkParameterProvider;
64 $this->thisScript = $linkParameterProvider->getScriptUrl();
65 }
66
67 /**
68 * Wrapping the title in a link, if applicable.
69 *
70 * @param string $title Title, (must be ready for output, that means it must be htmlspecialchars()'ed).
71 * @param array $v The record
72 * @param bool $ext_pArrPages (ignored)
73 * @return string Wrapping title string.
74 */
75 public function wrapTitle($title, $v, $ext_pArrPages = false)
76 {
77 if ($this->ext_isLinkable($v['doktype'], $v['uid'])) {
78 return '<span class="list-tree-title"><a href="#" class="t3js-pageLink" data-id="' . (int)$v['uid'] . '">' . $title . '</a></span>';
79 } else {
80 return '<span class="list-tree-title text-muted">' . $title . '</span>';
81 }
82 }
83
84 /**
85 * Create the page navigation tree in HTML
86 *
87 * @param array|string $treeArr Tree array
88 * @return string HTML output.
89 */
90 public function printTree($treeArr = '')
91 {
92 $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
93 if (!is_array($treeArr)) {
94 $treeArr = $this->tree;
95 }
96 $out = '';
97 // We need to count the opened <ul>'s every time we dig into another level,
98 // so we know how many we have to close when all children are done rendering
99 $closeDepth = [];
100 foreach ($treeArr as $treeItem) {
101 if ($treeItem['isMountPointPath']) {
102 $out .= '<li class="list-tree-path">' . $treeItem['title'] . '</li>';
103 continue;
104 }
105
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 }