TYPO3 - userFunc: Unterschied zwischen den Versionen
(Die Seite wurde neu angelegt: „Je nach Version unterschiedlich V7.6: http://www.schmutt.de/542/userfunc-tutorial-update/ V8.7: http://typo3blogger.de/userfuncs-per-typoscript-in-typo3-8-7-…“) |
|||
| Zeile 1: | Zeile 1: | ||
Je nach Version unterschiedlich | Je nach Version unterschiedlich | ||
| − | V7. | + | V7.4: http://www.schmutt.de/542/userfunc-tutorial-update/ |
V8.7: http://typo3blogger.de/userfuncs-per-typoscript-in-typo3-8-7-einbinden/ | V8.7: http://typo3blogger.de/userfuncs-per-typoscript-in-typo3-8-7-einbinden/ | ||
| + | |||
| + | == UserFunc in TYPO3 7.4 == | ||
| + | Ab 7.4 hat sich die include Syntax geändert, config.includeLibrary und config.includeLibs wurden entfernt. Userfuncs müssen ab TYPO3 7.4 folgendermaßen eingebunden werden: | ||
| + | |||
| + | <pre> | ||
| + | page.20 = USER_INT | ||
| + | page.20 { | ||
| + | userFunc = user_printTime | ||
| + | includeLibs = fileadmin/example_time.php | ||
| + | } | ||
| + | </pre> | ||
| + | Einfache Extension für die userFunc | ||
| + | |||
| + | Empfohlen wird aber, die benötigten Klassen über eine Extension einzubinden und das Autoload-Verhalten mit Namepaces auszunutzen. Dafür ist minimal nötig (Beispiel – danke dafür an Peter Linzenkirchner): | ||
| + | |||
| + | Ein Ordner in typo3conf/ext/ mit diesem Inhalt: | ||
| + | <pre> | ||
| + | typo3conf/ext/myincludes | ||
| + | typo3conf/ext/myincludes/Classes/ | ||
| + | typo3conf/ext/myincludes/Classes/Example.php | ||
| + | typo3conf/ext/myincludes/ext_emconf.php | ||
| + | typo3conf/ext/myincludes/ext_icon.gif | ||
| + | </pre> | ||
| + | Der Inhalt der ext_emconf.php: | ||
| + | |||
| + | <?php | ||
| + | $EM_CONF[$_EXTKEY] = array( | ||
| + | 'title' => 'Include all my Classes', | ||
| + | 'description' => 'Einbinden der Klassen für userFunc', | ||
| + | 'category' => 'fe', | ||
| + | 'author' => 'my Name', | ||
| + | 'author_email' => 'my Email', | ||
| + | 'state' => 'alpha', | ||
| + | 'author_company' => 'my Company', | ||
| + | 'version' => '0.0.1', | ||
| + | 'constraints' => array( | ||
| + | 'depends' => array( | ||
| + | ), | ||
| + | 'conflicts' => array( | ||
| + | ), | ||
| + | 'suggests' => array( | ||
| + | ), | ||
| + | ), | ||
| + | ); | ||
| + | |||
| + | Der Inhalt der Example.php: | ||
| + | |||
| + | <?php | ||
| + | namespace Myvendor\Myincludes; | ||
| + | class Example { | ||
| + | public function myExampleFunction($content, $conf) { | ||
| + | $color = $conf['userFunc.']['color']; | ||
| + | return '<p style="color:' . $color. ';">Dynamic time: ' . date('H:i:s') . '</p><br />'; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Und der Aufruf im TS: | ||
| + | |||
| + | page.30 = USER_INT | ||
| + | page.30 { | ||
| + | userFunc = Myvendor\Myincludes\Example->myExampleFunction | ||
| + | userFunc.color = #ff0000 | ||
| + | } | ||
| + | |||
| + | ExtBase Extension mit userFunc Action | ||
| + | |||
| + | Oft hat man bereits eine Extbase Extension und will eine bestimmte Action als userFunc aufrufen. Das geht so: | ||
| + | |||
| + | 10 = USER_INT | ||
| + | 10 { | ||
| + | userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run | ||
| + | vendorName = MyVendor\Myincludes | ||
| + | extensionName = MyExtension | ||
| + | pluginName = Pi1 | ||
| + | switchableControllerActions { | ||
| + | Example { | ||
| + | 1 = myUserFunc | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Und das ist der zugehörige Controller. Der Eintrag in switchableControllerActions ist nötig, da sonst die default listAction aufgerufen wird: | ||
| + | |||
| + | <?php | ||
| + | namespace MyVendor\MyExtension\Controller; | ||
| + | |||
| + | class ExampleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController | ||
| + | { | ||
| + | public function listAction() { | ||
| + | ... | ||
| + | } | ||
| + | |||
| + | public function myUserFuncAction() { | ||
| + | return '<p style="color: red;">Dynamic time: ' . date('H:i:s') . '</p><br />'; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | Weitere Infos zu der ExtBase Variante findet man hier: http://blog.teamgeist-medien.de/2014/03/typo3-eine-extbase-extension-per-typoscript-einbinden.html | ||
Version vom 23. Januar 2018, 12:21 Uhr
Je nach Version unterschiedlich
V7.4: http://www.schmutt.de/542/userfunc-tutorial-update/
V8.7: http://typo3blogger.de/userfuncs-per-typoscript-in-typo3-8-7-einbinden/
UserFunc in TYPO3 7.4
Ab 7.4 hat sich die include Syntax geändert, config.includeLibrary und config.includeLibs wurden entfernt. Userfuncs müssen ab TYPO3 7.4 folgendermaßen eingebunden werden:
page.20 = USER_INT
page.20 {
userFunc = user_printTime
includeLibs = fileadmin/example_time.php
}
Einfache Extension für die userFunc
Empfohlen wird aber, die benötigten Klassen über eine Extension einzubinden und das Autoload-Verhalten mit Namepaces auszunutzen. Dafür ist minimal nötig (Beispiel – danke dafür an Peter Linzenkirchner):
Ein Ordner in typo3conf/ext/ mit diesem Inhalt:
typo3conf/ext/myincludes
typo3conf/ext/myincludes/Classes/
typo3conf/ext/myincludes/Classes/Example.php
typo3conf/ext/myincludes/ext_emconf.php
typo3conf/ext/myincludes/ext_icon.gif
Der Inhalt der ext_emconf.php:
<?php $EM_CONF[$_EXTKEY] = array(
'title' => 'Include all my Classes',
'description' => 'Einbinden der Klassen für userFunc',
'category' => 'fe',
'author' => 'my Name',
'author_email' => 'my Email',
'state' => 'alpha',
'author_company' => 'my Company',
'version' => '0.0.1',
'constraints' => array(
'depends' => array(
),
'conflicts' => array(
),
'suggests' => array(
),
),
);
Der Inhalt der Example.php:
<?php namespace Myvendor\Myincludes; class Example {
public function myExampleFunction($content, $conf) {
$color = $conf['userFunc.']['color'];
return '
Dynamic time: ' . date('H:i:s') . '
';
}
}
Und der Aufruf im TS:
page.30 = USER_INT page.30 {
userFunc = Myvendor\Myincludes\Example->myExampleFunction userFunc.color = #ff0000
}
ExtBase Extension mit userFunc Action
Oft hat man bereits eine Extbase Extension und will eine bestimmte Action als userFunc aufrufen. Das geht so:
10 = USER_INT 10 {
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run
vendorName = MyVendor\Myincludes
extensionName = MyExtension
pluginName = Pi1
switchableControllerActions {
Example {
1 = myUserFunc
}
}
}
Und das ist der zugehörige Controller. Der Eintrag in switchableControllerActions ist nötig, da sonst die default listAction aufgerufen wird:
<?php namespace MyVendor\MyExtension\Controller;
class ExampleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
public function listAction() {
...
}
public function myUserFuncAction() {
return '
Dynamic time: ' . date('H:i:s') . '
';
}
}
Weitere Infos zu der ExtBase Variante findet man hier: http://blog.teamgeist-medien.de/2014/03/typo3-eine-extbase-extension-per-typoscript-einbinden.html