jsonFactory->create(); try { $entityType = (string)$this->getRequest()->getParam('entity_type', ''); $entityId = (int)$this->getRequest()->getParam('entity_id'); $targetStoreId = (int)$this->getRequest()->getParam('target_store_id'); $sourceStoreId = (int)$this->getRequest()->getParam('source_store_id'); if ($entityType === '' || $entityId <= 0 || $targetStoreId <= 0) { throw new \InvalidArgumentException(__('Invalid request.')); } $this->assertBlogPermission($entityType); $entity = $this->entityPool->get($entityType); $fields = $entity->getFields($entityId, $sourceStoreId, $targetStoreId); return $result->setData([ 'success' => true, 'fields' => $fields ]); } catch (\Throwable $exception) { return $result->setData([ 'success' => false, 'message' => $exception->getMessage(), ]); } } 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.')); } } }