[TASK] Use Fluid for rendering LinkBrowsers
[Packages/TYPO3.CMS.git] / typo3 / sysext / recordlist / Classes / LinkHandler / MailLinkHandler.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 email links
23 */
24 class MailLinkHandler 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 attributes
47 foreach (['target', 'rel'] as $attribute) {
48 $position = array_search($attribute, $this->linkAttributes, true);
49 if ($position !== false) {
50 unset($this->linkAttributes[$position]);
51 }
52 }
53 }
54
55 /**
56 * Checks if this is the handler for the given link
57 *
58 * The handler may store this information locally for later usage.
59 *
60 * @param array $linkParts Link parts as returned from TypoLinkCodecService
61 *
62 * @return bool
63 */
64 public function canHandleLink(array $linkParts)
65 {
66 if ($linkParts['url'] && strpos($linkParts['url'], '@')) {
67 $this->linkParts = $linkParts;
68 return true;
69 }
70 return false;
71 }
72
73 /**
74 * Format the current link for HTML output
75 *
76 * @return string
77 */
78 public function formatCurrentUrl()
79 {
80 return $this->linkParts['url'];
81 }
82
83 /**
84 * Render the link handler
85 *
86 * @param ServerRequestInterface $request
87 *
88 * @return string
89 */
90 public function render(ServerRequestInterface $request)
91 {
92 GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Recordlist/MailLinkHandler');
93
94 $this->view->assign('email', !empty($this->linkParts) ? $this->linkParts['url'] : '');
95 return $this->view->render('Mail');
96 }
97
98 /**
99 * @return string[] Array of body-tag attributes
100 */
101 public function getBodyTagAttributes()
102 {
103 return [];
104 }
105 }