RequestTranslationTmgmtActionApproveForm.php in TMGMT Extension Suite 8.2
File
src/Form/RequestTranslationTmgmtActionApproveForm.php
View source
<?php
namespace Drupal\tmgmt_extension_suit\Form;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Queue\QueueInterface;
use Drupal\tmgmt\Entity\JobItem;
use Drupal\tmgmt\JobCheckoutManager;
use Drupal\tmgmt\JobQueue;
use Drupal\user\PrivateTempStoreFactory;
use Drupal\tmgmt\Entity\Job;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RequestTranslationTmgmtActionApproveForm extends BaseTmgmtActionApproveForm {
protected $checkoutManager;
protected $jobQueue;
public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, QueueInterface $queue, ImmutableConfig $config, JobCheckoutManager $checkout_manager, JobQueue $job_queue) {
parent::__construct($temp_store_factory, $entity_type_manager, $language_manager, $queue, $config);
$this->checkoutManager = $checkout_manager;
$this->jobQueue = $job_queue;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('user.private_tempstore'), $container
->get('entity_type.manager'), $container
->get('language_manager'), $container
->get('queue')
->get('tmgmt_extension_suit_upload'), $container
->get('config.factory')
->get('tmgmt_extension_suit.settings'), $container
->get('tmgmt.job_checkout_manager'), $container
->get('tmgmt.queue'));
}
protected $tempStorageName = 'tmgmt_extension_suit_tmgmt_job_operations_request_translation';
public function getFormId() {
return 'tmgmt_extension_suit_request_translation_multiple_confirm';
}
public function getConfirmText() {
return $this
->t('Request translation');
}
public function getQuestion() {
return $this
->t('Are you sure you want to Request translations for these jobs?');
}
public function getDescription() {
return $this
->t('Requesting translation can take some time, do not close the browser');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$jobs = $this
->getEntities($this->entityIds);
foreach ($jobs as $job) {
$job
->setState(Job::STATE_UNPROCESSED);
foreach ($job
->getItems() as $item) {
$item
->setState(JobItem::STATE_ACTIVE);
$item
->resetData();
$item
->recalculateStatistics();
$item
->save();
}
}
$this->checkoutManager
->checkoutAndRedirect($form_state, $jobs);
$this->jobQueue
->setDestination('/admin/tmgmt/jobs');
}
public static function processBatch($data, &$context) {
}
}