I have two plugins that need to communicate with each other. One of the plugins allows a user to create workouts. The other plugin needs to be able to allow the user to link to the workout plugin to specific workouts.
To do this, it would be ideal to be able to go into the consuming plugin, click something like "link a workout", and have it take me via buildfire.navigation.navigateTo to the workout plugin where I can select a workout (because the workout data is only accessible to this plugin). From there, once the selection is made, it would navigate me back to the other plugin with the id of the workout record that I linked. This way, I could save the id of the workout and whenever somebody wants to see the workout from the widget, it would be able to navigate them to the workout plugin and load the proper ID.
When I tried implementing this in the control panel, navigation.navigateTo errors out with this message:
postMessageHandler error: TypeError: Cannot read property 'source' of undefined
at Object.navigateTo (pluginAPI.js:265)
at PluginAPI.postMessageHandler (pluginAPI.js:221)
at tryPMH (postMaster.js:44)
at Object._acceptRequest (postMaster.js:62)
at postMessageHandler (postMaster.js:29)
Can navigation.navigateTo only be used on the widget side? This is my navigation object for reference:
pluginId: '6d9d8456-d2c9-4ddb-80b8-**********',
instanceId: '6drt3456-d2c9-4ddb-80b8-fdbbff854r1b-*********',
folderName: 'theplugin',
title: '',
queryString: '?id=abc123def456'
Also, I'm not sure what the folderName is supposed to be. It seems like it is required from the SDK source code, but I can't figure out what I should be putting there. I put something I thought might work for it, but it may be the culprit of why this isn't working. Looking for confirmation on this.
Despite all of that, even when I use the navigation from the Widget, when it loads the new plugin and admin panel for the newly loaded plugin says "404 not found" instead of loading the admin panel. Any ideas on this as well?
If you want the control to trigger navigation on the widget, you will need to use messaging. See the example below.
On the control:
buildfire.messaging.sendMessageToWidget({
name: 'OPEN_PLUGIN',
message: {
data: pluginData
}
});
On the widget:
buildfire.messaging.onReceivedMessage = function(message){
var plugin = event.message.data;
switch (message.section){
case 'OPEN_PLUGIN':
if (plugin && plugin.pluginType && plugin.pluginType.folderName)
fName = plugin.pluginType.folderName;
else if (plugin && plugin.folderName)
fName = plugin.folderName;
buildfire.navigation.navigateTo({
pluginId: plugin.pluginId,
instanceId: plugin.instanceId,
title: plugin.title,
folderName: fName
});
break;
}
}
In terms of the of the folder name, there are several ways to obtain it. One simple way is to edit a plugin instance in the control panel. The URL will look as follows:
That translates the following format:
So in this example the folder name is 52.