-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd49800
commit fcf41fd
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
namespace T3kit\themeT3kit\ViewHelpers\Link; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
/** | ||
* Tel link view helper. | ||
* Generates an tel link | ||
* | ||
* = Examples | ||
* | ||
* <code title="basic tel link"> | ||
* {namespace t3kit=T3kit\themeT3kit\ViewHelpers} | ||
* <t3kit:link.tel tel="+46 (0) 40-01 ma 23 45 67" /> | ||
* </code> | ||
* <output> | ||
* <a href="tel:+464001234567">+46 (0) 40-01 ma 23 45 67</a> | ||
* </output> | ||
*/ | ||
class TelViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $tagName = 'a'; | ||
|
||
/** | ||
* Arguments initialization | ||
*/ | ||
public function initializeArguments() | ||
{ | ||
parent::initializeArguments(); | ||
$this->registerArgument('tel', 'string', 'The telephone number to be turned into a link', true); | ||
$this->registerUniversalTagAttributes(); | ||
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor'); | ||
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document'); | ||
} | ||
|
||
/** | ||
* @return string Rendered tel link | ||
*/ | ||
public function render() | ||
{ | ||
$tel = $this->arguments['tel']; | ||
|
||
$linkHref = 'tel:' . preg_replace('/\(0\)|\s|[^\d+]/', '', $tel); | ||
$linkText = htmlspecialchars($tel); | ||
$escapeSpecialCharacters = true; | ||
|
||
$tagContent = $this->renderChildren(); | ||
if ($tagContent !== null) { | ||
$linkText = $tagContent; | ||
} | ||
$this->tag->setContent($linkText); | ||
$this->tag->addAttribute('href', $linkHref, $escapeSpecialCharacters); | ||
$this->tag->forceClosingTag(true); | ||
return $this->tag->render(); | ||
} | ||
} |