[TASK] Fix CGL errors
[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 * Constructor
56 */
57 public function __construct()
58 {
59 }
60
61 /**
62 * Initialize the handler
63 *
64 * @param AbstractLinkBrowserController $linkBrowser
65 * @param string $identifier
66 * @param array $configuration Page TSconfig
67 *
68 * @return void
69 */
70 public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration)
71 {
72 $this->linkBrowser = $linkBrowser;
73 $this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
74 }
75
76 /**
77 * @return array
78 */
79 public function getLinkAttributes()
80 {
81 return $this->linkAttributes;
82 }
83
84 /**
85 * @param string[] $fieldDefinitions Array of link attribute field definitions
86 * @return string[]
87 */
88 public function modifyLinkAttributes(array $fieldDefinitions)
89 {
90 return $fieldDefinitions;
91 }
92
93 /**
94 * Return TRUE if the handler supports to update a link.
95 *
96 * This is useful for e.g. file or page links, when only attributes are changed.
97 *
98 * @return bool
99 */
100 public function isUpdateSupported()
101 {
102 return $this->updateSupported;
103 }
104
105 /**
106 * @return void
107 */
108 protected function setTemporaryDbMounts()
109 {
110 $backendUser = $this->getBackendUser();
111
112 // Clear temporary DB mounts
113 $tmpMount = GeneralUtility::_GET('setTempDBmount');
114 if (isset($tmpMount)) {
115 $backendUser->setAndSaveSessionData('pageTree_temporaryMountPoint', (int)$tmpMount);
116 }
117 // Set temporary DB mounts
118 $alternativeWebmountPoint = (int)$backendUser->getSessionData('pageTree_temporaryMountPoint');
119 if ($alternativeWebmountPoint) {
120 $alternativeWebmountPoint = GeneralUtility::intExplode(',', $alternativeWebmountPoint);
121 $backendUser->setWebmounts($alternativeWebmountPoint);
122 } else {
123 // Setting alternative browsing mounts (ONLY local to browse_links.php this script so they stay "read-only")
124 $alternativeWebmountPoints = trim($backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints'));
125 $appendAlternativeWebmountPoints = $backendUser->getTSConfigVal('options.pageTree.altElementBrowserMountPoints.append');
126 if ($alternativeWebmountPoints) {
127 $alternativeWebmountPoints = GeneralUtility::intExplode(',', $alternativeWebmountPoints);
128 $this->getBackendUser()->setWebmounts($alternativeWebmountPoints, $appendAlternativeWebmountPoints);
129 }
130 }
131 }
132
133 /**
134 * @return BackendUserAuthentication
135 */
136 protected function getBackendUser()
137 {
138 return $GLOBALS['BE_USER'];
139 }
140
141 /**
142 * @return LanguageService
143 */
144 protected function getLanguageService()
145 {
146 return $GLOBALS['LANG'];
147 }
148 }