Skip to content

Instantly share code, notes, and snippets.

@htuscher
Created November 27, 2015 08:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save htuscher/331b9e67d38105f38eff to your computer and use it in GitHub Desktop.
Save htuscher/331b9e67d38105f38eff to your computer and use it in GitHub Desktop.
TYPO3 Command Controller TypoScript from different rootPid
<?php
namespace Onedrop\Solution\Command;
/*****************************************************************
* Copyright notice
*
* (c) 2015 Hans Höchtl <hhoechtl@1drop.de>
*
* 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 FluidTYPO3\Flux\Configuration\BackendConfigurationManager;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use TYPO3\CMS\Core\Log\LogManager;
/**
* Class AbstractCommandController
*
* @package Onedrop\Solution\Command
*/
abstract class AbstractCommandController extends CommandController {
/**
* @var BackendConfigurationManager
*/
protected $configurationManager;
/**
* @var array
*/
protected $settings;
/**
* @var string
*/
protected $_EXTKEY = 'solution';
/**
* @var int
*/
protected $_TS_PID = 1;
/**
* We add the functionality to have magic initialize methods in front of a command
*/
protected function mapRequestArgumentsToControllerArguments()
{
$this->initializeCommand();
$actionInitializationMethodName = 'initialize' . ucfirst($this->commandMethodName);
if (method_exists($this, $actionInitializationMethodName)) {
call_user_func(array($this, $actionInitializationMethodName));
}
parent::mapRequestArgumentsToControllerArguments();
}
/**
* initialize controller settings
*/
protected function initializeCommand() {
$this->configurationManager = $this->objectManager->get(BackendConfigurationManager::class);
/*
* This clears the first level typoscript cache, so we can reload the configuration from a different PID.
* The TS configuration has already been loaded from PID 1 at this point.
*/
$this->configurationManager->setConfiguration();
$this->configurationManager->setCurrentPageId($this->_TS_PID);
$this->settings = [];
$tsSettings = $this->configurationManager->getConfiguration($this->_EXTKEY);
if (isset($tsSettings['settings'])) {
$this->settings = $tsSettings['settings'];
}
$this->settings['_rootPid'] = $this->_TS_PID;
}
}
<?php
namespace Onedrop\Solution\Service;
/***************************************************************
* Copyright notice
*
* (c) 2015 Hans Höchtl <hhoechtl@1drop.de>
* 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 2 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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\Extbase\Configuration\ConfigurationManagerInterface;
class SomeService
{
/**
* @var array
*/
protected $settings;
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
*/
protected $configurationManager;
/**
* Initialize the indexer
*/
public function initializeObject()
{
$this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS,
'solution');
}
/**
* @param array $settings
*/
public function injectSettings(array $settings) {
$this->settings = $settings;
}
/**
* Do something fancy
*/
public function doSomething()
{
// TODO: add code here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment