For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

1

Enable your custom connector

  • Go to Applications

  • Find your custom connector

  • Click Configure

  • Check the “Enabled?” checkbox

  • Click Save

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.

registerWithDispatcher listener (PHP)
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:

1

Create a new dataset

  • Go to the DataSets page.

  • Create a new dataset.

  • Check the “Real time?” checkbox.

2

Choose your connector

  • A Data Connector Source Dropdown will appear. Choose your custom connector from the selection.

  • Save the dataset.

3

Open the dataset

  • Find the dataset that you just added in the table.

  • Open the dataset’s row menu and click “View Data Connector”.

4

Verify logs

  • You should then see the logs being recorded by the JavaScript from the connector.

Last updated

Was this helpful?