[!!!][+FEATURE] Extbase (Settings): Persistence settings now reside in plugin.tx_extensionnname.persistence instead of tt_content.list.20. ... THIS IS A BREAKING CHANGE, but of a really new feature. Resolves #4177
[!!!]?\027[TASK] Extbase (Dispatcher): Renamed Tx_Extbase_Dispatcher::getSettings() to Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration(). THIS IS A BREAKING CHANGE, but of a non-public API. Related to #4177
[TASK] Extbase (Configuration): Cleaned up configuration manager and renamed methods there.
const DEFAULT_BACKEND_STORAGE_PID = 0;
/**
- * Storage for the settings, loaded by loadGlobalSettings()
+ * Storage for the settings, loaded by loadSettings()
*
* @var array
*/
*/
public function getSettings($extensionName) {
if (empty($this->settings[$extensionName])) {
- $this->loadGlobalSettings($extensionName);
+ $this->loadSettings($extensionName);
}
return $settings = $this->settings[$extensionName];
}
/**
- * Loads the Extbase core settings.
+ * Loads the settings defined in the specified extensions and merges them with
+ * those potentially existing in the global configuration folders.
*
- * The Extbase settings can be retrieved like any other setting through the
- * getSettings() method but need to be loaded separately because they are
- * needed way earlier in the bootstrap than the package's settings.
+ * The result is stored in the configuration manager's settings registry
+ * and can be retrieved with the getSettings() method.
*
- * @param array $configuration The current incoming extbase configuration
- * @param tslib_cObj $cObj The current Content Object
+ * @param string $extensionName
* @return void
+ * @see getSettings()
*/
- public function loadExtbaseSettings($configuration, $cObj) {
+ protected function loadSettings($extensionName) {
$settings = array();
- $settings['storagePid'] = $this->getDefaultStoragePageId($cObj);
- $settings['contentObjectData'] = $cObj->data;
+ foreach ($this->configurationSources as $configurationSource) {
+ $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionName));
+ }
+ $this->settings[$extensionName] = $settings;
+ }
+
+ /**
+ * Loads the Extbase Framework configuration.
+ *
+ * The Extbase framework configuration HAS TO be retrieved using this method, as they are come from different places than the normal settings.
+ * Framework configuration is, in contrast to normal settings, needed for the Extbase framework to operate correctly.
+ *
+ * @param array $pluginConfiguration The current incoming extbase configuration
+ * @param tslib_cObj $cObj The current Content Object
+ * @return array the Extbase framework configuration
+ */
+ public function getFrameworkConfiguration($pluginConfiguration, $cObj) {
+ $frameworkConfiguration = array();
+ $frameworkConfiguration['persistence']['storagePid'] = $this->getDefaultStoragePageId($cObj);
+ $frameworkConfiguration['contentObjectData'] = $cObj->data;
+
// TODO Support BE modules by parsing the file "manually" and all files EXT:myext/Configuration/Objects/setup.txt
$extbaseConfiguration = $GLOBALS['TSFE']->tmpl->setup['config.']['tx_extbase.'];
if (is_array($extbaseConfiguration)) {
$extbaseConfiguration = Tx_Extbase_Configuration_Manager::postProcessSettings($extbaseConfiguration);
- } else {
- $extbaseConfiguration = array();
+ $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, $extbaseConfiguration);
}
- $settings = t3lib_div::array_merge_recursive_overrule($settings, $extbaseConfiguration);
- $settings = t3lib_div::array_merge_recursive_overrule($settings, self::postProcessSettings($configuration));
- $this->settings['Extbase'] = $settings;
+ if (isset($pluginConfiguration['persistence'])) {
+ $pluginConfiguration = $this->resolveTyposcriptReference($pluginConfiguration, 'persistence');
+ }
+ $frameworkConfiguration = t3lib_div::array_merge_recursive_overrule($frameworkConfiguration, self::postProcessSettings($pluginConfiguration));
+ return $frameworkConfiguration;
+ }
+
+ /**
+ * Resolves the TypoScript reference for $pluginConfiguration[$setting].
+ * In case the setting is a string and starts with "<", we know that this is a TypoScript reference which
+ * needs to be resolved separately.
+ *
+ * @param array $pluginConfiguration The whole plugin configuration
+ * @param string $setting The key inside the $pluginConfiguration to check
+ * @return array The modified plugin configuration
+ */
+ protected function resolveTyposcriptReference($pluginConfiguration, $setting) {
+ if (is_string($pluginConfiguration[$setting]) && substr($pluginConfiguration[$setting], 0, 1) === '<') {
+ $typoScriptParser = t3lib_div::makeInstance('t3lib_TSparser');
+ $key = trim(substr($pluginConfiguration[$setting], 1));
+ list(, $newValue) = $typoScriptParser->getVal($key,$GLOBALS['TSFE']->tmpl->setup);
+
+ unset($pluginConfiguration[$setting]);
+ $pluginConfiguration[$setting . '.'] = $newValue;
+ }
+ return $pluginConfiguration;
}
/**
return self::DEFAULT_BACKEND_STORAGE_PID;
}
- /**
- * Loads the settings defined in the specified extensions and merges them with
- * those potentially existing in the global configuration folders.
- *
- * The result is stored in the configuration manager's settings registry
- * and can be retrieved with the getSettings() method.
- *
- * @param string $extensionName
- * @return void
- * @see getSettings()
- */
- protected function loadGlobalSettings($extensionName) {
- $settings = array();
- foreach ($this->configurationSources as $configurationSource) {
- $settings = t3lib_div::array_merge_recursive_overrule($settings, $configurationSource->load($extensionName));
- }
- $this->settings[$extensionName] = $settings;
- }
-
/**
* Removes all trailing dots recursively from TS settings array
* TODO Explain why we remove the dots.
*/
public function load($extensionName) {
// TODO Needs a FE (does actually not work with BE or CLI)
- $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionName) . '.'];
+ $settings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_' . strtolower($extensionName) . '.']['settings.'];
if (is_array($settings)) {
$settings = Tx_Extbase_Configuration_Manager::postProcessSettings($settings);
} else {
private static $persistenceManager;
/**
- * The settings for the Extbase framework
+ * The configuration for the Extbase framework
* @var array
*/
- private static $settings;
+ private static $extbaseFrameworkConfiguration;
/**
* @return string $content The processed content
*/
public function dispatch($content, $configuration) {
-
// FIXME Remove the next lines. These are only there to generate the ext_autoload.php file
//$extutil = new Tx_Extbase_Utility_Extension;
//$extutil->createAutoloadRegistryForExtension('extbase', t3lib_extMgm::extPath('extbase'));
t3lib_div::sysLog('Extbase was not able to dispatch the request. No configuration.', 'extbase', t3lib_div::SYSLOG_SEVERITY_ERROR);
return $content;
}
- $this->initializeConfiguration($configuration);
+ $this->initializeConfigurationManagerAndFrameworkConfiguration($configuration);
$requestBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_RequestBuilder');
$request = $requestBuilder->initialize($configuration);
$request = $requestBuilder->build();
$response = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Response');
- $persistenceManager = self::getPersistenceManager($configuration);
+ $persistenceManager = self::getPersistenceManager();
$dispatchLoopCount = 0;
while (!$request->isDispatched()) {
* @param $configuration The current incoming configuration
* @return void
*/
- protected function initializeConfiguration($configuration) {
+ protected function initializeConfigurationManagerAndFrameworkConfiguration($configuration) {
$configurationSources = array();
$configurationSources[] = t3lib_div::makeInstance('Tx_Extbase_Configuration_Source_TypoScriptSource');
if (!empty($this->cObj->data['pi_flexform'])) {
$configurationSources[] = $configurationSource;
}
$this->configurationManager = t3lib_div::makeInstance('Tx_Extbase_Configuration_Manager', $configurationSources);
- $this->configurationManager->loadExtbaseSettings($configuration, $this->cObj);
- self::$settings = $this->configurationManager->getSettings('Extbase');
+ self::$extbaseFrameworkConfiguration = $this->configurationManager->getFrameworkConfiguration($configuration, $this->cObj);
}
/**
/**
* This function prepares and returns the Persistance Manager
*
- * @param array $configuration The given configuration
* @return Tx_Extbase_Persistence_Manager A (singleton) instance of the Persistence Manager
*/
- public static function getPersistenceManager(array $configuration = array()) {
+ public static function getPersistenceManager() {
if (self::$persistenceManager === NULL) {
$queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory'); // singleton
$storageBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Storage_Typo3DbBackend', $GLOBALS['TYPO3_DB']); // singleton
$storageBackend->injectDataMapper($dataMapper);
- if (isset($configuration['enableAutomaticCacheClearing']) && $configuration['enableAutomaticCacheClearing'] === '1') {
- $storageBackend->setAutomaticCacheClearing(TRUE);
- } else {
- $storageBackend->setAutomaticCacheClearing(FALSE);
- }
-
+
$persistenceSession = t3lib_div::makeInstance('Tx_Extbase_Persistence_Session'); // singleton
$persistenceBackend = t3lib_div::makeInstance('Tx_Extbase_Persistence_Backend', $persistenceSession, $storageBackend); // singleton
*
* @return array The settings
*/
- public static function getSettings() {
- return self::$settings;
+ public static function getExtbaseFrameworkConfiguration() {
+ return self::$extbaseFrameworkConfiguration;
}
-
/**
* Loads php files containing classes or interfaces found in the classes directory of
* an extension.
*/
protected function determineStoragePageIdForNewRecord(Tx_Extbase_DomainObject_DomainObjectInterface $object) {
$className = get_class($object);
- $extbaseSettings = Tx_Extbase_Dispatcher::getSettings();
+ $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
- if (isset($extbaseSettings['classes'][$className]) && !empty($extbaseSettings['classes'][$className]['newRecordStoragePid'])) {
- return (int)$extbaseSettings['classes'][$className]['newRecordStoragePid'];
+ if (isset($extbaseSettings['persistence']['classes'][$className]) && !empty($extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'])) {
+ return (int)$extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'];
} else {
- $storagePidList = t3lib_div::intExplode(',', $extbaseSettings['storagePid']);
+ $storagePidList = t3lib_div::intExplode(',', $extbaseSettings['persistence']['storagePid']);
return (int) $storagePidList[0];
}
}
if (empty($this->dataMaps[$className])) {
// FIXME This is a costy for table name aliases -> implement a DataMapBuilder (knowing the aliases defined in $TCA)
$mapping = array();
- $extbaseSettings = Tx_Extbase_Dispatcher::getSettings();
- if (isset($extbaseSettings['classes'][$className]) && !empty($extbaseSettings['classes'][$className]['mapping']['tableName'])) {
- $tableName = $extbaseSettings['classes'][$className]['mapping']['tableName'];
+ $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+ if (isset($extbaseSettings['persistence']['classes'][$className]) && !empty($extbaseSettings['persistence']['classes'][$className]['mapping']['tableName'])) {
+ $tableName = $extbaseSettings['persistence']['classes'][$className]['mapping']['tableName'];
} else {
foreach (class_parents($className) as $parentClassName) {
- if (isset($extbaseSettings['classes'][$parentClassName]) && !empty($extbaseSettings['classes'][$parentClassName]['mapping']['tableName'])) {
- $tableName = $extbaseSettings['classes'][$parentClassName]['mapping']['tableName'];
+ if (isset($extbaseSettings['persistence']['classes'][$parentClassName]) && !empty($extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['tableName'])) {
+ $tableName = $extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['tableName'];
break;
}
// TODO throw Exception
}
}
- if (is_array($extbaseSettings['classes'][$parentClassName]['mapping']['columns'])) {
- $mapping = $extbaseSettings['classes'][$parentClassName]['mapping']['columns'];
+ if (is_array($extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['columns'])) {
+ $mapping = $extbaseSettings['persistence']['classes'][$parentClassName]['mapping']['columns'];
}
$dataMap = new Tx_Extbase_Persistence_Mapper_DataMap($className, $tableName, $mapping);
*/
protected $pageSelectObject;
- /**
- * TRUE if automatic cache clearing in TCEMAIN should be done on insert/update/delete, FALSE otherwise.
- *
- * @var boolean
- */
- protected $automaticCacheClearing = FALSE;
-
/**
* Constructs this Storage Backend instance
*
public function __construct($databaseHandle) {
$this->databaseHandle = $databaseHandle;
}
-
+
/**
+
* Injects the DataMapper to map nodes to objects
*
* @param Tx_Extbase_Persistence_Mapper_DataMapper $dataMapper
$this->dataMapper = $dataMapper;
}
- /**
- * Set the automatic cache clearing flag.
- * If TRUE, then inserted/updated/deleted records trigger a TCEMAIN cache clearing.
- *
- * @param $automaticCacheClearing boolean if TRUE, enables automatic cache clearing
- * @return void
-
- */
- public function setAutomaticCacheClearing($automaticCacheClearing) {
- $this->automaticCacheClearing = (boolean)$automaticCacheClearing;
- }
-
/**
* Adds a row to the storage
*
$sql['orderings'] = array();
$sql['limit'] = array();
$tuples = array();
-
+
$source = $query->getSource();
$this->parseSource($query, $source, $sql, $parameters);
-
+
$statement = 'SELECT ' . implode(',', $sql['fields']) . ' FROM ' . implode(' ', $sql['tables']);
$this->parseConstraint($query->getConstraint(), $source, $sql, $parameters, $query->getBoundVariableValues());
$statement .= ' LIMIT ' . $sql['limit'];
}
}
-
+
$this->replacePlaceholders($statement, $parameters);
return $statement;
protected function addPageIdStatement($tableName, array &$sql) {
// TODO We have to call the appropriate API method if we are in TYPO3BE mode
if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) {
- $extbaseSettings = Tx_Extbase_Dispatcher::getSettings();
- $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', t3lib_div::intExplode(',', $extbaseSettings['storagePid'])) . ')';
+ $extbaseFrameworkConfiguration = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+ $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', t3lib_div::intExplode(',', $extbaseFrameworkConfiguration['persistence']['storagePid'])) . ')';
}
}
* @return void
*/
protected function clearPageCache($tableName, $uid) {
- if ($this->automaticCacheClearing !== TRUE) return;
+ $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
+ if (isset($extbaseSettings['persistence']['enableAutomaticCacheClearing']) && $extbaseSettings['persistence']['enableAutomaticCacheClearing'] === '1') {
+ } else {
+ // if disabled, return
+ return;
+ }
$pageCache = $GLOBALS['typo3CacheManager']->getCache('cache_pages');
$pageSectionCache = $GLOBALS['typo3CacheManager']->getCache('cache_pagesection');
* (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
* All rights reserved
*
-* This class is a backport of the corresponding class of FLOW3.
+* This class is a backport of the corresponding class of FLOW3.
* All credits go to the v5 team.
*
* This script is part of the TYPO3 project. The TYPO3 project is
/**
* Add auto-generated TypoScript to configure the Extbase Dispatcher.
*
- * When adding a frontend plugin you will have to add both an entry to the TCA definition
+ * When adding a frontend plugin you will have to add both an entry to the TCA definition
* of tt_content table AND to the TypoScript template which must initiate the rendering.
- * Since the static template with uid 43 is the "content.default" and practically always
- * used for rendering the content elements it's very useful to have this function automatically
+ * Since the static template with uid 43 is the "content.default" and practically always
+ * used for rendering the content elements it's very useful to have this function automatically
* adding the necessary TypoScript for calling the appropriate controller and action of your plugin.
* It will also work for the extension "css_styled_content"
* FOR USE IN ext_localconf.php FILES
$nonCachableActions = array();
if (!empty($nonCachableControllerActions[$defaultController])) {
$nonCachableActions = t3lib_div::trimExplode(',', $nonCachableControllerActions[$defaultController]);
- }
+ }
$cachableActions = array_diff(t3lib_div::trimExplode(',', $controllerActions[$defaultController]), $nonCachableActions);
$contentObjectType = in_array($defaultAction, $nonCachableActions) ? 'USER_INT' : 'USER';
}
}
+ $pluginTemplate = trim('plugin.tx_' . strtolower($extensionName) . '.settings {
+}
+plugin.tx_' . strtolower($extensionName) . '.persistence {
+ enableAutomaticCacheClearing = 1
+ # storagePid
+ classes {
+ }
+}');
+ t3lib_extMgm::addTypoScript($extensionName, 'setup', '
+# Setting ' . $extensionName . ' plugin TypoScript
+' . $pluginTemplate);
+
$pluginContent = trim('
tt_content.list.20.' . $pluginSignature . ' = ' . $contentObjectType . '
tt_content.list.20.' . $pluginSignature . ' {
userFunc = tx_extbase_dispatcher->dispatch
pluginName = ' . $pluginName . '
extensionName = ' . $extensionName . '
- enableAutomaticCacheClearing = 1' .
- $controller .
- $action .
+ ' . $controller .
+ $action .
$switchableControllerActions . '
+
+ persistence =< plugin.tx_' . strtolower($extensionName) . '.persistence
}
' . $conditions);
}
$extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
$pluginSignature = strtolower($extensionName) . '_' . strtolower($pluginName);
-
+
t3lib_extMgm::addPlugin(array($pluginTitle, $pluginSignature), 'list_type');
}
}
}
}
- classes {
+ persistence.classes {
Tx_Extbase_Domain_Model_FrontendUser {
mapping {
tableName = fe_users