From 03d4470799477b4c5e07e3616af76a97594df751 Mon Sep 17 00:00:00 2001 From: Bhupesh Pandey <72725957+bhupeshappfoster@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:25:04 +0530 Subject: [PATCH] Release/3.4.2 (#542) * fixed: neo block issue * updated: change log & version bumped * updated: discord notification trigger --- .craftplugin | 2 +- .github/workflows/discord-notify.yml | 2 +- CHANGELOG.md | 5 +++ src/Translations.php | 2 +- .../fieldtranslator/MatrixFieldTranslator.php | 6 ++-- .../fieldtranslator/NeoFieldTranslator.php | 32 ++++++++++++++++--- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/.craftplugin b/.craftplugin index 38e98a8d..31e4a1c2 100644 --- a/.craftplugin +++ b/.craftplugin @@ -1,7 +1,7 @@ { "pluginName": "Translations for Craft", "pluginDescription": "Drive global growth with simplified translation workflows.", - "pluginVersion": "3.4.1", + "pluginVersion": "3.4.2", "pluginAuthorName": "Acclaro", "pluginVendorName": "Acclaro", "pluginAuthorUrl": "http://www.acclaro.com/", diff --git a/.github/workflows/discord-notify.yml b/.github/workflows/discord-notify.yml index fd16084f..e6dcda3a 100644 --- a/.github/workflows/discord-notify.yml +++ b/.github/workflows/discord-notify.yml @@ -6,7 +6,7 @@ name: Discord Notification # events but only for the main branch on: push: - branches: [ master ] + branches: [ master, craft4] # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b12c5d7..0762b5fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 3.4.2 - 2024-12-16 + +### Fixed +- An issue where neo block content is overwritten to all sites. ([AcclaroInc#562](https://github.com/AcclaroInc/pm-craft-translations/issues/562)) + ## 3.4.1 - 2024-08-29 ### Fixed diff --git a/src/Translations.php b/src/Translations.php index 5d23d529..4946fede 100644 --- a/src/Translations.php +++ b/src/Translations.php @@ -686,7 +686,7 @@ private function _onDeleteElement(Event $event) if ($currentFile) { $order = self::$plugin->orderRepository->getOrderById($currentFile->orderId); - $currentFile->status = Constants::FILE_STATUS_CANCELED; + $currentFile->status = Constants::FILE_STATUS_REVIEW_READY; self::$plugin->fileRepository->saveFile($currentFile); diff --git a/src/services/fieldtranslator/MatrixFieldTranslator.php b/src/services/fieldtranslator/MatrixFieldTranslator.php index aaefc204..751bc328 100644 --- a/src/services/fieldtranslator/MatrixFieldTranslator.php +++ b/src/services/fieldtranslator/MatrixFieldTranslator.php @@ -88,14 +88,12 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans foreach ($blocks as $i => $block) { $i = sprintf('new%s', ++$new); - // Check for old key in case an order was created before plugin update - $oldKey = sprintf('%s_%s', $block->fieldId, $block->canonicalId); /** * Block id changes for localised block so use $i and using same for non localised blocks merges other * sites non localised block to non localised block. */ - $blockId = $field->getIsTranslatable() ? $i : $block->id; - $blockData = $fieldData[$i] ?? $fieldData[$oldKey] ?? array(); + $blockId = $field->getIsTranslatable($element) ? $i : $block->id; + $blockData = $fieldData[$i] ?? array(); $post[$fieldHandle][$blockId] = array( 'type' => $block->getType()->handle, diff --git a/src/services/fieldtranslator/NeoFieldTranslator.php b/src/services/fieldtranslator/NeoFieldTranslator.php index a4f9db95..ed61ac6b 100644 --- a/src/services/fieldtranslator/NeoFieldTranslator.php +++ b/src/services/fieldtranslator/NeoFieldTranslator.php @@ -101,10 +101,11 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans foreach ($blocks as $i => $block) { $i = 'new' . ++$new; - $blockId = $field->getIsTranslatable() ? $i : $block->id; + $isTranslatable = $field->getIsTranslatable($element); + $blockId = $isTranslatable ? $i : $this->getBlockUid($block); $blockData = $allBlockData[$i] ?? array(); - $post[$fieldHandle][$blockId] = array( + $data = array( 'modified' => '1', 'type' => $block->getType()->handle, 'enabled' => $block->enabled, @@ -112,6 +113,12 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans 'level' => $block->level, 'fields' => $elementTranslator->toPostArrayFromTranslationTarget($block, $sourceLanguage, $targetLanguage, $blockData, true), ); + + if ($isTranslatable) { + $post[$fieldHandle][$blockId] = $data; + } else { + $post[$fieldHandle]['blocks'][$blockId] = $data; + } } return $post; @@ -155,15 +162,30 @@ public function toPostArray(ElementTranslator $elementTranslator, Element $eleme ); foreach ($blocks as $i => $block) { + $isTranslatable = $field->getIsTranslatable($element); + $blockId = $isTranslatable ? $i : $this->getBlockUid($block); - $blockId = $block->id ?? sprintf('new%s', ++$i); - $post[$fieldHandle][$blockId] = array( + $data = array( + 'modified' => '1', 'type' => $block->getType()->handle, 'enabled' => $block->enabled, - 'fields' => $elementTranslator->toPostArray($block), + 'collapsed' => $block->collapsed, + 'level' => $block->level, + 'fields' => $elementTranslator->toPostArray($block) ); + + if ($isTranslatable) { + $post[$fieldHandle][$blockId] = $data; + } else { + $post[$fieldHandle]['blocks'][$blockId] = $data; + } } return $post; } + + private function getBlockUid($block) + { + return sprintf('uid:%s', $block->getCanonicalUid()); + } }