Skip to content

Commit

Permalink
Merge pull request #540 from AcclaroInc/neo-block-issue-fix
Browse files Browse the repository at this point in the history
fixed: neo block issue
  • Loading branch information
bhupeshappfoster authored Dec 13, 2024
2 parents 56b82c3 + afcb9a7 commit a8ceb75
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 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": "v4.0.2",
"pluginVersion": "v4.0.3",
"pluginAuthorName": "Acclaro",
"pluginVendorName": "Acclaro",
"pluginAuthorUrl": "http://www.acclaro.com/",
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/).

## 4.0.3 - 2024-12-13

### Fixed
- Neo blocks overwriting content in other sites on draft creation. ([AcclaroInc#562](https://github.com/AcclaroInc/pm-craft-translations/issues/562))

## 4.0.2 - 2024-11-21

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/Translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,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
38 changes: 30 additions & 8 deletions src/services/fieldtranslator/NeoFieldTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,24 @@ public function toPostArrayFromTranslationTarget(ElementTranslator $elementTrans
foreach ($blocks as $i => $block) {
$i = 'new' . ++$new;

$blockId = $field->getIsTranslatable($element) ? $i : $block->id;
$isTranslatable = $field->getIsTranslatable($element);
$blockId = $isTranslatable ? $i : $this->getBlockUid($block);
$blockData = $allBlockData[$i] ?? array();

$post[$fieldHandle][$blockId] = array(
$data = [
'modified' => '1',
'type' => $block->getType()->handle,
'enabled' => $block->enabled,
'collapsed' => $block->collapsed,
'level' => $block->level,
'fields' => $elementTranslator->toPostArrayFromTranslationTarget($block, $sourceLanguage, $targetLanguage, $blockData, true),
);
'fields' => $elementTranslator->toPostArrayFromTranslationTarget($block, $sourceLanguage, $targetLanguage, $blockData, true),
];

if ($isTranslatable) {
$post[$fieldHandle][$blockId] = $data;
} else {
$post[$fieldHandle]['blocks'][$blockId] = $data;
}
}

return $post;
Expand All @@ -147,6 +154,11 @@ public function getWordCount(ElementTranslator $elementTranslator, Element $elem
return $wordCount;
}

private function getBlockUid($block)
{
return sprintf('uid:%s', $block->getCanonicalUid());
}

/**
* {@inheritdoc}
*/
Expand All @@ -165,13 +177,23 @@ 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 = [
'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;
Expand Down

0 comments on commit a8ceb75

Please sign in to comment.