TYPO3  7.6
backend/Classes/Tree/View/ElementBrowserPageTreeView.php
Go to the documentation of this file.
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 
20 
27 {
34  public $ext_showPageId = false;
35 
39  public $ext_showNavTitle = false;
40 
44  public $ext_pArrPages = true;
45 
50 
54  public function __construct()
55  {
56  parent::__construct();
57  $this->init();
58  $this->clause = ' AND doktype <> ' . PageRepository::DOKTYPE_RECYCLER . $this->clause;
59  }
60 
67  {
68  $this->linkParameterProvider = $linkParameterProvider;
69  $this->thisScript = $linkParameterProvider->getScriptUrl();
70  }
71 
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 
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 
160  public function ext_isLinkable($doktype, $uid)
161  {
162  return $uid && $doktype < PageRepository::DOKTYPE_SPACER;
163  }
164 
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 
192  public function wrapIcon($icon, $row)
193  {
194  if ($this->ext_showPageId) {
195  $icon .= '[' . $row['uid'] . ']&nbsp;';
196  }
197  return $icon;
198  }
199 }