[TASK] Allow multiple extractor services with the same priority
[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 * @internal This class is a specific LinkHandler implementation and is not part of the TYPO3's Core API.
24 */
25 class MailLinkHandler extends AbstractLinkHandler implements LinkHandlerInterface
26 {
27 /**
28 * Parts of the current link
29 *
30 * @var array
31 */
32 protected $linkParts = [];
33
34 /**
35 * We don't support updates since there is no difference to simply set the link again.
36 *
37 * @var bool
38 */
39 protected $updateSupported = false;
40
41 /**
42 * Constructor
43 */
44 public function __construct()
45 {
46 parent::__construct();
47 // remove unsupported link attributes
48 foreach (['target', 'rel'] as $attribute) {
49 $position = array_search($attribute, $this->linkAttributes, true);
50 if ($position !== false) {
51 unset($this->linkAttributes[$position]);
52 }
53 }
54 }
55
56 /**
57 * Checks if this is the handler for the given link
58 *
59 * The handler may store this information locally for later usage.
60 *
61 * @param array $linkParts Link parts as returned from TypoLinkCodecService
62 *
63 * @return bool
64 */
65 public function canHandleLink(array $linkParts)
66 {
67 if (isset($linkParts['url']['email'])) {
68 $this->linkParts = $linkParts;
69 return true;
70 }
71 return false;
72 }
73
74 /**
75 * Format the current link for HTML output
76 *
77 * @return string
78 */
79 public function formatCurrentUrl()
80 {
81 return $this->linkParts['url']['email'];
82 }
83
84 /**
85 * Render the link handler
86 *
87 * @param ServerRequestInterface $request
88 *
89 * @return string
90 */
91 public function render(ServerRequestInterface $request)
92 {
93 GeneralUtility::makeInstance(PageRenderer::class)->loadRequireJsModule('TYPO3/CMS/Recordlist/MailLinkHandler');
94
95 $this->view->assign('email', !empty($this->linkParts) ? $this->linkParts['url']['email'] : '');
96 return $this->view->render('Mail');
97 }
98
99 /**
100 * @return string[] Array of body-tag attributes
101 */
102 public function getBodyTagAttributes()
103 {
104 return [];
105 }
106 }