87edbcccd992c2ae1de5097b5de21a239da82535
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / LinkHandler / UrlLinkHandler.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 Psr\Http\Message\ServerRequestInterface;
18 use TYPO3\CMS\Core\Page\PageRenderer;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Link handler for external URLs
23 */
24 class UrlLinkHandler extends AbstractLinkHandler implements LinkHandlerInterface
25 {
26 /**
27 * Parts of the current link
28 *
29 * @var array
30 */
31 protected $linkParts = [];
32
33 /**
34 * We don't support updates since there is no difference to simply set the link again.
35 *
36 * @var bool
37 */
38 protected $updateSupported = false;
39
40 /**
41 * Constructor
42 */
43 public function __construct()
44 {
45 parent::__construct();
46 // remove unsupported link attribute
47 unset($this->linkAttributes[array_search('params', $this->linkAttributes, true)]);
48 }
49
50 /**
51 * Checks if this is the handler for the given link
52 *
53 * The handler may store this information locally for later usage.
54 *
55 * @param array $linkParts Link parts as returned from TypoLinkCodecService
56 *
57 * @return bool
58 */
59 public function canHandleLink(array $linkParts)
60 {
61 if (!isset($linkParts['url']['url'])) {
62 return false;
63 }
64 $linkParts['url'] = $linkParts['url']['url'];
65 $this->linkParts = $linkParts;
66
67 return true;
68 }
69
70 /**
71 * Format the current link for HTML output
72 *
73 * @return string
74 */
75 public function formatCurrentUrl()
76 {
77 return $this->linkParts['url'];
78 }
79
80 /**
81 * Render the link handler
82 *
83 * @param ServerRequestInterface $request
84 *
85 * @return string
86 */
87 public function render(ServerRequestInterface $request)
88 {
89 GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Recordlist/UrlLinkHandler');
90
91 $this->view->assign('url', !empty($this->linkParts) ? $this->linkParts['url'] : 'http://');
92 return $this->view->render('Url');
93 }
94
95 /**
96 * @return string[] Array of body-tag attributes
97 */
98 public function getBodyTagAttributes()
99 {
100 return [];
101 }
102 }