Refactor getting segments from form body to form entity

[MAILPOET-3297]
This commit is contained in:
Rostislav Wolny
2020-12-28 11:15:40 +01:00
committed by Veljko V
parent 36a7cc0b25
commit af574f7e1b
3 changed files with 34 additions and 10 deletions

View File

@ -211,18 +211,10 @@ class Forms extends APIEndpoint {
// or if it's selected by the admin
$formEntity = new FormEntity($name);
$formEntity->setBody($body);
$listSelectionBlocks = $formEntity->getBlocksByType(FormEntity::SEGMENT_SELECTION_BLOCK_TYPE);
$listSelection = [];
foreach ($listSelectionBlocks as $listSelectionBlock) {
$listSelection = array_unique(
array_merge(
$listSelection, array_column($listSelectionBlock['params']['values'] ?? [], 'id')
)
);
}
$listSelection = $formEntity->getSegmentBlocksSegmentIds();
// check list selection
if (count($listSelectionBlocks)) {
if (count($listSelection)) {
$settings['segments_selected_by'] = 'user';
$settings['segments'] = $listSelection;
} else {