如何向 TYPO3 前端插件添加动作?
How can I add an action to a TYPO3 frontend plugin?
我正在使用 powermail
并使用 powermail_extended
对其进行扩展,并希望为前端插件正在执行的操作添加一个新操作。
扩展控制器不是问题:它是通过 XCLASS 重载的:
config.tx_extbase.objects {
In2code\Powermail\Controller\FormController.className = In2code\PowermailExtended\Controller\FormController
}
但是仅仅调用这个动作是不够的,因为prefences存储在后端的前端插件中。此前端插件在 powermail 的 ext_localconf.php
中配置。如何向此前端插件添加新操作?
(使用 TYPO3 7 LTS)
看完\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin
的代码其实比我想象的要简单:
将以下代码添加到 powermailextended 的 ext_localconf.php
中:
if (!function_exists('configure_plugin_add_action')) {
/**
* Add a action to a existing frontend plugin
*
* @param string $extensionName The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
* @param string $pluginName must be a unique id for your plugin in UpperCamelCase (the string length of the extension key added to the length of the plugin name should be less than 32!)
* @param string $controllerName Name of the Controller
* @param string $newAction Name of the action
* @param bool $cachable Can this action be cached?
*
* @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin
*/
function configure_plugin_add_action($extensionName, $pluginName, $controllerName, $newAction, $cachable = true) {
$delimiterPosition = strrpos($extensionName, '.');
if ($delimiterPosition !== false) {
$extensionName = substr($extensionName, $delimiterPosition + 1);
}
$extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
$newAction = trim($newAction);
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'][] = $newAction;
if (!$cachable) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['nonCacheableActions'][] = $newAction;
}
}
}
你可以这样使用它(也在ext_localconf.php
中):
configure_plugin_add_action('In2code.powermail', 'Pi1', 'Form', 'debug', false);
这应该适用于 Typo3 7-9(因为 configurePlugin
- 功能并没有真正改变)。
我正在使用 powermail
并使用 powermail_extended
对其进行扩展,并希望为前端插件正在执行的操作添加一个新操作。
扩展控制器不是问题:它是通过 XCLASS 重载的:
config.tx_extbase.objects {
In2code\Powermail\Controller\FormController.className = In2code\PowermailExtended\Controller\FormController
}
但是仅仅调用这个动作是不够的,因为prefences存储在后端的前端插件中。此前端插件在 powermail 的 ext_localconf.php
中配置。如何向此前端插件添加新操作?
(使用 TYPO3 7 LTS)
看完\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin
的代码其实比我想象的要简单:
将以下代码添加到 powermailextended 的 ext_localconf.php
中:
if (!function_exists('configure_plugin_add_action')) {
/**
* Add a action to a existing frontend plugin
*
* @param string $extensionName The extension name (in UpperCamelCase) or the extension key (in lower_underscore)
* @param string $pluginName must be a unique id for your plugin in UpperCamelCase (the string length of the extension key added to the length of the plugin name should be less than 32!)
* @param string $controllerName Name of the Controller
* @param string $newAction Name of the action
* @param bool $cachable Can this action be cached?
*
* @see \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin
*/
function configure_plugin_add_action($extensionName, $pluginName, $controllerName, $newAction, $cachable = true) {
$delimiterPosition = strrpos($extensionName, '.');
if ($delimiterPosition !== false) {
$extensionName = substr($extensionName, $delimiterPosition + 1);
}
$extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', $extensionName)));
$newAction = trim($newAction);
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['actions'][] = $newAction;
if (!$cachable) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['plugins'][$pluginName]['controllers'][$controllerName]['nonCacheableActions'][] = $newAction;
}
}
}
你可以这样使用它(也在ext_localconf.php
中):
configure_plugin_add_action('In2code.powermail', 'Pi1', 'Form', 'debug', false);
这应该适用于 Typo3 7-9(因为 configurePlugin
- 功能并没有真正改变)。