Providing Data Connector JS via Connector
This guide will walk you through the steps to create a Data Connector that is supplied via a connector. This feature allows connectors to provide predefined JavaScript. The process is divided into two parts:
Part 1: Register Connector for Data Source Dropdown
To make your custom connector available as an option in the Data Connector Source Dropdown when adding or editing a dataset, you need to register it with the system.
Create Custom Connector
Follow the documentation for creating a custom connector. You can find the detailed guide here.
Be sure to enable it afterward:
Add Event Listener
Now that you have created your connector, you must register it so that the system knows it provides a Data Connector. This will ensure it appears as an option in the Data Connector Source Dropdown when adding or editing a dataset. We do this by adding a listener that executes a method to provide the connector’s ID and name.
Add a listener to your connector class to register it with the event dispatcher.
use Xibo\Event\DataConnectorSourceRequestEvent;
public function registerWithDispatcher(EventDispatcherInterface $dispatcher): ConnectorInterface
{
// Add a listener to handle the Data Connector Source Request event
$dispatcher->addListener(DataConnectorSourceRequestEvent::$NAME, [$this, 'onDataConnectorSourceRequest']);
return $this;
}Implement Event Handler
Add a method to handle the event and provide the connector’s ID and name.
Then, it would be added to the form as shown below:

Part 2: Extend Connector to Provide JavaScript
Now that you have registered your connector, you need to extend it to provide predefined JavaScript. This will involve adding another listener to respond when the system checks if your connector is the selected one, and if so, provide the JavaScript.
Add Another Listener
Add another listener to the registerWithDispatcher() method:
Implement New Event Handler
Add a method to handle the event and provide the JavaScript if the connector ID matches; a sample predefined JavaScript snippet is included in the code example below.
By following these steps, you have successfully registered your custom connector and extended it to provide predefined JavaScript. This enables your Data Connector to appear as an option in the Data Connector Source Dropdown and supply JavaScript when selected.
Test Data Connector JS
To check if it’s working:

Last updated
Was this helpful?

