After you have enabled this Bundle, there are some global steps to define.
If you don't have any pimcore data object to manage your jobs you need to create it first. After that, you need to tell JobsBundle about it:
# config/packages/jobs.yaml
jobs:
data_class: MyJobDataClass
Add the "Jobs Connector Context" field to your data class. It would be good practice if it's placed in a dedicated tab.
Name it (Field "name") jobConnectorContext
.
You can check the Health state by visiting the Jobs Menu "Settings"
=> "Jobs Configuration"
.
Watch out for this information:
Some connectors require an interface from which they can fetch the data. For certain connectors, the path even has to be submitted first (Like Facebook). This forces us to define a global feed host.
# config/packages/jobs.yaml
jobs:
data_class: MyJobDataClass
feed_host: 'http://www.my-company.com'
There can be only one host per instance. But no worries, you're still able to publish jobs for multisites by using the context definitions, which we gonna checkout next.
Context definitions determine which jobs should get published on which portal with a given locale
and host
.
Since an object can live in multiple ways, we need to make things certain.
For Example facebook does not have any possibilities to publish jobs in multiple locales. But within the google context it's possible for sure.
Click on the Add
button to create your first Context Definition:
Name | Description |
---|---|
Host |
Define your host. This is required to generate absolute links |
Locale |
Set a locale. The Job Object should get transformed within this locale |
You can add as many Context Definitions as you want. However, please note that some Connectors do not allow multiple definitions (Like Facebook).
Your Job Object needs a valid Link Generator. If you already have created a Link Generator make sure that you're respecting the host value.
Note
If you're using the I18n Bundle, you don't have to build such a complex link generator. JobsBundle will automatically send all required data to the link generator instead.
A Link Generator could look like this:
<?php
namespace App;
use JobsBundle\Model\ConnectorContextItemInterface;
use Pimcore\Model\DataObject\ClassDefinition\LinkGeneratorInterface;
use Pimcore\Model\DataObject\Concrete;
use Pimcore\Model\Staticroute;
class ObjectLinkGenerator implements LinkGeneratorInterface
{
public function generate(Concrete $object, array $params = []): string
{
$staticRoute = Staticroute::getByName('my_object_route');
$connectorContextConfig = null;
$connectorContextItem = isset($params['connectorContextItem']) ? $params['connectorContextItem'] : null;
if ($connectorContextItem instanceof ConnectorContextItemInterface) {
$connectorContextConfig = $connectorContextItem->getContextDefinition();
}
$mainRequest = \Pimcore::getContainer()->get('request_stack')->getMainRequest();
$baseLocale = isset($params['_locale']) ? $params['_locale'] : $mainRequest->getLocale();
$baseHost = isset($params['host']) ? $params['host'] : null;
$locale = $connectorContextConfig !== null ? $connectorContextConfig->getLocale() : $baseLocale;
$host = $connectorContextConfig !== null ? $connectorContextConfig->getHost() : $baseHost;
$path = $staticRoute->assemble(['object_id' => $object->getId(), '_locale' => $locale]);
if ($host !== null) {
return sprintf('%s%s', $host, $path);
}
return $path;
}
}
This is the final step: Set up your Connectors. Each connector has its own configuration and strategies. Lets checkout the Connector Guide to learn how to use and install them.