|
<?php |
|
declare(strict_types=1); |
|
|
|
namespace Vendor\Extension\ViewHelpers; |
|
|
|
use GeorgRinger\News\Domain\Repository\NewsRepository; |
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
|
use TYPO3\CMS\Core\Context\Context; |
|
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException; |
|
use TYPO3\CMS\Core\Context\LanguageAspect; |
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
|
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface; |
|
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper; |
|
|
|
class TranslationAvailableViewHelper extends AbstractViewHelper |
|
{ |
|
public function initializeArguments(): void |
|
{ |
|
$this->registerArgument('languageId', 'int', 'Lanuage ID', true); |
|
} |
|
|
|
/** |
|
* Returns true if the current view is a news detail view |
|
* and there's a translation available for the current news. |
|
* |
|
* @param array $arguments |
|
* @param \Closure $renderChildrenClosure |
|
* @param RenderingContextInterface $renderingContext |
|
* @return bool |
|
*/ |
|
public static function renderStatic( |
|
array $arguments, |
|
\Closure $renderChildrenClosure, |
|
RenderingContextInterface $renderingContext |
|
): bool { |
|
if (isset($GLOBALS['_GET']['tx_news_pi1']['news'], $GLOBALS['_GET']['tx_news_pi1']['action']) && |
|
$GLOBALS['_GET']['tx_news_pi1']['action'] === 'detail') { |
|
|
|
/** @var QueryBuilder $queryBuilder */ |
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) |
|
->getQueryBuilderForTable('tx_news_domain_model_news'); |
|
|
|
// Default language |
|
if ((int)$arguments['languageId'] === 0) { |
|
return (bool)$queryBuilder->count('uid') |
|
->from('tx_news_domain_model_news') |
|
->where( |
|
$queryBuilder->expr()->eq('uid', (int)$GLOBALS['_GET']['tx_news_pi1']['news']) |
|
) |
|
->execute() |
|
->fetchColumn(); |
|
} |
|
|
|
return (bool)$queryBuilder->count('uid') |
|
->from('tx_news_domain_model_news') |
|
->where( |
|
$queryBuilder->expr()->eq('l10n_parent', (int)$GLOBALS['_GET']['tx_news_pi1']['news']) |
|
) |
|
->execute() |
|
->fetchColumn(); |
|
} |
|
|
|
// Something else than a news record, show the language menu |
|
return true; |
|
} |
|
|
|
/** |
|
* @return TypoScriptFrontendController |
|
*/ |
|
protected static function getTypoScriptFrontendController(): TypoScriptFrontendController |
|
{ |
|
return $GLOBALS['TSFE']; |
|
} |
|
} |