Call the TYPO3 plugin from another plugin

I need to call the typo3 plugin from another plugin body and pass its result to the template. This is the pseudo code that describes what I want to achieve:

$data['###SOME_VARIABLE###'] = $someOtherPlugin->main(); $this->cObj->substituteMarkerArray($someTemplate, $data); 

Is it possible?

Thanks!

+4
source share
5 answers

You should use the t3lib_div: makeInstance method.

There is a working example from the TYPO3 "powermail" extension.

 function getGeo() { // use geo ip if loaded if (t3lib_extMgm::isLoaded('geoip')) { require_once( t3lib_extMgm::extPath('geoip').'/pi1/class.tx_geoip_pi1.php'); $this->media = t3lib_div::makeInstance('tx_geoip_pi1'); if ($this->conf['geoip.']['file']) { // only if file for geoip is set $this->media->init($this->conf['geoip.']['file']); // Initialize the geoip Ext $this->GEOinfos = $this->media->getGeoIP($this->ipOverride ? $this->ipOverride : t3lib_div::getIndpEnv('REMOTE_ADDR')); // get all the infos of current user ip } } } 
+4
source

This works if you use the entire pi construct, for example. for links, marker functions, etc., and TSFE data may be corrupted.

Dmitry said: http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html

 $cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1']; $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_rgsmoothgallery_pi1.']; $cObj = t3lib_div::makeInstance('tslib_cObj'); $cObj->start(array(), '_NO_TABLE'); $conf['val'] = 1; $content = $cObj->cObjGetSingle($cObjType, $conf); //calling the main method 
+6
source

@Mitchiru's answer is good and basically correct.

If you created an external extension using Kickstarter and use pi_base, then there is already an instance of tslib_cObj, and the whole construction becomes simpler:

 // get type of inner extension, eg. USER or USER_INT $cObjType = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1']; // get configuration array of inner extension $cObjConf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_innerextension_pi1.']; // add own parameters to configuration array if needed - otherwise skip this line $cObjConf['myparam'] = 'myvalue'; // call main method of inner extension, using cObj of outer extension $content = $this->cObj->cObjGetSingle($cObjType, $cObjConf); 
+1
source

First, you must include your plugin class before or outside of your class:

 include_once(t3lib_extMgm::extPath('myext').'pi1/class.tx_myext_pi1.php'); 

Secondly, in your code (mainly as an example)

 $res = tx_myext_pi1::myMethod(); 
0
source

This will work for sure (I checked it): http://lists.typo3.org/pipermail/typo3-english/2008-August/052259.html .

Fedir's answer is probably correct too, but I have not had the opportunity to try it.

Hooray!

0
source

Source: https://habr.com/ru/post/1369141/


All Articles