Skip to content

Commit

Permalink
also migrate condition workflow to name
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Oct 13, 2023
1 parent 01d68d7 commit c6b0ea6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [DEPRECATION REMOVED] removed `FormDefinition::setMailLayout`. Please migrate to output workflows before updating
- [IMPROVEMENT] Recommended folder structure by symfony adopted
- [IMPROVEMENT] Make success flash message optional [#403](https://github.com/dachcom-digital/pimcore-formbuilder/issues/403)
- [IMPROVEMENT] Use name instead of ID in output workflow actions [#408](https://github.com/dachcom-digital/pimcore-formbuilder/pull/408)
- [FUNNEL] Route include changed from `@FormBuilderBundle/Resources/config/pimcore/routing_funnels.yml` to `@FormBuilderBundle/config/pimcore/routing_funnels.yaml`
- [BC BREAK] Mail Layout Editor: While there is a migration, we're not able to migrate container (fieldset, repeater) fields. Please adjust your output workflow channels manually.
- [BC BREAK] All views are lowercase/underscore now (`email/form_data.html.twig`, `form/elements/dynamic_multi_file/*`)
Expand Down
4 changes: 2 additions & 2 deletions public/js/extjs/conditional-logic/condition/outputWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Formbuilder.extjs.conditionalLogic.condition.outputWorkflow = Class.create(Formb
anchor: '100%',
stacked: true,
displayField: 'name',
valueField: 'id',
valueField: 'name',
allowBlank: false,
flex: 1,
queryMode: 'local',
Expand All @@ -49,7 +49,7 @@ Formbuilder.extjs.conditionalLogic.condition.outputWorkflow = Class.create(Formb
afterrender: function (cb) {
cb.store.load({
callback: function () {
var value = this.data ? this.checkFieldAvailability(this.data.outputWorkflows, cb.store, 'id') : null;
var value = this.data ? this.checkFieldAvailability(this.data.outputWorkflows, cb.store, 'name') : null;
cb.setValue(value);
}.bind(this)
});
Expand Down
29 changes: 26 additions & 3 deletions src/Migrations/Version20230908101855.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,22 @@ public function up(Schema $schema): void
$forms = $this->connection->fetchAllAssociative("SELECT id, conditionalLogic FROM formbuilder_forms WHERE conditionalLogic LIKE '%switchOutputWorkflow%'");

foreach ($forms as $form) {

$conditionalLogic = array_map(static function ($logic) use ($workflowIdMap) {
return [
'condition' => $logic['condition'],
'action' => array_map(static function ($action) use ($workflowIdMap) {
'condition' => array_map(static function ($condition) use ($workflowIdMap) {
if ($condition['type'] !== 'outputWorkflow') {
return $condition;
}

foreach ($condition['outputWorkflows'] as $index => $outputWorkflowId) {
$condition['outputWorkflows'][$index] = $workflowIdMap[$outputWorkflowId];
}

return $condition;

}, $logic['condition']),
'action' => array_map(static function ($action) use ($workflowIdMap) {
if ($action['type'] !== 'switchOutputWorkflow') {
return $action;
}
Expand Down Expand Up @@ -61,7 +73,18 @@ public function down(Schema $schema): void
foreach ($forms as $form) {
$conditionalLogic = array_map(static function ($logic) use ($workflowIdMap) {
return [
'condition' => $logic['condition'],
'condition' => array_map(static function ($condition) use ($workflowIdMap) {
if ($condition['type'] !== 'outputWorkflow') {
return $condition;
}

foreach ($condition['outputWorkflows'] as $index => $outputWorkflowId) {
$condition['outputWorkflows'][$index] = $workflowIdMap[$outputWorkflowId];
}

return $condition;

}, $logic['condition']),
'action' => array_map(static function ($action) use ($workflowIdMap) {
if ($action['type'] !== 'switchOutputWorkflow') {
return $action;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace FormBuilderBundle\Validation\ConditionalLogic\Rule\Condition;

use FormBuilderBundle\Model\OutputWorkflowInterface;
use FormBuilderBundle\Repository\OutputWorkflowRepositoryInterface;
use FormBuilderBundle\Validation\ConditionalLogic\Rule\Traits\ConditionTrait;

class OutputWorkflowCondition implements ConditionInterface
Expand All @@ -10,6 +12,10 @@ class OutputWorkflowCondition implements ConditionInterface

protected array $outputWorkflow = [];

public function __construct(protected OutputWorkflowRepositoryInterface $outputWorkflowRepository)
{
}

public function isValid(array $formData, int $ruleId, array $configuration = []): bool
{
// ignore
Expand All @@ -27,7 +33,14 @@ public function isValid(array $formData, int $ruleId, array $configuration = [])
return true;
}

return in_array($configuration['formRuntimeOptions']['form_output_workflow'], $this->getOutputWorkflows(), true);
$formOutputWorkflowId = $configuration['formRuntimeOptions']['form_output_workflow'];
$outputWorkflow = $this->outputWorkflowRepository->findById($formOutputWorkflowId);

if (!$outputWorkflow instanceof OutputWorkflowInterface) {
return false;
}

return in_array($outputWorkflow->getName(), $this->getOutputWorkflows(), true);
}

public function getOutputWorkflows(): array
Expand Down

0 comments on commit c6b0ea6

Please sign in to comment.