49a06a05f686c8b8660c380bc8f4fc9c8733978f
[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\Localization\LanguageService;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Recordlist\Controller\AbstractLinkBrowserController;
22
23 /**
24 * Base class for link handlers
25 *
26 * @internal 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 public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration)
74 {
75 $this->linkBrowser = $linkBrowser;
76 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
77 $this->view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
78 $this->view->getRequest()->setControllerExtensionName('recordlist');
79 $this->view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Templates/LinkBrowser')]);
80 $this->view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Partials/LinkBrowser')]);
81 $this->view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:recordlist/Resources/Private/Layouts/LinkBrowser')]);
82 }
83
84 /**
85 * @return array
86 */
87 public function getLinkAttributes()
88 {
89 return $this->linkAttributes;
90 }
91
92 /**
93 * @param string[] $fieldDefinitions Array of link attribute field definitions
94 * @return string[]
95 */
96 public function modifyLinkAttributes(array $fieldDefinitions)
97 {
98 return $fieldDefinitions;
99 }
100
101 /**
102 * Return TRUE if the handler supports to update a link.
103 *
104 * This is useful for e.g. file or page links, when only attributes are changed.
105 *
106 * @return bool
107 */
108 public function isUpdateSupported()
109 {
110 return $this->updateSupported;
111 }
112
113 /**
114 * Sets a DB mount and stores it in the currently defined backend user in her/his uc
115 */
116 protected function setTemporaryDbMounts()
117 {
118 $backendUser = $this->getBackendUser();
119
120 // Clear temporary DB mounts
121 $tmpMount = GeneralUtility::_GET('setTempDBmount');
122 if (isset($tmpMount)) {
123 $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
124 }
125 // Set temporary DB mounts
126 $alternativeWebmountPoint = (int)$backendUser->getSessionData('pageTree_temporaryMountPoint');
127 if ($alternativeWebmountPoint) {
128 $alternativeWebmountPoint = GeneralUtility::intExplode(',', $alternativeWebmountPoint);
129 $backendUser->setWebmounts($alternativeWebmountPoint);
130 } else {
131 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
132 $alternativeWebmountPoints = \trim($backendUser->getTSConfig()['options.']['pageTree.']['altElementBrowserMountPoints'] ?? '');
133 $appendAlternativeWebmountPoints = $backendUser->getTSConfig()['options.']['pageTree.']['altElementBrowserMountPoints.']['append'] ?? '';
134 if ($alternativeWebmountPoints) {
135 $alternativeWebmountPoints = GeneralUtility::intExplode(',', $alternativeWebmountPoints);
136 $this->getBackendUser()->setWebmounts($alternativeWebmountPoints, $appendAlternativeWebmountPoints);
137 }
138 }
139 }
140
141 /**
142 * @return BackendUserAuthentication
143 */
144 protected function getBackendUser()
145 {
146 return $GLOBALS['BE_USER'];
147 }
148
149 /**
150 * @return LanguageService
151 */
152 protected function getLanguageService()
153 {
154 return $GLOBALS['LANG'];
155 }
156 }