Documentation

5.1 Creating an exporter for content distribution

Integrated provides an easy way to distribute content. Integrated manages what, when and where content has to be distributed, while individual connectors take care of the distribution itself. Integrated takes care of:

  • Saving your connector configuration per channel
  • Finding out which content needs to be distributed at what moment
  • Running the export function of your connector when content needs to be distributed

To create a connector you need to:

  • Create a form for the configuration
  • Implement the export function and distribute the content to your target
  • The connector is responsible for finding out if the document is already available on the target and need to be updated, or need the be created

To create your own connector you have to implement some interfaces.

Manifest implementation

First implement the ManifestInterface with your connector name, description and title.

Connector\TestManifest.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
 
namespace Integrated\Bundle\TestBundle\Connector;
use Integrated\Common\Channel\Connector\Adapter\ManifestInterface;
 
class TestManifest implements ManifestInterface
{
/**
* {@inheritdoc}
*/
public function getName()
{
return 'test';
}
 
/**
* {@inheritdoc}
*/
public function getLabel()
{
return 'Test';
}
 
/**
* {@inheritdoc}
*/
public function getDescription()
{
return 'This is a test adaptor that does nothing';
}
 
/**
* {@inheritdoc}
*/
public function getVersion()
{
return '1.0';
}
}

Configuration implementation

After that, implement the ConfigurationInterface to allow configuration of your connector. You need a form with your configuration options. This is a standard Symfony form.

Connector\TestConfiguration:php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
 
namespace Integrated\Bundle\TestBundle\Connector;
 
use Integrated\Common\Channel\Connector\ConfigurationInterface;
use Symfony\Component\Form\FormTypeInterface;
 
class TestConfiguration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getForm()
{
return 'integrated_test_options';
}
}

Exporter implementation

Now implement the ExporterInterface to export your content:

Connector\TestExporter.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
namespace Integrated\Bundle\TestBundle\Connector;
 
use Integrated\Common\Channel\ChannelInterface;
use Integrated\Common\Channel\Exporter\ExporterInterface;
 
class TestExporter implements ExporterInterface
{
/**
* {@inheritdoc}
*/
public function export($content, $state, ChannelInterface $channel)
{
\Symfony\Component\VarDumper\VarDumper::dump($content->getId());
\Symfony\Component\VarDumper\VarDumper::dump($state);
\Symfony\Component\VarDumper\VarDumper::dump($channel->getId());
}
}

The $state variable

The $state can be "add" or "delete". Please note that an updated document will also have the "add" state, so you'll have to make sure you verify if the document is already added before and needs to be updated.

When a document is unpublished the $state will be "delete". You can choose to delete the document in your target system in that case, or to unpublish it.

Adapter implementation

Finally implement some interfaces to implement the adapter:

Connector\TestAdapter.php:

1
<?php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
namespace Integrated\Bundle\TestBundle\Connector;
 
use Integrated\Common\Channel\Connector\AdapterInterface;
use Integrated\Common\Channel\Connector\Config\OptionsInterface;
use Integrated\Common\Channel\Connector\ConfigurableInterface;
 
use Integrated\Common\Channel\Exporter\ExportableInterface;
use Integrated\Common\Channel\Exporter\ExporterInterface;
 
class TestAdapter implements AdapterInterface, ConfigurableInterface, ExportableInterface
{
/**
* @var TestManifest
*/
private $manifest = null;
 
/**
* @var TestConfiguration
*/
private $configuration = null;
 
/**
* @var TestExporter
*/
private $exporter = null;
 
/**
* {@inheritdoc}
*/
public function getManifest()
{
if (null === $this->manifest) {
$this->manifest = new TestManifest();
}
 
return $this->manifest;
}
 
/**
* {@inheritdoc}
*/
public function getConfiguration()
{
if (null === $this->configuration) {
$this->configuration = new TestConfiguration();
}
 
return $this->configuration;
}
 
/**
* {@inheritdoc}
*/
public function getExporter(OptionsInterface $options)
{
if (null === $this->exporter) {
$this->exporter = new TestExporter();
}
 
return $this->exporter;
}
}
 
 

This one needs to be registered as a service, with the "integrated_channel.connector" tag.

Resources/config/connector.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8" ?>
 
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
 
<parameters>
 
<parameter key="integrated_test.connector.test.class">Integrated\Bundle\TestBundle\Connector\TestAdapter</parameter>
 
</parameters>
 
<services>
 
<service id="integrated_test.connector.test" class="%integrated_test.connector.test.class%">
<tag name="integrated_channel.connector" />
</service>
 
</services>
 
</container>

Example exporter

Download our example exporter with the files from this document.

Configure and activate the exporter

To activate your exporter in Integrated go to the main menu and choose Manage - Connectors. You can now create a new configuration instance for your exporter and configure the settings with your form. You have to attach it to one or more channels to be able to export content.

Your new or edited content will be distributed (when published).

Make sure you have the channel:export cron running, or run it manually:

1
php app/console channel:export