How can I add an action to a TYPO3 frontend plugin?

倖福魔咒の 提交于 2019-12-11 19:53:20

问题


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

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
}

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?

(Using TYPO3 7 LTS)


回答1:


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

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;
        }
    }

}

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

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

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



来源:https://stackoverflow.com/questions/48743890/how-can-i-add-an-action-to-a-typo3-frontend-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!