[TASK] Use Fluid for rendering LinkBrowsers
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / LinkHandler / AbstractLinkHandler.php
1 <?php
2 namespace TYPO3\CMS\Recordlist\LinkHandler;
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\Authentication\BackendUserAuthentication;
18 use TYPO3\CMS\Core\Imaging\IconFactory;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20 use TYPO3\CMS\Lang\LanguageService;
21 use TYPO3\CMS\Recordlist\Controller\AbstractLinkBrowserController;
22
23 /**
24 * Base class for link handlers
25 *
26 * NOTE: This class should only be used internally. Extensions must implement the LinkHandlerInterface.
27 */
28 abstract class AbstractLinkHandler
29 {
30 /**
31 * Available additional link attributes
32 *
33 * 'rel' only works in RTE, still we have to declare support for it.
34 *
35 * @var string[]
36 */
37 protected $linkAttributes = [ 'target', 'title', 'class', 'params', 'rel' ];
38
39 /**
40 * @var bool
41 */
42 protected $updateSupported = true;
43
44 /**
45 * @var AbstractLinkBrowserController
46 */
47 protected $linkBrowser;
48
49 /**
50 * @var IconFactory
51 */
52 protected $iconFactory;
53
54 /**
55 * @var \TYPO3\CMS\Fluid\View\StandaloneView
56 */
57 protected $view;
58
59 /**
60 * Constructor
61 */
62 public function __construct()
63 {
64 }
65
66 /**
67 * Initialize the handler
68 *
69 * @param AbstractLinkBrowserController $linkBrowser
70 * @param string $identifier
71 * @param array $configuration Page TSconfig
72 *
73 * @return void
74 */
75 public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration)
76 {
77 $this->linkBrowser = $linkBrowser;
78 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
79 $this->view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
80 $this->view->getRequest()->setControllerExtensionName('recordlist');
81 $this->view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Templates/LinkBrowser')]);
82 $this->view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Partials/LinkBrowser')]);
83 $this->view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Layouts/LinkBrowser')]);
84 }
85
86 /**
87 * @return array
88 */
89 public function getLinkAttributes()
90 {
91 return $this->linkAttributes;
92 }
93
94 /**
95 * @param string[] $fieldDefinitions Array of link attribute field definitions
96 * @return string[]
97 */
98 public function modifyLinkAttributes(array $fieldDefinitions)
99 {
100 return $fieldDefinitions;
101 }
102
103 /**
104 * Return TRUE if the handler supports to update a link.
105 *
106 * This is useful for e.g. file or page links, when only attributes are changed.
107 *
108 * @return bool
109 */
110 public function isUpdateSupported()
111 {
112 return $this->updateSupported;
113 }
114
115 /**
116 * @return void
117 */
118 protected function setTemporaryDbMounts()
119 {
120 $backendUser = $this->getBackendUser();
121
122 // Clear temporary DB mounts
123 $tmpMount = GeneralUtility::_GET('setTempDBmount');
124 if (isset($tmpMount)) {
125 $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
126 }
127 // Set temporary DB mounts
128 $alternativeWebmountPoint = (int)$backendUser->getSessionData('pageTree_temporaryMountPoint');
129 if ($alternativeWebmountPoint) {
130 $alternativeWebmountPoint = GeneralUtility::intExplode(',', $alternativeWebmountPoint);
131 $backendUser->setWebmounts($alternativeWebmountPoint);
132 } else {
133 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
134 $alternativeWebmountPoints = trim($backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
135 $appendAlternativeWebmountPoints = $backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints.append');
136 if ($alternativeWebmountPoints) {
137 $alternativeWebmountPoints = GeneralUtility::intExplode(',', $alternativeWebmountPoints);
138 $this->getBackendUser()->setWebmounts($alternativeWebmountPoints, $appendAlternativeWebmountPoints);
139 }
140 }
141 }
142
143 /**
144 * @return BackendUserAuthentication
145 */
146 protected function getBackendUser()
147 {
148 return $GLOBALS['BE_USER'];
149 }
150
151 /**
152 * @return LanguageService
153 */
154 protected function getLanguageService()
155 {
156 return $GLOBALS['LANG'];
157 }
158 }