TYPO3 CMS  TYPO3_8-7
ElementBrowserPageTreeView.php
Go to the documentation of this file.
1 <?php
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 
21 
28 {
35  public $ext_showPageId = false;
36 
40  public $ext_pArrPages = true;
41 
46 
50  public function __construct()
51  {
52  parent::__construct();
53  $this->init();
54  $this->clause = ' AND doktype <> ' . PageRepository::DOKTYPE_RECYCLER . $this->clause;
55  }
56 
61  {
62  $this->linkParameterProvider = $linkParameterProvider;
63  $this->thisScript = $linkParameterProvider->getScriptUrl();
64  }
65 
74  public function wrapTitle($title, $v, $ext_pArrPages = false)
75  {
76  if ($this->ext_isLinkable($v['doktype'], $v['uid'])) {
77  $url = GeneralUtility::makeInstance(LinkService::class)->asString(['type' => LinkService::TYPE_PAGE, 'pageuid' => (int)$v['uid']]);
78  return '<span class="list-tree-title"><a href="' . htmlspecialchars($url) . '" class="t3js-pageLink">' . $title . '</a></span>';
79  }
80  return '<span class="list-tree-title text-muted">' . $title . '</span>';
81  }
82 
89  public function printTree($treeArr = '')
90  {
91  $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
92  if (!is_array($treeArr)) {
93  $treeArr = $this->tree;
94  }
95  $out = '';
96  // We need to count the opened <ul>'s every time we dig into another level,
97  // so we know how many we have to close when all children are done rendering
98  $closeDepth = [];
99  foreach ($treeArr as $treeItem) {
100  if ($treeItem['isMountPointPath']) {
101  $out .= '<li class="list-tree-path">' . $treeItem['title'] . '</li>';
102  continue;
103  }
104 
105  $classAttr = $treeItem['row']['_CSSCLASS'];
106  if ($treeItem['isFirst']) {
107  $out .= '<ul class="list-tree">';
108  }
109 
110  // Add CSS classes to the list item
111  if ($treeItem['hasSub']) {
112  $classAttr .= ' list-tree-control-open';
113  }
114 
115  $selected = '';
116  if ($this->linkParameterProvider->isCurrentlySelectedItem(['pid' => (int)$treeItem['row']['uid']])) {
117  $selected = ' bg-success';
118  $classAttr .= ' active';
119  }
120  $urlParameters = $this->linkParameterProvider->getUrlParameters(['pid' => (int)$treeItem['row']['uid']]);
121  $aOnClick = 'return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParameters), '&')) . ');';
122  $cEbullet = $this->ext_isLinkable($treeItem['row']['doktype'], $treeItem['row']['uid'])
123  ? '<a href="#" class="list-tree-show" onclick="' . htmlspecialchars($aOnClick) . '"><i class="fa fa-caret-square-o-right"></i></a>'
124  : '';
125  $out .= '
126  <li' . ($classAttr ? ' class="' . trim($classAttr) . '"' : '') . '>
127  <span class="list-tree-group' . $selected . '">
128  ' . $cEbullet . $treeItem['HTML'] . $this->wrapTitle($this->getTitleStr($treeItem['row'], $titleLen), $treeItem['row'], $this->ext_pArrPages) . '
129  </span>
130  ';
131  if (!$treeItem['hasSub']) {
132  $out .= '</li>';
133  }
134 
135  // We have to remember if this is the last one
136  // on level X so the last child on level X+1 closes the <ul>-tag
137  if ($treeItem['isLast']) {
138  $closeDepth[$treeItem['invertedDepth']] = 1;
139  }
140  // If this is the last one and does not have subitems, we need to close
141  // the tree as long as the upper levels have last items too
142  if ($treeItem['isLast'] && !$treeItem['hasSub']) {
143  for ($i = $treeItem['invertedDepth']; $closeDepth[$i] == 1; $i++) {
144  $closeDepth[$i] = 0;
145  $out .= '</ul></li>';
146  }
147  }
148  }
149  return '<ul class="list-tree list-tree-root">' . $out . '</ul>';
150  }
151 
159  public function ext_isLinkable($doktype, $uid)
160  {
161  return $uid && $doktype < PageRepository::DOKTYPE_SPACER;
162  }
163 
173  public function PM_ATagWrap($icon, $cmd, $bMark = '', $isOpen = false)
174  {
175  $anchor = $bMark ? '#' . $bMark : '';
176  $name = $bMark ? ' name=' . $bMark : '';
177  $urlParameters = $this->linkParameterProvider->getUrlParameters([]);
178  $urlParameters['PM'] = $cmd;
179  $aOnClick = 'return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParameters), '&')) . ',' . GeneralUtility::quoteJSvalue($anchor) . ');';
180  return '<a class="list-tree-control ' . ($isOpen ? 'list-tree-control-open' : 'list-tree-control-closed')
181  . '" href="#"' . htmlspecialchars($name) . ' onclick="' . htmlspecialchars($aOnClick) . '"><i class="fa"></i></a>';
182  }
183 
191  public function wrapIcon($icon, $row)
192  {
193  if ($this->ext_showPageId) {
194  $icon .= '[' . $row['uid'] . ']&nbsp;';
195  }
196  return $icon;
197  }
198 }
init($clause='', $orderByFields='')
static makeInstance($className,... $constructorArguments)
static implodeArrayForUrl($name, array $theArray, $str='', $skipBlank=false, $rawurlencodeParamName=false)
setLinkParameterProvider(LinkParameterProviderInterface $linkParameterProvider)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']