request->getParam('post', []); $postData = is_array($postData) ? $postData : []; $storeId = max(0, (int)($postData['translation_store_id'] ?? 0)); if ($storeId <= 0) { return $proceed(); } $postId = (int)$this->request->getParam('id'); if ($postId <= 0) { $this->messageManager->addErrorMessage(__('The blog post no longer exists.')); return $this->redirectFactory->create()->setPath('mageplaza_blog/post/index'); } if (!$this->authorization->isAllowed('Esun_MultiLocaleTranslation::translate_blog')) { $this->messageManager->addErrorMessage(__('You are not allowed to save blog translations.')); return $this->redirectToEdit($postId, $storeId); } try { $fields = array_intersect_key($postData, array_flip(BlogPostFields::codes())); $useDefault = is_array($postData['use_default'] ?? null) ? $postData['use_default'] : []; $this->blogPostEntity->apply($postId, $storeId, $fields, $useDefault); $this->cacheManager->clean(['full_page', 'block_html']); $this->messageManager->addSuccessMessage(__('You saved the blog post translation.')); } catch (\Throwable $exception) { $this->messageManager->addErrorMessage( __('Something went wrong while saving the blog post translation: %1', $exception->getMessage()) ); } return $this->redirectToEdit($postId, $storeId); } private function redirectToEdit(int $postId, int $storeId): Redirect { return $this->redirectFactory->create()->setPath( 'mageplaza_blog/post/edit', ['id' => $postId, 'store' => $storeId] ); } }