Last active
February 16, 2023 16:37
-
-
Save geldmacher/e3ffdd7cb938b2da036763e002482780 to your computer and use it in GitHub Desktop.
Custom TYPO3 condition for checking if a specific extension is loaded (with custom Symfony ExpressionLanguage provider)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Vendor\Extension\ExpressionLanguage\FunctionsProvider; | |
use Symfony\Component\ExpressionLanguage\ExpressionFunction; | |
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; | |
/** | |
* ConditionFunctionsProvider | |
*/ | |
class ConditionFunctionsProvider implements ExpressionFunctionProviderInterface | |
{ | |
/** | |
* getFunctions | |
* | |
* @return ExpressionFunction[] | |
*/ | |
public function getFunctions(): array | |
{ | |
return [ | |
$this->getIsExtensionLoadedFunction(), | |
]; | |
} | |
/** | |
* getIsExtensionLoadedFunction | |
* | |
* [isExtensionLoaded('extensionKey')] | |
* lib.foo = TEXT | |
* lib.foo.value = bar | |
* [END] | |
* | |
* @return ExpressionFunction | |
*/ | |
protected function getIsExtensionLoadedFunction(): ExpressionFunction | |
{ | |
return new ExpressionFunction('isExtensionLoaded', static function () { | |
// Not implemented, we only use the evaluator | |
}, static function ($existingVariables, $extensionKey) { | |
return !empty($extensionKey) && ExtensionManagementUtility::isLoaded($extensionKey); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This file needs to be in the Configuration folder of your extension | |
return [ | |
'typoscript' => [ | |
Vendor\Extension\ExpressionLanguage\TyposcriptConditionProvider::class, | |
] | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace Vendor\Extension\ExpressionLanguage; | |
use Vendor\Extension\ExpressionLanguage\FunctionsProvider\ConditionFunctionsProvider; | |
use TYPO3\CMS\Core\ExpressionLanguage\AbstractProvider; | |
/** | |
* TyposcriptConditionProvider | |
*/ | |
class TyposcriptConditionProvider extends AbstractProvider | |
{ | |
public function __construct() | |
{ | |
$this->expressionLanguageProviders = [ | |
ConditionFunctionsProvider::class, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment