MageBridge plugin events
While actually the Joomla! plugin-type Magento is much more interesting (because it allows for catching Magento events in Joomla!), the Joomla! plugins of type MageBridge offers some extra functionality when dealing with building the bridge. This tutorial describes the plugin-events.
onBeforeDisplayBlock(&$block_name, $arguments, &$block_data)
The event onBeforeDisplayBlock allows you to parse a Magento block before it is being displayed in Joomla!. This functionality is comparable with the Joomla! Content Plugins, however Content Plugins deal with all types of content, while the MageBridge Plugins only deal with Magento blocks. This gives you the ability to do something specific with Magento content, instead of all Joomla! content.
The plugin method uses the following options: A reference to the $block_name; the arguments passed to the bridge when building this block (mostly empty); and a reference to the $block_data. Parsing the blocks content means modifying the $block_data variable. The plugin-method returns nothing.
Remember that the main component-area of MageBridge is actually a Magento block called content. So this plugin deals with both the component-output as well as modules-output.
onBeforeBuildMageBridge()
The event onBeforeBuildMageBridge is thrown just before the bridge is actually built (and a request is being sent to Magento). While you can add your own bridge-request in many other ways (for instance, by writing a Joomla! System Plugin), this event allows for more complicated tricks that should be applied to all MageBridge request-segments.
The method has no arguments, however instances of vital MageBridge objects are still available. For instance, if you want to modify the bridge-request (which is actually referred to as the pending register) you can call upon the register with the code below:
$register = MageBridgeModelRegister::getInstance();
This method would be very powerful for instance when implementing caching. For the moment we have implemented block caching in a diffferent way, but this may change. You could also add something to the MageBridge register that can then be extracted on the Magento side:
$register->add('mystuff', null, array('test1', 'test2', 'test3'));
Within Magento you can then use the following code to receive $mystuff from the bridge.
$bridge = Mage::getSingleton('magebridge/core');
$data = $bridge->getRequestData();
$mystuff = $data['mystuff']; // returns array('test1', 'test2', 'test3');
onAfterBuildMageBridge()
Last but not least, once the bridge is built you can catch this event. After the bridge is built, the bridge-response is merged into the register, so just like with the onBeforeBuildMageBridge() method above, you can fetch the register to get the data you want. Just like with the before-build event, you can also add your own kind of data. Within Magento, you can call upon the pending response and add something to it:
$bridge = Mage::getSingleton('magebridge/core');
$bridge->addResponseData('mystuff', array('test1', 'test2', 'test3'));
And in Joomla!, you can then again extract this information using the Joomla! plugin with the event onAfterBuildMageBridge():
$data = $register->getData();Created on Sunday, 12 September 2010
print_r($data);
Modified on Wednesday, 27 July 2011
More tutorials in this section
- MageBridge plugin events
- MageBridge from the command-line
- MageBridge FAQ: Development
- Reusing MageBridge parameters in Joomla! extensions
- Catching Magento events with a Joomla! plugin
- Fetch your own Magento data from MageBridge
- Handling events with MageBridge (in progress)
- How can I create a language-pack for MageBridge?
- Creating custom store connectors
- Discovering the MageBridge Magento package
