Skip to content

Instantly share code, notes, and snippets.

@fazzyx
Last active March 11, 2021 08:35
Show Gist options
  • Save fazzyx/7d14c3531bae03da77e31b2934419d2e to your computer and use it in GitHub Desktop.
Save fazzyx/7d14c3531bae03da77e31b2934419d2e to your computer and use it in GitHub Desktop.
TYPO3 PIDinRootline Custom Condition
####################################################################
# Configuration/ExpressionLanguage.php
####################################################################
<?php
return [
'typoscript' => [
\MEDIENGARAGE\CustomTheme\Condition\CustomTypoScriptConditionProvider::class,
]
];
####################################################################
# Classes/Condition/CustomTypoScriptConditionProvider.php
####################################################################
<?php
namespace MEDIENGARAGE\CustomTheme\Condition;
use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider;
class CustomTypoScriptConditionProvider extends AbstractProvider
{
public function __construct()
{
$this->expressionLanguageProviders = [
CustomConditionFunctionsProvider::class,
];
}
}
####################################################################
# Classes/Condition/CustomConditionFunctionsProvider.php
####################################################################
<?php
namespace MEDIENGARAGE\CustomTheme\Condition;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class CustomConditionFunctionsProvider implements ExpressionFunctionProviderInterface
{
public function getFunctions()
{
return [
$this->isPIDinRootline(),
];
}
/**
* Check if the current page id is inside the rootline uid list
* Example
* [PIDinRootlineService([13,37])]
*
* @return ExpressionFunction
*/
protected function isPIDinRootline(): ExpressionFunction
{
return new ExpressionFunction('PIDinRootlineService', function () {
// Not implemented, we only use the evaluator
}, function (array $arguments, array $uidList) {
$rootLineIds = $arguments['tree']->rootLineIds;
if($rootLineIds) {
// Not sure if array_intersect can be faster
foreach ($rootLineIds as $uid) {
if(in_array($uid,$uidList)) {
return true;
}
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment