Damit die Plugin-Settings einer Extbase Extension auch im CommandController (Backend / CLI Kontext) verfügbar sind, muss auf folgendes geachtet werden:
1. die plugin Settings in module kopieren:
1 |
module.tx_foo < plugin.tx_foo |
2. In der ext_localconf.php die constants.txt und setup.txt mittels ExtensionManagementUtility::addTypoScript includen:
1 2 3 4 5 6 7 8 9 10 11 12 |
if(TYPO3_MODE === 'BE') { // Constants \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY,'constants',' <INCLUDE_TYPOSCRIPT: source="FILE:EXT:'. $_EXTKEY .'/Configuration/TypoScript/constants.txt">'); // Setup \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScript($_EXTKEY,'setup',' <INCLUDE_TYPOSCRIPT: source="FILE:EXT:'. $_EXTKEY .'/Configuration/TypoScript/setup.txt">'); // CommandController registrieren $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Vendor\Foo\Command\FooCommandController'; } |
damit wird sichergestellt, dass das Setup unter allen Umständen geladen wird. In der Regel bindet man das Extension Setup ja in einem Frontend TS Template ein; somit wird es im Backend / CLI Kontext nicht geladen (zumindest dann nicht, wenn man es nicht im Root Template eingebunden hat sondern z.B. in einem Extension Template auf einer Unterseite).
3) im Controller die Settings über den ConfigurationManager reinholen:
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 |
<?php namespace Vendor\Foo\Command; class FooCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController { /** * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface * @inject */ protected $configurationManager; /** * @var array */ protected $settings = array(); /** * Settings aus dem CibfigurationManager ziehen und zuweisen */ public function initialize() { $settings = $this->configurationManager->getConfiguration( \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS ); $this->settings = $settings; } /** * die eigentliche Command Methode -> initialize() aufrufen */ public function fooCommand() { $this->initialize(); // $foo = $this->settings['bar']; // Command Logik ... } } |
Danke für den Artikel, gut beschrieben! Man kann auch die Funktion „initializeAction“ nutzen und sich damit den Aufruf „$this->initialize()“ sparen. So mach ich es immer…
Halleluja. Schönes, kleines Tutorial! Besonders gefällt mir das Laden der constant.txt und setup.txt zentral in der Extension, anstatt es an 2-3 anderen Stellen zu machen.. das ist wirklich elegant gelöst. Das habe ich so bisher noch nirgendwo gesehen. Danke!