[BUGFIX] Ensure manually updated slug is saved correctly
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / View / BrowseTreeView.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\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Exception\SiteNotFoundException;
19 use TYPO3\CMS\Core\Site\SiteFinder;
20 use TYPO3\CMS\Core\Type\Bitmask\Permission;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Generate a page-tree, browsable.
25 */
26 class BrowseTreeView extends AbstractTreeView
27 {
28 /**
29 * @var array
30 */
31 public $fieldArray = [
32 'uid',
33 'pid',
34 'title',
35 'doktype',
36 'nav_title',
37 'mount_pid',
38 'php_tree_stop',
39 't3ver_state',
40 'hidden',
41 'starttime',
42 'endtime',
43 'fe_group',
44 'module',
45 'extendToSubpages',
46 'nav_hide',
47 't3ver_wsid',
48 't3ver_move_id',
49 'is_siteroot'
50 ];
51
52 /**
53 * override to use this treeName
54 * @var string
55 */
56 public $treeName = 'browsePages';
57
58 /**
59 * override to use this table
60 * @var string
61 */
62 public $table = 'pages';
63
64 /**
65 * override to use this domIdPrefix
66 * @var string
67 */
68 public $domIdPrefix = 'pages';
69
70 /**
71 * @var bool
72 */
73 public $ext_showNavTitle = false;
74
75 /**
76 * Initialize, setting what is necessary for browsing pages.
77 * Using the current user.
78 *
79 * @param string $clause Additional clause for selecting pages.
80 * @param string $orderByFields record ORDER BY field
81 */
82 public function init($clause = '', $orderByFields = '')
83 {
84 $backendUser = $this->getBackendUser();
85 // This will hide records from display - it has nothing to do with user rights!!
86 $clauseExcludePidList = '';
87 $pidList = $backendUser->getTSConfig()['options.']['hideRecords.']['pages'] ?? '';
88 if (!empty($pidList)) {
89 if ($pidList = implode(',', GeneralUtility::intExplode(',', $pidList))) {
90 $clauseExcludePidList = ' AND pages.uid NOT IN (' . $pidList . ')';
91 }
92 }
93 // This is very important for making trees of pages: Filtering out deleted pages, pages with no access to and sorting them correctly:
94 parent::init(' AND deleted=0 AND sys_language_uid=0 AND ' . $backendUser->getPagePermsClause(Permission::PAGE_SHOW) . ' ' . $clause . $clauseExcludePidList, 'sorting');
95 $this->title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
96 $this->MOUNTS = $backendUser->returnWebmounts();
97 if ($pidList) {
98 // Remove mountpoint if explicitly set in options.hideRecords.pages (see above)
99 $hideList = explode(',', $pidList);
100 $this->MOUNTS = array_diff($this->MOUNTS, $hideList);
101 }
102 }
103
104 /**
105 * Creates title attribute content for pages.
106 * Uses API function in \TYPO3\CMS\Backend\Utility\BackendUtility which will retrieve lots of useful information for pages.
107 *
108 * @param array $row The table row.
109 * @return string
110 */
111 public function getTitleAttrib($row)
112 {
113 return BackendUtility::titleAttribForPages($row, '1=1 ' . $this->clause, 0);
114 }
115
116 /**
117 * Wrapping the image tag, $icon, for the row, $row (except for mount points)
118 *
119 * @param string $icon The image tag for the icon
120 * @param array $row The row for the current element
121 * @return string The processed icon input value.
122 * @internal
123 */
124 public function wrapIcon($icon, $row)
125 {
126 // Wrap icon in click-menu link.
127 $theIcon = '';
128 if (!$this->ext_IconMode) {
129 $theIcon = BackendUtility::wrapClickMenuOnIcon($icon, $this->treeName, $this->getId($row), 0);
130 } elseif ($this->ext_IconMode === 'titlelink') {
131 $aOnClick = 'return jumpTo(' . GeneralUtility::quoteJSvalue($this->getJumpToParam($row)) . ',this,'
132 . GeneralUtility::quoteJSvalue($this->domIdPrefix . $this->getId($row)) . ',' . $this->bank . ');';
133 $theIcon = '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $icon . '</a>';
134 }
135 return $theIcon;
136 }
137
138 /**
139 * Returns the title for the input record. If blank, a "no title" label (localized) will be returned.
140 * Do NOT htmlspecialchar the string from this function - has already been done.
141 *
142 * @param array $row The input row array (where the key "title" is used for the title)
143 * @param int $titleLen Title length (30)
144 * @return string The title.
145 */
146 public function getTitleStr($row, $titleLen = 30)
147 {
148 if ($this->ext_showNavTitle && isset($row['nav_title']) && trim($row['nav_title']) !== '') {
149 $title = parent::getTitleStr(['title' => $row['nav_title']], $titleLen);
150 } else {
151 $title = parent::getTitleStr($row, $titleLen);
152 }
153 if (!empty($row['is_siteroot'])
154 && $this->getBackendUser()->getTSConfig()['options.']['pageTree.']['showDomainNameWithTitle'] ?? false
155 ) {
156 $pageId = (int)$row['uid'];
157 $siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
158 try {
159 $site = $siteFinder->getSiteByRootPageId($pageId);
160 $title .= ' [' . (string)$site->getBase() . ']';
161 } catch (SiteNotFoundException $e) {
162 // No site found
163 }
164 }
165 return $title;
166 }
167 }