public function ContinuousManager::addItem in Translation Management Tool 8
Creates job item and submits according to the configured settings.
The job item will only be created if the given source plugin for the job is configured to accept this source.
The job item will be immediately submitted to the translator unless this happens on cron runs.
Parameters
\Drupal\tmgmt\Entity\Job $job: Continuous job.
string $plugin: The plugin name.
string $item_type: The source item type.
string $item_id: The source item id.
Return value
\Drupal\tmgmt\Entity\JobItem Continuous job item.
See also
\Drupal\tmgmt\Events\ContinuousEvents::SHOULD_CREATE_JOB
File
- src/
ContinuousManager.php, line 131
Class
- ContinuousManager
- A service manager for continuous jobs.
Namespace
Drupal\tmgmtCode
public function addItem(Job $job, $plugin, $item_type, $item_id) {
// Check if a job item should be created.
$most_recent_job_item = $job
->getMostRecentItem($plugin, $item_type, $item_id);
$should_create_item = $this->sourcePluginManager
->createInstance($plugin)
->shouldCreateContinuousItem($job, $plugin, $item_type, $item_id);
// Some modules might want to filter out candidates for items.
$event = new ShouldCreateJobEvent($job, $plugin, $item_type, $item_id, $should_create_item);
$this->eventDispatcher
->dispatch(ContinuousEvents::SHOULD_CREATE_JOB, $event);
if ($event
->shouldCreateItem()) {
if ($most_recent_job_item) {
// If the most recent job item is active do nothing.
if (!$most_recent_job_item
->isAborted() && !$most_recent_job_item
->isAccepted()) {
$most_recent_job_item
->addMessage('Source was updated, changes were ignored as job item is still active.');
return NULL;
}
}
// If there are no job items or it's finished/aborted create new one.
$job_item = $job
->addItem($plugin, $item_type, $item_id);
$job_item
->addMessage('Continuous job item created');
// Only submit the item if cron submission is disabled.
if (!$this->configFactory
->get('tmgmt.settings')
->get('submit_job_item_on_cron')) {
$translator = $job
->getTranslatorPlugin();
\Drupal::moduleHandler()
->invokeAll('tmgmt_job_before_request_translation', [
[
$job_item,
],
]);
if ($job_item
->getCountPending() > 0) {
$translator
->requestJobItemsTranslation([
$job_item,
]);
}
\Drupal::moduleHandler()
->invokeAll('tmgmt_job_after_request_translation', [
[
$job_item,
],
]);
}
return $job_item;
}
return NULL;
}