getRequest()->getParam('token'); try { $selection = $this->selectionRegistry->get($token); $entityType = $selection['entity_type'] ?? (string)$this->getRequest()->getParam('entity_type'); $this->assertBlogPermission((string)$entityType); $entityIds = $selection['entity_ids'] ?? $this->parseIds( (string)$this->getRequest()->getParam('entity_ids') ); $result = $this->queueManager->enqueue( $entityType, $entityIds, (int)$this->getRequest()->getParam('source_store_id'), (array)$this->getRequest()->getParam('target_store_ids', []), (string)$this->getRequest()->getParam('provider') ); $this->selectionRegistry->clear($token); $this->messageManager->addSuccessMessage( __('%1 task(s) added to the translation queue. %2 duplicate active task(s) skipped.', $result['created'], $result['skipped']) ); return $this->resultRedirectFactory->create()->setPath('*/*/index', [ 'batch_id' => $result['batch_id'], ]); } catch (\Throwable $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); return $this->resultRedirectFactory->create()->setPath('*/*/new', ['token' => $token]); } } /** @return int[] */ private function parseIds(string $value): array { $parts = preg_split('/[^0-9]+/', $value, -1, PREG_SPLIT_NO_EMPTY); return array_values(array_unique(array_map('intval', $parts ?: []))); } private function assertBlogPermission(string $entityType): void { if ($entityType === 'blog_post' && !$this->_authorization->isAllowed('Esun_MultiLocaleTranslation::translate_blog') ) { throw new \InvalidArgumentException((string)__('You are not allowed to translate blog posts.')); } if (in_array($entityType, ['wiki_category', 'wiki_homepage'], true) && !$this->_authorization->isAllowed('Esun_MultiLocaleTranslation::translate_wiki') ) { throw new \InvalidArgumentException((string)__('You are not allowed to translate Wiki content.')); } } }