class RequestTranslationSubscriber in TMGMT Translator Smartling 8
Same name and namespace in other branches
- 8.4 src/EventSubscriber/RequestTranslationSubscriber.php \Drupal\tmgmt_smartling\EventSubscriber\RequestTranslationSubscriber
- 8.2 src/EventSubscriber/RequestTranslationSubscriber.php \Drupal\tmgmt_smartling\EventSubscriber\RequestTranslationSubscriber
- 8.3 src/EventSubscriber/RequestTranslationSubscriber.php \Drupal\tmgmt_smartling\EventSubscriber\RequestTranslationSubscriber
Hierarchy
- class \Drupal\tmgmt_smartling\EventSubscriber\RequestTranslationSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RequestTranslationSubscriber
1 string reference to 'RequestTranslationSubscriber'
1 service uses RequestTranslationSubscriber
File
- src/
EventSubscriber/ RequestTranslationSubscriber.php, line 12
Namespace
Drupal\tmgmt_smartling\EventSubscriberView source
class RequestTranslationSubscriber implements EventSubscriberInterface {
const WAIT_BEFORE_CONTEXT_UPLOAD = 600;
protected $contextUploadQueue;
public function __construct(QueueFactory $queue, TranslationJobToUrl $url_converter) {
$this->contextUploadQueue = $queue
->get('smartling_context_upload', TRUE);
$this->urlConverter = $url_converter;
}
/**
* Code that should be triggered on event specified
*/
public function onUploadRequest(RequestTranslationEvent $event) {
/** @var JobInterface $job */
$job = $event
->getJob();
if (!$job
->getTranslator()
->getPlugin() instanceof SmartlingTranslator) {
return;
}
$job_items = $job
->getItems();
if (empty($job_items)) {
return;
}
$filename = $job
->getTranslatorPlugin()
->getFileName($job);
foreach ($job_items as $item) {
$url = $this->urlConverter
->convert($item);
\Drupal::moduleHandler()
->alter('tmgmt_smartling_context_url', $url, clone $item);
if (!empty($url)) {
$this->contextUploadQueue
->createItem([
'url' => $url,
'filename' => $filename,
'job_id' => $job
->id(),
'upload_date' => time() + self::WAIT_BEFORE_CONTEXT_UPLOAD,
]);
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// For this example I am using KernelEvents constants (see below a full list).
$events = [];
$events[RequestTranslationEvent::REQUEST_TRANSLATION_EVENT][] = [
'onUploadRequest',
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RequestTranslationSubscriber:: |
protected | property | ||
RequestTranslationSubscriber:: |
public static | function | ||
RequestTranslationSubscriber:: |
public | function | Code that should be triggered on event specified | |
RequestTranslationSubscriber:: |
constant | |||
RequestTranslationSubscriber:: |
public | function |