Skip to content

Commit

Permalink
Release/3.4.2 (#542)
Browse files Browse the repository at this point in the history
* fixed: neo block issue

* updated: change log & version bumped

* updated: discord notification trigger
  • Loading branch information
bhupeshappfoster authored Dec 16, 2024
1 parent 87c75bb commit 03d4470
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .craftplugin
Original file line number Diff line number Diff line change
@@ -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/",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/discord-notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions src/services/fieldtranslator/MatrixFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 27 additions & 5 deletions src/services/fieldtranslator/NeoFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,24 @@ 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,
'collapsed' => $block->collapsed,
'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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 03d4470

Please # to comment.