[BUGFIX] Bring declarations of wrapTitle() in line
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Tree / View / ElementBrowserFolderTreeView.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\Resource\Folder;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Recordlist\Tree\View\LinkParameterProviderInterface;
20
21 /**
22 * Base extension class which generates the folder tree.
23 * Used directly by the RTE.
24 * also used for the linkpicker on files
25 *
26 * Browsable folder tree, used in Element Browser and RTE (for which it will be extended)
27 * previously located inside typo3/class.browse_links.php
28 */
29 class ElementBrowserFolderTreeView extends FolderTreeView
30 {
31 /**
32 * @var int
33 */
34 public $ext_IconMode = 1;
35
36 /**
37 * @var LinkParameterProviderInterface
38 */
39 protected $linkParameterProvider;
40
41 /**
42 * @param LinkParameterProviderInterface $linkParameterProvider
43 *
44 * @return void
45 */
46 public function setLinkParameterProvider(LinkParameterProviderInterface $linkParameterProvider)
47 {
48 $this->linkParameterProvider = $linkParameterProvider;
49 $this->thisScript = $linkParameterProvider->getScriptUrl();
50 }
51
52 /**
53 * Wrapping the title in a link, if applicable.
54 *
55 * @param string $title Title, ready for output.
56 * @param Folder $folderObject The record
57 * @param int $bank Bank pointer (which mount point number)
58 * @return string Wrapping title string.
59 */
60 public function wrapTitle($title, $folderObject, $bank = 0)
61 {
62 if ($this->ext_isLinkable($folderObject)) {
63 $parameters = GeneralUtility::implodeArrayForUrl('', $this->linkParameterProvider->getUrlParameters(['identifier' => $folderObject->getCombinedIdentifier()]));
64 return '<a href="#" onclick="return jumpToUrl(' . htmlspecialchars(GeneralUtility::quoteJSvalue($this->getThisScript() . ltrim($parameters, '&'))) . ');">' . $title . '</a>';
65 } else {
66 return '<span class="text-muted">' . $title . '</span>';
67 }
68 }
69
70 /**
71 * Returns TRUE if the input "record" contains a folder which can be linked.
72 *
73 * @param Folder $folderObject Object with information about the folder element. Contains keys like title, uid, path, _title
74 * @return bool TRUE is returned if the path is found in the web-part of the server and is NOT a recycler or temp folder AND if ->ext_noTempRecyclerDirs is not set.
75 */
76 public function ext_isLinkable(Folder $folderObject)
77 {
78 $identifier = $folderObject->getIdentifier();
79 return !$this->ext_noTempRecyclerDirs || substr($identifier, -7) !== '_temp_/' && substr($identifier, -11) !== '_recycler_/';
80 }
81
82 /**
83 * @param string $cmd
84 * @param bool $isOpen
85 * @return string
86 */
87 protected function renderPMIconAndLink($cmd, $isOpen)
88 {
89 if (get_class($this) === __CLASS__) {
90 return $this->PMiconATagWrap('', $cmd, !$isOpen);
91 }
92 return parent::renderPMIconAndLink($cmd, $isOpen);
93 }
94
95 /**
96 * Wrap the plus/minus icon in a link
97 *
98 * @param string $icon HTML string to wrap, probably an image tag.
99 * @param string $cmd Command for 'PM' get var
100 * @param bool|string $bMark If set, the link will have an anchor point (=$bMark) and a name attribute (=$bMark)
101 * @param bool $isOpen check if the item has children
102 * @return string Link-wrapped input string
103 * @access private
104 */
105 public function PM_ATagWrap($icon, $cmd, $bMark = '', $isOpen = false)
106 {
107 $anchor = $bMark ? '#' . $bMark : '';
108 $name = $bMark ? ' name=' . $bMark : '';
109 $urlParameters = $this->linkParameterProvider->getUrlParameters([]);
110 $urlParameters['PM'] = $cmd;
111 $aOnClick = 'return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . ltrim(GeneralUtility::implodeArrayForUrl('', $urlParameters), '&')) . ',' . GeneralUtility::quoteJSvalue($anchor) . ');';
112 return '<a href="#"' . htmlspecialchars($name) . ' onclick="' . htmlspecialchars($aOnClick) . '">' . $icon . '</a>';
113 }
114
115 /**
116 * Wrap the plus/minus icon in a link
117 *
118 * @param string $icon HTML string to wrap, probably an image tag.
119 * @param string $cmd Command for 'PM' get var
120 * @param bool $isExpand Whether to be expanded
121 * @return string Link-wrapped input string
122 * @internal
123 */
124 public function PMiconATagWrap($icon, $cmd, $isExpand = true)
125 {
126 if (empty($this->scope)) {
127 $this->scope = array(
128 'class' => get_class($this),
129 'script' => $this->thisScript,
130 'ext_noTempRecyclerDirs' => $this->ext_noTempRecyclerDirs,
131 'browser' => $this->linkParameterProvider->getUrlParameters([]),
132 );
133 }
134
135 return parent::PMiconATagWrap($icon, $cmd, $isExpand);
136 }
137 }