Skip to content

Instantly share code, notes, and snippets.

@boettner-it
Last active March 9, 2018 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boettner-it/011737c010ca47f6ba92632fca1945df to your computer and use it in GitHub Desktop.
Save boettner-it/011737c010ca47f6ba92632fca1945df to your computer and use it in GitHub Desktop.
TYPO3 CommandController demo with injection of TS module settings
<?php
namespace My\Extension\Command;
/***************************************************************
*
* Copyright notice
*
* (c) 2017 Robert Böttner <robert@boettner.it>, boettner.it - Informationstechnologie
*
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Core\Localization\LocalizationFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/**
* Command Controller which handles Admin tasks
*/
class AdminCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController {
/**
* @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager
*/
protected $configurationManager;
/**
* @param \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $configurationManager
*/
public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $configurationManager) {
$this->configurationManager = $configurationManager;
}
/**
* @var \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
*/
protected $typoScriptService;
/**
* @param \TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService
*/
public function injectTypoScriptService(\TYPO3\CMS\Core\TypoScript\TypoScriptService $typoScriptService) {
$this->typoScriptService = $typoScriptService;
}
/**
* The TypoScript extension configuration
* @var array
*/
protected $settings = array();
/**
* action initialize
*
* @return void
*/
public function initialize() {
$tsSettings = $this->configurationManager->getTypoScriptSetup();
if (isset($tsSettings['module.']['tx_myextension_web_mypluginadmin.'])) {
$this->settings = $this->typoScriptService->convertTypoScriptArrayToPlainArray($tsSettings['module.']['tx_myextension_web_mypluginadmin.']);
}
}
/**
* my vommand
*
* @return void
*/
public function myNewCommand() {
$this->initialize();
// do stuff
}
/**
* @return TypoScriptFrontendController
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected function getTyposcriptFrontendController() {
return $GLOBALS['TSFE'];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment