如何为TYPO3前端插件添加动作? [英] How can I add an action to a TYPO3 frontend plugin?

查看:87
本文介绍了如何为TYPO3前端插件添加动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用powermail并将其扩展为powermail_extended,并想对前端插件的操作添加新的操作.

I am using powermail and extending it with powermail_extended and want to add a new action to what the frontend plugin is doing.

扩展控制器不是问题:它通过XCLASS重载:

Extending the Controller is not the issue: It is overloaded via XCLASS:

config.tx_extbase.objects {
  In2code\Powermail\Controller\FormController.className = In2code\PowermailExtended\Controller\FormController
}

但是仅调用此操作是不够的,因为这些偏好存储在后端的前端插件中.在Powermail的ext_localconf.php中配置了此前端插件.如何向该前端插件添加新动作?

But simply calling this action is not enough, because the prefences are stored in the frontend plugin in the backend. This frontend plugin is configured in ext_localconf.php of powermail. How can a add a new action to this frontend plugin?

(使用TYPO3 7 LTS)

(Using TYPO3 7 LTS)

推荐答案

阅读\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin的代码后,实际上比我想象的要容易:

After reading the code of \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin it is actually easier than I thought:

将以下代码添加到扩展的powermail的ext_localconf.php中:

Add the following code to ext_localconf.php of powermailextended:

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中):

You can use it like this (also in ext_localconf.php):

configure_plugin_add_action('In2code.powermail', 'Pi1', 'Form', 'debug', false);

这应该在Typo3 7-9中有效(因为configurePlugin-功能并没有真正改变).

This should work in Typo3 7-9 (as the configurePlugin-Function didn't really change).

这篇关于如何为TYPO3前端插件添加动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆