/
TitleTagViewHelper.php
60 lines (54 loc) · 1.91 KB
/
TitleTagViewHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/*
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace GeorgRinger\News\ViewHelpers;
use GeorgRinger\News\Seo\NewsTitleProvider;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
/**
* ViewHelper to render the page title
*
* # Example: Basic Example
* # Description: Render the content of the VH as page title
* <code>
* <n:titleTag>{newsItem.title}</n:titleTag>
* </code>
* <output>
* <title>TYPO3 is awesome</title>
* </output>
*/
class TitleTagViewHelper extends AbstractViewHelper implements ViewHelperInterface
{
use CompileWithRenderStatic;
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
): void {
// Skip if current record is part of tt_content CType shortcut
if (!empty($GLOBALS['TSFE']->recordRegister)
&& is_array($GLOBALS['TSFE']->recordRegister)
&& strpos(array_keys($GLOBALS['TSFE']->recordRegister)[0], 'tt_content:') !== false
&& !empty($GLOBALS['TSFE']->currentRecord)
&& strpos($GLOBALS['TSFE']->currentRecord, 'tx_news_domain_model_news:') !== false
) {
return;
}
$content = trim($renderChildrenClosure());
if (!empty($content)) {
GeneralUtility::makeInstance(NewsTitleProvider::class)->setTitle($content);
}
}
}