Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Documentation / t3lib_extMgm_addExtbasePlugin.diff
1 --- typo3_src-trunk.orig/t3lib/class.t3lib_extmgm.php 2009-04-16 17:41:01.000000000 +0200
2 +++ typo3_src-trunk/t3lib/class.t3lib_extmgm.php 2009-04-16 17:32:25.000000000 +0200
3 @@ -994,7 +994,7 @@
4
5 // General plugin:
6 $pluginContent = trim('
7 -plugin.'.$cN.$prefix.' = USER' . ($cached ? '' : '_INT') . '
8 +plugin.'.$cN.$prefix.' = ' . ($cached ? 'USER' : 'USER_INT') . '
9 plugin.'.$cN.$prefix.' {
10 includeLibs = '.$TYPO3_LOADED_EXT[$key]['siteRelPath'].$classFile.'
11 userFunc = '.$cN.$prefix.'->main
12 @@ -1042,6 +1042,121 @@
13 }
14
15 /**
16 + * Add an Extbase PlugIn to TypoScript
17 + *
18 + * When adding a frontend plugin you will have to add both an entry to the TCA definition
19 + * of tt_content table AND to the TypoScript template which must initiate the rendering.
20 + * Since the static template with uid 43 is the "content.default" and practically always
21 + * used for rendering the content elements it's very useful to have this function automatically
22 + * adding the necessary TypoScript for calling your plugin. It will also work for the
23 + * extension "css_styled_content"
24 + * FOR USE IN ext_locallang.php FILES
25 + * Usage: 2
26 + *
27 + * @param string $pluginKey must be a unique id for your plugin in lower_underscore (the string length of the extension key added to the length of the plugin key should be less than 32!)
28 + * @param string $extensionKEy is the extension key in lower_underscore (available in $_EXTKEY)
29 + * @param string $controllerActions is an array of allowed combinations of controller and action stored in an array (controller name as key and a comma separated list of action names as value)
30 + * @param string $nonCachableControllerActions is an optional array of controller name and action names which should not be cached (array as defined in $controllerActions)
31 + * @param string $defaultControllerAction is an optional array controller name (as array key) and action name (as array value) that should be called as default
32 + * @return void
33 + */
34 + // TODO tt_content field 'list_type' should be enabled to hold at least 128 characters
35 + public static function addExtbasePlugin($pluginKey, $extensionKey, array $controllerActions = array(), array $nonCachableControllerActions = array(), $defaultControllerAction = NULL) {
36 + if (empty($pluginKey)) {
37 + throw new InvalidArgumentException('The plugin key must not be empty', 1239891987);
38 + }
39 + if (empty($extensionKey) || preg_match('/[^_a-z0-9]/', $extensionKey) === 1) {
40 + throw new InvalidArgumentException('The extension key was invalid (must not be empty and must match [_a-z0-9])', 1239891989);
41 + }
42 + $extensionName = str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($extensionKey))));
43 +
44 + $controllerCounter = 1;
45 + $hasMultipleActionsCounter = 0;
46 + $controllers = '';
47 + foreach ($controllerActions as $controller => $actionsList) {
48 + $controllers .= '
49 + ' . $controllerCounter . '.controller = ' . $controller . '
50 + ' . $controllerCounter . '.actions = ' . $actionsList;
51 + $controllerCounter++;
52 + if (strpos($actionsList, ',') !== FALSE) {
53 + $hasMultipleActionsCounter++;
54 + }
55 + }
56 + if ($hasMultipleActionsCounter > 0) {
57 + $switchableControllerActions = '
58 + switchableControllerActions {' . $controllers . '
59 + }';
60 + } else {
61 + $switchableControllerActions = '';
62 + }
63 +
64 + reset($controllerActions);
65 + if ($defaultControllerAction !== NULL) {
66 + $defaultController = key($defaultControllerAction);
67 + $controller = '
68 + controller = ' . $defaultController;
69 + $defaultAction = current($defaultControllerAction);
70 + $action = '
71 + action = ' . $defaultAction;
72 + } elseif (!empty($controllerActions)) {
73 + $defaultController = key($controllerActions);
74 + $controller = '
75 + controller = ' . $defaultController;
76 + $defaultAction = array_shift(t3lib_div::trimExplode(',', current($controllerActions)));
77 + $action = '
78 + action = ' . $defaultAction;
79 + } else {
80 + $defaultController = NULL;
81 + $controller = '';
82 + $defaultAction = NULL;
83 + $action = '';
84 + }
85 +
86 + if (!empty($nonCachableControllerActions[$defaultController])) {
87 + $nonCachableActions = t3lib_div::trimExplode(',', $nonCachableControllerActions[$defaultController]);
88 + } else {
89 + $nonCachableActions = array();
90 + }
91 + $cachableActions = array_diff(t3lib_div::trimExplode(',', $controllerActions[$defaultController]), $nonCachableActions);
92 + $contentObjectType = in_array($defaultAction, $nonCachableActions) ? 'USER_INT' : 'USER';
93 +
94 + $conditions = '';
95 + foreach ($controllerActions as $controllerName => $actionsList) {
96 + if (!empty($nonCachableControllerActions[$controllerName])) {
97 + $nonCachableActions = t3lib_div::trimExplode(',', $nonCachableControllerActions[$controllerName]);
98 + $cachableActions = array_diff(t3lib_div::trimExplode(',', $controllerActions[$controllerName]), $nonCachableActions);
99 + if ((($contentObjectType === 'USER') && (count($nonCachableActions) !== 0)) || (($contentObjectType === 'USER_INT') && (count($cachableActions) !== 0))) {
100 + $conditions .= '
101 +[globalString: GP = tx_' . strtolower($extensionName) . '_' . strtolower($pluginKey) . '|controller = ' . $controllerName . '] && [globalString: GP = tx_' . strtolower($extensionName) . '_' . strtolower($pluginKey) . '|action = /' . implode('|', $contentObjectType === 'USER' ? $nonCachableActions : $cachableActions) . '/]
102 +tt_content.list.20.' . strtolower($extensionKey) . '_' . strtolower($pluginKey) . ' = ' . ($contentObjectType === 'USER' ? 'USER_INT' : 'USER') . '
103 +[global]
104 +';
105 + }
106 + }
107 + }
108 +
109 + $pluginContent = trim('
110 +includeLibs.tx_extbase_dispatcher = EXT:extbase/class.tx_extbase_dispatcher.php
111 +
112 +tt_content.list.20.' . strtolower($extensionKey) . '_' . strtolower($pluginKey) . ' = ' . $contentObjectType . '
113 +tt_content.list.20.' . strtolower($extensionKey) . '_' . strtolower($pluginKey) . ' {
114 + userFunc = tx_extbase_dispatcher->dispatch
115 + pluginKey = ' . $pluginKey . '
116 + extensionName = ' . $extensionName .
117 + $controller .
118 + $action .
119 + $switchableControllerActions . '
120 +}
121 +' . $conditions);
122 +
123 +syslog(LOG_ERR, $pluginContent);
124 +
125 + t3lib_extMgm::addTypoScript($extensionKey, 'setup', '
126 +# Setting ' . $extensionKey . ' plugin TypoScript
127 +' . $pluginContent, 43);
128 + }
129 +
130 + /**
131 * Call this method to add an entry in the static template list found in sys_templates
132 * "static template files" are the modern equalent (provided from extensions) to the traditional records in "static_templates"
133 * FOR USE IN ext_localconf.php FILES