1<?php 2namespace 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 17use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; 18use TYPO3\CMS\Core\Imaging\IconFactory; 19use TYPO3\CMS\Core\Localization\LanguageService; 20use TYPO3\CMS\Core\Utility\GeneralUtility; 21use 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 */ 28abstract 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 126 $backendUser->initializeWebmountsForElementBrowser(); 127 } 128 129 /** 130 * @return BackendUserAuthentication 131 */ 132 protected function getBackendUser() 133 { 134 return $GLOBALS['BE_USER']; 135 } 136 137 /** 138 * @return LanguageService 139 */ 140 protected function getLanguageService() 141 { 142 return $GLOBALS['LANG']; 143 } 144} 145