diff --git a/Classes/ViewHelpers/Link/TelViewHelper.php b/Classes/ViewHelpers/Link/TelViewHelper.php new file mode 100644 index 00000000..46280d53 --- /dev/null +++ b/Classes/ViewHelpers/Link/TelViewHelper.php @@ -0,0 +1,70 @@ + + * {namespace t3kit=T3kit\themeT3kit\ViewHelpers} + * + * + * + * +46 (0) 40-01 ma 23 45 67 + * + */ +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(); + } +}