/** * 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. * * @param \Drupal\tmgmt\Entity\Job $job * Continuous job. * @param string $plugin * The plugin name. * @param string $item_type * The source item type. * @param string $item_id * The source item id. * * @return \Drupal\tmgmt\Entity\JobItem * Continuous job item. */ 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); if ($should_create_item) { 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(); $translator->requestJobItemsTranslation([$job_item]); } return $job_item; } return NULL; }
/** * Submit method for Add to continuous jobs button. * * @param array $form * Drupal form array. * @param FormStateInterface $form_state * Drupal form_state array. */ public function submitToContinuousJobs(array &$form, FormStateInterface $form_state) { $plugin = $form_state->get('plugin'); $item_type = $form_state->get('item_type'); // Execute the submit method on the source plugin controller. $source_ui = $this->sourceManager->createUIInstance($plugin); $source_ui->overviewSubmitToContinuousJobs($form_state, $item_type); }