Skip to content

Commit

Permalink
Merge pull request #108 from lilt/3.x-fix-neo-draft-override
Browse files Browse the repository at this point in the history
Duplicate published neo content to draft before publishing
  • Loading branch information
hadomskyi authored May 26, 2023
2 parents c860122 + f47b34e commit 97d4c84
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.5.4 - 2023-05-26
### Fixed
- Merge canonical changes from the Neo field into drafts

## 3.5.3 - 2023-05-18
### Fixed
- Added fallback for block elements without a created structure to fix content provider
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lilt/craft-lilt-plugin",
"description": "The Lilt plugin makes it easy for you to send content to Lilt for translation right from within Craft CMS.",
"type": "craft-plugin",
"version": "3.5.3",
"version": "3.5.4",
"keywords": [
"craft",
"cms",
Expand Down
37 changes: 35 additions & 2 deletions src/services/handlers/PublishDraftHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function __invoke(int $draftId, int $targetSiteId): void
// Merge canonical changes for supertable fields in current draft before publishing
if (
class_exists('verbb\supertable\SuperTable')
&& method_exists('verbb\supertable\SuperTable', 'getService')
&& method_exists('verbb\supertable\SuperTable', 'getInstance')
|| class_exists('benf\neo\Plugin')
) {
$translation = TranslationRecord::findOne(['translatedDraftId' => $draftId]);
$translations = TranslationRecord::findAll(
Expand All @@ -69,6 +68,8 @@ class_exists('verbb\supertable\SuperTable')
// Check if the field is of Super Table type and the required classes and methods are available
if (
get_class($field) === CraftliltpluginParameters::CRAFT_FIELDS_SUPER_TABLE
&& method_exists('verbb\supertable\SuperTable', 'getService')
&& method_exists('verbb\supertable\SuperTable', 'getInstance')
) {
// Get the Super Table plugin instance
$superTablePluginInstance = call_user_func(['verbb\supertable\SuperTable', 'getInstance']);
Expand All @@ -83,6 +84,38 @@ class_exists('verbb\supertable\SuperTable')
$draftElementLanguageToUpdate->getCanonical(),
$draftElementLanguageToUpdate
);

continue;
}

if (
get_class($field) === CraftliltpluginParameters::BENF_NEO_FIELD
&& class_exists('benf\neo\Plugin')
&& method_exists('benf\neo\Plugin', 'getInstance')
) {
// Get the Neo plugin instance
/** @var \benf\neo\Plugin $neoPluginInstance */
$neoPluginInstance = call_user_func(['benf\neo\Plugin', 'getInstance']);

// Get the Neo plugin Fields service
/** @var \benf\neo\services\Fields $neoPluginFieldsService */
$neoPluginFieldsService = $neoPluginInstance->get('fields');

// Clear current neo field value
$neoField = $draftElementLanguageToUpdate->getFieldValue($field->handle);
foreach ($neoField as $block) {
Craft::$app->getElements()->deleteElement($block);
}
Craft::$app->getElements()->saveElement($draftElementLanguageToUpdate);

// Duplicate the blocks for the field
$neoPluginFieldsService->duplicateBlocks(
$field,
$draftElementLanguageToUpdate->getCanonical(),
$draftElementLanguageToUpdate
);

continue;
}
}
}
Expand Down

0 comments on commit 97d4c84

Please sign in to comment.