use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\DataProcessing\LanguageMenuProcessor;
/**
public $cObj;
/**
+ * @var TypoScriptFrontendController
+ */
+ protected $typoScriptFrontendController;
+
+ /**
* HreflangGenerator constructor
*
- * @param ContentObjectRenderer $cObj
+ * @param ContentObjectRenderer|null $cObj
+ * @param TypoScriptFrontendController|null $typoScriptFrontendController
*/
- public function __construct(ContentObjectRenderer $cObj = null)
+ public function __construct(ContentObjectRenderer $cObj = null, TypoScriptFrontendController $typoScriptFrontendController = null)
{
if ($cObj === null) {
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
}
+ if ($typoScriptFrontendController === null) {
+ $typoScriptFrontendController = $this->getTypoScriptFrontendController();
+ }
+
$this->cObj = $cObj;
+ $this->typoScriptFrontendController = $typoScriptFrontendController;
}
public function generate(): string
{
$hreflangs = '';
+ if ((int)$this->typoScriptFrontendController->page['no_index'] === 1) {
+ return '';
+ }
+
if ($GLOBALS['TYPO3_REQUEST']->getAttribute('site') instanceof Site) {
$languageMenu = GeneralUtility::makeInstance(LanguageMenuProcessor::class);
$languages = $languageMenu->process($this->cObj, [], [], []);
{
return $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
}
+
+ /**
+ * @return TypoScriptFrontendController
+ */
+ protected function getTypoScriptFrontendController(): TypoScriptFrontendController
+ {
+ return $GLOBALS['TSFE'];
+ }
}
'uid: 5 without canonical_link AND without content_from_pid set' => [5, '<link rel="canonical" href="http://localhost/dummy-1-2-5"/>' . chr(10)],
'uid: 6 without canonical_link AND content_from_pid = 7 (but target page is deleted)' => [6, '<link rel="canonical" href="http://localhost/dummy-1-2-6"/>' . chr(10)],
'uid: 8 without canonical_link AND content_from_pid = 9 (but target page is hidden)' => [8, '<link rel="canonical" href="http://localhost/dummy-1-2-8"/>' . chr(10)],
+ 'uid: 10 no index' => [10, ''],
];
}
*/
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Seo\HrefLang\HrefLangGenerator;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
$subject = $this->getAccessibleMock(
HrefLangGenerator::class,
['getSiteLanguage'],
- [$this->prophesize(ContentObjectRenderer::class)->reveal()],
+ [
+ $this->prophesize(ContentObjectRenderer::class)->reveal(),
+ $this->prophesize(TypoScriptFrontendController::class)->reveal()
+ ],
'',
true
);