marketo_ma-8.x-2.x-dev/src/Plugin/QueueWorker/MarketoMaLead.php
src/Plugin/QueueWorker/MarketoMaLead.php
<?php
namespace Drupal\marketo_ma\Plugin\QueueWorker;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\marketo_ma\Service\MarketoMaApiClientInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Updates Marketo lead.
*
* @QueueWorker(
* id = "marketo_ma_lead",
* title = @Translation("Marketo MA Lead"),
* cron = {"time" = 60}
* )
*/
class MarketoMaLead extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The Marketo MA API Client.
*
* @var \Drupal\marketo_ma\Service\MarketoMaApiClientInterface
*/
protected $marketoMaApiClient;
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\marketo_ma\Service\MarketoMaApiClientInterface|null $api_client
* The marketo API client.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MarketoMaApiClientInterface $api_client = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->marketoMaApiClient = $api_client;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('marketo_ma.api_client')
);
}
/**
* {@inheritdoc}
*/
public function processItem($lead) {
// Use the API service to sync the lead.
$this->marketoMaApiClient->syncLead($lead);
}
}
